@@ -13,17 +13,24 @@ namespace Stratis.VS.StratisEVM
13
13
{
14
14
public class SolidityCompiler : Runtime
15
15
{
16
- public static async Task CompileFileAsync ( string file )
16
+ public static async Task CompileFileAsync ( string file , string workspaceDir )
17
17
{
18
18
await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
19
19
VSUtil . ShowLogOutputWindowPane ( ServiceProvider . GlobalProvider , "Solidity Compiler" ) ;
20
+ VSUtil . LogInfo ( "Solidity Compiler" , string . Format ( "Compiling {0} in {1}..." , file , workspaceDir ) ) ;
20
21
var binfiles = Directory . GetFiles ( AssemblyLocation , "*.bin" , SearchOption . TopDirectoryOnly ) ;
21
22
foreach ( var binfile in binfiles )
22
23
{
23
24
File . Delete ( binfile ) ;
24
25
}
26
+
27
+
25
28
var cmd = "cmd.exe" ;
26
- var args = "/c node " + Path . Combine ( "node_modules" , "solc" , "solc.js" ) + " \" " + file + "\" --bin" ;
29
+ var args = "/c node " + Path . Combine ( "node_modules" , "solc" , "solc.js" ) + " --base-path=\" " + workspaceDir + "\" " + " \" " + file + "\" --bin" ;
30
+ if ( Directory . Exists ( Path . Combine ( workspaceDir , "node_modules" ) ) )
31
+ {
32
+ args += " --include-path=" + Path . Combine ( workspaceDir , "node_modules" ) ;
33
+ }
27
34
var output = await ThreadHelper . JoinableTaskFactory . RunAsync ( async ( ) => await RunCmdAsync ( cmd , args , AssemblyLocation ) ) ;
28
35
if ( CheckRunCmdError ( output ) )
29
36
{
@@ -45,30 +52,33 @@ public static async Task CompileFileAsync(string file)
45
52
}
46
53
else
47
54
{
48
- var s = Directory . GetFiles ( AssemblyLocation , "*.bin" , SearchOption . TopDirectoryOnly ) ;
49
- if ( s is null || s . Length == 0 )
55
+ binfiles = Directory . GetFiles ( AssemblyLocation , "*.bin" , SearchOption . TopDirectoryOnly ) ;
56
+ if ( binfiles is null || binfiles . Length == 0 )
50
57
{
51
- VSUtil . LogError ( "Solidity Compiler" , "Could not read Solidity compiler output file ." ) ;
58
+ VSUtil . LogError ( "Solidity Compiler" , "Could not read Solidity compiler output. No compiler output files found ." ) ;
52
59
return ;
53
60
}
54
- else if ( s . Length != 1 )
61
+ else
55
62
{
56
- VSUtil . LogError ( "Solidity Compiler" , "Error reading Solidity compiler output file: more than one output file found." ) ;
57
- binfiles = Directory . GetFiles ( AssemblyLocation , "*.bin" , SearchOption . TopDirectoryOnly ) ;
63
+ string b = null ;
58
64
foreach ( var binfile in binfiles )
59
65
{
66
+ if ( binfile . Contains ( Path . GetFileNameWithoutExtension ( file ) ) )
67
+ {
68
+ b = File . ReadAllText ( binfile ) ;
69
+ VSUtil . LogInfo ( "Solidity Compiler" , "======= " + file + "======= " + "\n Binary: \n " + b ) ;
70
+ }
60
71
File . Delete ( binfile ) ;
61
72
}
73
+ if ( b == null )
74
+ {
75
+ VSUtil . LogError ( "Solidity Compiler" , "Error reading Solidity compiler output: could not find compiler output file for " + file + "." ) ;
76
+
77
+ }
78
+
62
79
return ;
63
80
}
64
- else
65
- {
66
- var binfile = s . Single ( ) ;
67
- var b = File . ReadAllText ( binfile ) ;
68
- File . Delete ( binfile ) ;
69
- VSUtil . LogInfo ( "Solidity Compiler" , "======= " + file + "======= " + "\n Binary: \n " + b ) ;
70
- return ;
71
- }
81
+
72
82
73
83
}
74
84
}
0 commit comments