Add a version reporting fallback for owl-native.

parent fc2506a7
......@@ -24,6 +24,10 @@ Build:
script:
- apt-get update && apt-get install -y --no-install-recommends build-essential zlib1g-dev # TODO: Remove this after Docker update
- ./gradlew distZip
- unzip -d build/unzipped build/distributions/*.zip
- mv build/unzipped/owl-*/bin build
- mv build/unzipped/owl-*/lib build
- build/bin/owl --version
- build/native-executable/owl-native --version
artifacts:
paths:
......
......@@ -215,6 +215,11 @@ startScripts.outputDir = file(project.buildDir.path + '/scripts/owl')
// ---------------- Jars ----------------
java {
withJavadocJar()
withSourcesJar()
}
jar {
manifest {
attributes(
......@@ -224,19 +229,7 @@ jar {
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
task mavenJars(dependsOn: [jar, sourcesJar, javadocJar])
task buildNativeLibrary(type: Exec, dependsOn: [classes]) {
task buildNativeLibrary(type: Exec, dependsOn: [jar]) {
mkdir "${buildDir}/native-library"
workingDir "${buildDir}/native-library"
onlyIf { buildOwlNative }
......@@ -259,7 +252,7 @@ task buildNativeLibrary(type: Exec, dependsOn: [classes]) {
'-H:-UseServiceLoaderFeature'
}
task buildNativeExecutable(type: Exec, dependsOn: [classes]) {
task buildNativeExecutable(type: Exec, dependsOn: [jar]) {
mkdir "${buildDir}/native-executable"
workingDir "${buildDir}/native-executable"
onlyIf { buildOwlNative }
......@@ -269,7 +262,8 @@ task buildNativeExecutable(type: Exec, dependsOn: [classes]) {
// TODO: remove dependency on header files.
commandLine command,
"owl.run.DefaultCli", "owl-native",
"owl-native",
"-jar", jar.archivePath,
"-cp", sourceSets.main.runtimeClasspath.asPath,
enableNativeAssertions ? '-ea' : '-da',
"-DowlHeader=${projectDir}/src/main/headers",
......
......@@ -47,6 +47,7 @@ import owl.automaton.Automaton;
import owl.automaton.acceptance.OmegaAcceptance;
import owl.automaton.edge.Edge;
import owl.collections.ValuationSet;
import owl.util.OwlVersion;
public final class HoaWriter {
......@@ -103,7 +104,8 @@ public final class HoaWriter {
try {
consumer.notifyHeaderStart("v1");
consumer.setTool(tool(), version());
var nameAndVersion = OwlVersion.getNameAndVersion();
consumer.setTool(nameAndVersion.name(), nameAndVersion.version());
if (options.contains(HoaOption.ANNOTATIONS)) {
consumer.setName(name);
......@@ -137,18 +139,6 @@ public final class HoaWriter {
}
}
// TODO: global scope?
private static String tool() {
String title = Wrapper.class.getPackage().getImplementationTitle();
return title == null ? "owl" : title;
}
// TODO: global scope?
private static String version() {
String version = Wrapper.class.getPackage().getImplementationVersion();
return version == null ? "development" : version;
}
private void addEdgeBackend(BooleanExpression<AtomLabel> label, S end, IntList accSets) {
try {
consumer.addEdgeWithLabel(getStateId(currentState), label, List.of(getStateId(end)),
......
......@@ -32,6 +32,7 @@ import org.graalvm.word.PointerBase;
import org.graalvm.word.UnsignedWord;
import org.graalvm.word.WordFactory;
import owl.run.Environment;
import owl.util.OwlVersion;
@CContext(CInterface.CDirectives.class)
public final class CInterface {
......@@ -74,6 +75,17 @@ public final class CInterface {
ObjectHandles.getGlobal().get(handle).toString(), buffer, bufferSize);
}
@CEntryPoint(
name = "owl_version",
exceptionHandler = PrintStackTraceAndExit.ReturnUnsignedWord.class
)
public static UnsignedWord owlVersion(
IsolateThread thread, CCharPointer buffer, UnsignedWord bufferSize) {
return CTypeConversion.toCString(
OwlVersion.getNameAndVersion().version(), buffer, bufferSize);
}
static class CDirectives implements CContext.Directives {
@Override
......
......@@ -37,6 +37,7 @@ public abstract class ValuationTree<E> {
private ValuationTree() {
}
@SuppressWarnings("unchecked")
public static <E> ValuationTree<E> of() {
return (ValuationTree<E>) Leaf.EMPTY;
}
......@@ -102,7 +103,7 @@ public abstract class ValuationTree<E> {
Set<Set<E>> values, Set<ValuationTree<E>> seenNodes);
public static final class Leaf<E> extends ValuationTree<E> {
private static final ValuationTree<Object> EMPTY = new Leaf<>(Set.of());
private static final ValuationTree<?> EMPTY = new Leaf<>(Set.of());
public final Set<E> value;
......
......@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.Option;
import owl.util.OwlVersion;
public final class RunUtil {
private static final Logger logger = Logger.getLogger(RunUtil.class.getName());
......@@ -62,23 +63,11 @@ public final class RunUtil {
@SuppressWarnings({"PMD.SystemPrintln"})
public static void checkForVersion(String[] args) {
if (Arrays.asList(args).contains("-v") || Arrays.asList(args).contains("--version")) {
Class<?> moduleClass;
var nameAndVersion = OwlVersion.getNameAndVersion();
try {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement main = stack[stack.length - 1];
moduleClass = Class.forName(main.getClassName());
} catch (ClassNotFoundException e) {
moduleClass = null;
}
System.out.println(
String.format("Name: %s \nVersion: %s", nameAndVersion.name(), nameAndVersion.version()));
String moduleName = moduleClass == null
? "unknown"
: moduleClass.getSimpleName().toLowerCase().replace("module", "");
String name = String.format("Name: %s (%s)",
moduleName, RunUtil.class.getPackage().getImplementationTitle());
System.out.println(name);
System.out.println("Version: " + RunUtil.class.getPackage().getImplementationVersion());
System.exit(0);
}
}
......
......@@ -89,7 +89,7 @@ public abstract class NbaDetConfSets {
if (!args.sepAccCyc()) {
//if not requested to separate, put all ASCCs in single determinisation tuple component
final var merged = asccs.stream().reduce(BitSetUtil::union).orElse(BitSetUtil.empty());
final var merged = asccs.stream().reduce(BitSetUtil::union).orElse(new BitSet());
asccs.clear();
asccs.add(merged);
}
......@@ -121,7 +121,7 @@ public abstract class NbaDetConfSets {
if (!args.sepMix()) {
//if not requested to separate, put all states in single determinisation tuple component
final var merged = msccs.stream().reduce(BitSetUtil::union).orElse(BitSetUtil.empty());
final var merged = msccs.stream().reduce(BitSetUtil::union).orElse(new BitSet());
msccs.clear();
if (!merged.isEmpty()) {
msccs.add(merged);
......
......@@ -36,11 +36,6 @@ public final class BitSetUtil {
return fromSet(stateMap.keySet(), stateMap);
}
/** returns an empty BitSet. */
public static BitSet empty() {
return fromInt(0);
}
/**
* Converts a set into a bitset.
* @param set set to be converted
......
package owl.util;
import java.util.HashSet;
import java.util.LinkedList;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public final class CombinationGenerator {
private CombinationGenerator() {
}
public static <S> List<S> get(List<S> elements, int mask) {
return IntStream.range(0, elements.size())
.filter(i -> (mask & (1 << i)) > 0)
.mapToObj(i -> elements.get(i))
.collect(Collectors.toList());
}
private CombinationGenerator() {}
public static int count(int mask) {
int n;
......@@ -28,80 +18,26 @@ public final class CombinationGenerator {
}
public static <R> List<List<R>> comb(List<R> input, int k) {
LinkedList<List<R>> out = new LinkedList<>();
List<List<R>> out = new ArrayList<>();
for (int i = 1; i <= k; i++) {
for (int mask = 0; mask < (1 << input.size()); mask++) {
if (count(mask) == i) {
out.push(get(input, mask));
}
}
}
return out;
}
public static <R> Set<List<R>> combFast(Set<R> input, int k) {
if (input.isEmpty()) {
return Set.of();
}
assert k > 0;
List<R> list = new ArrayList<>();
int i = 1;
Set<List<R>> out = new HashSet<>();
int bound = input.size();
input.forEach(in -> {
out.add(List.of(in));
});
for (int i1 = 0; i1 < bound; i1++) {
if ((mask & (1 << i1)) > 0) {
list.add(input.get(i1));
}
}
while (i < k) {
Set<List<R>> toAdd = new HashSet<>();
out.forEach(e -> {
input.forEach(in -> {
var tmp = new LinkedList<>(e);
tmp.add(in);
toAdd.add(tmp);
});
});
out.addAll(toAdd);
i++;
}
return out;
}
public static <R> List<List<R>> combFast(List<R> input, int k) {
if (input.isEmpty()) {
return List.of();
}
assert k > 0;
int i = 1;
List<List<R>> out = new LinkedList<>();
input.forEach(in -> {
out.add(List.of(in));
});
while (i < k) {
List<List<R>> toAdd = new LinkedList<>();
out.forEach(e -> {
input.forEach(in -> {
var tmp = new LinkedList<>(e);
tmp.add(in);
toAdd.add(tmp);
});
});
out.addAll(toAdd);
i++;
out.add(list);
}
}
}
return out;
}
public static <S> List<List<S>> kComb(List<S> input, int k) {
LinkedList<List<S>> out = new LinkedList<>();
for (int i = 1; i <= k; i++) {
out.addAll(comb(input, i));
}
return out;
return Lists.reverse(out);
}
}
/*
* Copyright (C) 2016 - 2020 (See AUTHORS)
*
* This file is part of Owl.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package owl.util;
import com.google.auto.value.AutoValue;
public class OwlVersion {
// Fall-back strings if MANIFEST cannot be accessed correctly.
private static final String MAIN_NAME = "owl";
private static final String VERSION = "20.XX-development";
private OwlVersion() {}
/**
* Obtains the name and version of the currently running Owl component. This is done by searching
* the current stack trace for initial entry point. It is assumed that this is called from the
* main thread.
*/
public static NameAndVersion getNameAndVersion() {
String moduleName;
try {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement main = stack[stack.length - 1];
moduleName = Class.forName(main.getClassName())
.getSimpleName().toLowerCase().replace("module", "");
} catch (ArrayIndexOutOfBoundsException | ClassNotFoundException e) {
moduleName = null;
}
Package owlPackage = OwlVersion.class.getPackage();
String mainName = owlPackage.getImplementationTitle();
if (mainName == null) {
mainName = MAIN_NAME;
} else if (!mainName.equals(MAIN_NAME)) {
throw new IllegalStateException("Conflicting main names.");
}
String version = owlPackage.getImplementationVersion();
if (version == null) {
version = VERSION;
} else if (!version.equals(VERSION)) {
throw new IllegalStateException("Conflicting versions.");
}
if (moduleName == null) {
return NameAndVersion.of(mainName, version);
}
return NameAndVersion.of(String.format("%s (%s)", moduleName, mainName), version);
}
@AutoValue
public abstract static class NameAndVersion {
public abstract String name();
public abstract String version();
private static NameAndVersion of(String name, String version) {
return new AutoValue_OwlVersion_NameAndVersion(name, version);
}
}
}
package owl.util;
import java.util.Objects;
import java.util.function.Function;
@FunctionalInterface
public interface TriFunction<A, B, C, R> {
R apply(A a, B b, C c);
default <V> TriFunction<A, B, C, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after);
return (A a, B b, C c) -> after.apply(apply(a, b, c));
}
}
\ No newline at end of file
......@@ -93,7 +93,7 @@ public class MiscUtilTest {
@Test
void bitsetEncodeDecode() {
//empty and all
assertEquals(new BitSet(), BitSetUtil.empty());
assertEquals(new BitSet(), new BitSet());
HashBiMap<Integer,Integer> smap = HashBiMap.create();
smap.put(1,2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment