@@ -59,7 +59,7 @@ public FuncCompiler build() {
59
59
try {
60
60
ProcessBuilder pb = new ProcessBuilder ("func" , "-h" ).redirectErrorStream (true );
61
61
Process p = pb .start ();
62
- p .waitFor (5 , TimeUnit .SECONDS );
62
+ p .waitFor (1 , TimeUnit .SECONDS );
63
63
if (p .exitValue () != 2 ) {
64
64
throw new Error ("Cannot execute simple func command.\n " + errorMsg );
65
65
}
@@ -82,7 +82,7 @@ public FuncCompiler build() {
82
82
try {
83
83
ProcessBuilder pb = new ProcessBuilder ("fift" , "-h" ).redirectErrorStream (true );
84
84
Process p = pb .start ();
85
- p .waitFor (5 , TimeUnit .SECONDS );
85
+ p .waitFor (1 , TimeUnit .SECONDS );
86
86
if (p .exitValue () != 2 ) {
87
87
throw new Error ("Cannot execute simple fift command.\n " + errorMsg );
88
88
}
@@ -98,14 +98,34 @@ public FuncCompiler build() {
98
98
}
99
99
100
100
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
+ }
102
112
}
103
113
104
114
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
+ }
106
127
}
107
-
108
- System .out .println ("using fift include dirs: " + super .fiftAsmLibraryPath + ", " + super .fiftSmartcontLibraryPath );
128
+ System .out .println ("using include dirs: " + super .fiftAsmLibraryPath + ", " + super .fiftSmartcontLibraryPath );
109
129
110
130
return super .build ();
111
131
}
@@ -139,7 +159,7 @@ private String executeFift(String... params) {
139
159
if (Utils .getOS () == Utils .OS .WINDOWS ) {
140
160
withInclude = new String []{"-I" , "\" " + fiftAsmLibraryPath + "@" + fiftSmartcontLibraryPath + "\" " };
141
161
} else {
142
- withInclude = new String []{"-I" , " \" " + fiftAsmLibraryPath + ":" + fiftSmartcontLibraryPath + " \" " };
162
+ withInclude = new String []{"-I" , fiftAsmLibraryPath + ":" + fiftSmartcontLibraryPath };
143
163
}
144
164
String [] all = ArrayUtils .addAll (withInclude , params );
145
165
Pair <Process , Future <String >> result = execute (fiftExecutable , all );
@@ -174,6 +194,7 @@ private Pair<Process, Future<String>> execute(String pathToBinary, String... com
174
194
Future <String > future = executorService .submit (() -> {
175
195
176
196
Thread .currentThread ().setName (pathToBinary );
197
+ p .waitFor (1 , TimeUnit .SECONDS );
177
198
178
199
String resultInput = IOUtils .toString (p .getInputStream (), Charset .defaultCharset ());
179
200
@@ -208,12 +229,16 @@ private static String detectAbsolutePath(String executable) {
208
229
pb = new ProcessBuilder ("which" , executable ).redirectErrorStream (true );
209
230
}
210
231
Process p = pb .start ();
211
- p .waitFor (5 , TimeUnit .SECONDS );
232
+ p .waitFor (1 , TimeUnit .SECONDS );
212
233
String output = IOUtils .toString (p .getInputStream (), Charset .defaultCharset ());
213
234
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
+ }
217
242
}
218
243
}
219
244
return null ;
0 commit comments