Skip to content

Commit 13794a9

Browse files
author
neodiX
committed
tested on ubuntu
1 parent 8ca1d53 commit 13794a9

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

smartcontract/src/main/java/org/ton/java/smartcontract/FuncCompiler.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public FuncCompiler build() {
5959
try {
6060
ProcessBuilder pb = new ProcessBuilder("func", "-h").redirectErrorStream(true);
6161
Process p = pb.start();
62-
p.waitFor(5, TimeUnit.SECONDS);
62+
p.waitFor(1, TimeUnit.SECONDS);
6363
if (p.exitValue() != 2) {
6464
throw new Error("Cannot execute simple func command.\n" + errorMsg);
6565
}
@@ -82,7 +82,7 @@ public FuncCompiler build() {
8282
try {
8383
ProcessBuilder pb = new ProcessBuilder("fift", "-h").redirectErrorStream(true);
8484
Process p = pb.start();
85-
p.waitFor(5, TimeUnit.SECONDS);
85+
p.waitFor(1, TimeUnit.SECONDS);
8686
if (p.exitValue() != 2) {
8787
throw new Error("Cannot execute simple fift command.\n" + errorMsg);
8888
}
@@ -98,14 +98,34 @@ public FuncCompiler build() {
9898
}
9999

100100
if (StringUtils.isEmpty(super.fiftAsmLibraryPath)) {
101-
super.fiftAsmLibraryPath = new File(fiftAbsolutePath).getParent() + File.separator + "lib";
101+
if (Utils.getOS() == Utils.OS.WINDOWS) {
102+
super.fiftAsmLibraryPath = new File(fiftAbsolutePath).getParent() + File.separator + "lib";
103+
} else if ((Utils.getOS() == Utils.OS.LINUX) || (Utils.getOS() == Utils.OS.LINUX_ARM)) {
104+
super.fiftAsmLibraryPath = "/usr/lib/fift";
105+
} else { //mac
106+
if (new File("/usr/local/lib/fift").exists()) {
107+
super.fiftAsmLibraryPath = "/usr/local/lib/fift";
108+
} else if (new File("/opt/homebrew/lib/fift").exists()) {
109+
super.fiftAsmLibraryPath = "/opt/homebrew/lib/fift";
110+
}
111+
}
102112
}
103113

104114
if (StringUtils.isEmpty(super.fiftSmartcontLibraryPath)) {
105-
super.fiftSmartcontLibraryPath = new File(fiftAbsolutePath).getParent() + File.separator + "smartcont";
115+
if (Utils.getOS() == Utils.OS.WINDOWS) {
116+
super.fiftSmartcontLibraryPath = new File(fiftAbsolutePath).getParent() + File.separator + "smartcont";
117+
}
118+
if ((Utils.getOS() == Utils.OS.LINUX) || (Utils.getOS() == Utils.OS.LINUX_ARM)) {
119+
super.fiftSmartcontLibraryPath = "/usr/share/ton/smartcont";
120+
} else { // mac
121+
if (new File("/usr/local/share/ton/ton/smartcont").exists()) {
122+
super.fiftSmartcontLibraryPath = "/usr/local/share/ton/ton/smartcont";
123+
} else if (new File("/opt/homebrew/share/ton/ton/smartcont").exists()) {
124+
super.fiftSmartcontLibraryPath = "/opt/homebrew/share/ton/ton/smartcont";
125+
}
126+
}
106127
}
107-
108-
System.out.println("using fift include dirs: " + super.fiftAsmLibraryPath + ", " + super.fiftSmartcontLibraryPath);
128+
System.out.println("using include dirs: " + super.fiftAsmLibraryPath + ", " + super.fiftSmartcontLibraryPath);
109129

110130
return super.build();
111131
}
@@ -139,7 +159,7 @@ private String executeFift(String... params) {
139159
if (Utils.getOS() == Utils.OS.WINDOWS) {
140160
withInclude = new String[]{"-I", "\"" + fiftAsmLibraryPath + "@" + fiftSmartcontLibraryPath + "\""};
141161
} else {
142-
withInclude = new String[]{"-I", "\"" + fiftAsmLibraryPath + ":" + fiftSmartcontLibraryPath + "\""};
162+
withInclude = new String[]{"-I", fiftAsmLibraryPath + ":" + fiftSmartcontLibraryPath};
143163
}
144164
String[] all = ArrayUtils.addAll(withInclude, params);
145165
Pair<Process, Future<String>> result = execute(fiftExecutable, all);
@@ -174,6 +194,7 @@ private Pair<Process, Future<String>> execute(String pathToBinary, String... com
174194
Future<String> future = executorService.submit(() -> {
175195

176196
Thread.currentThread().setName(pathToBinary);
197+
p.waitFor(1, TimeUnit.SECONDS);
177198

178199
String resultInput = IOUtils.toString(p.getInputStream(), Charset.defaultCharset());
179200

@@ -208,12 +229,16 @@ private static String detectAbsolutePath(String executable) {
208229
pb = new ProcessBuilder("which", executable).redirectErrorStream(true);
209230
}
210231
Process p = pb.start();
211-
p.waitFor(5, TimeUnit.SECONDS);
232+
p.waitFor(1, TimeUnit.SECONDS);
212233
String output = IOUtils.toString(p.getInputStream(), Charset.defaultCharset());
213234
String[] paths = output.split("\n");
214-
for (String path : paths) {
215-
if (path.contains("ton")) {
216-
return StringUtils.trim(path);
235+
if (paths.length == 1) {
236+
return paths[0];
237+
} else {
238+
for (String path : paths) {
239+
if (path.contains("ton")) {
240+
return StringUtils.trim(path);
241+
}
217242
}
218243
}
219244
return null;

0 commit comments

Comments
 (0)