Skip to content

Commit ffc7769

Browse files
committed
Fix bug with compier bin files. Correctly include node_modules dependencies dir when compiling contracts.
1 parent be490c9 commit ffc7769

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

src/Stratis.VS.StratisEVM/SolidityCompiler.cs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@ namespace Stratis.VS.StratisEVM
1313
{
1414
public class SolidityCompiler : Runtime
1515
{
16-
public static async Task CompileFileAsync(string file)
16+
public static async Task CompileFileAsync(string file, string workspaceDir)
1717
{
1818
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
1919
VSUtil.ShowLogOutputWindowPane(ServiceProvider.GlobalProvider, "Solidity Compiler");
20+
VSUtil.LogInfo("Solidity Compiler", string.Format("Compiling {0} in {1}...", file, workspaceDir));
2021
var binfiles = Directory.GetFiles(AssemblyLocation, "*.bin", SearchOption.TopDirectoryOnly);
2122
foreach ( var binfile in binfiles )
2223
{
2324
File.Delete(binfile);
2425
}
26+
27+
2528
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+
}
2734
var output = await ThreadHelper.JoinableTaskFactory.RunAsync(async () => await RunCmdAsync(cmd, args, AssemblyLocation));
2835
if (CheckRunCmdError(output))
2936
{
@@ -45,30 +52,33 @@ public static async Task CompileFileAsync(string file)
4552
}
4653
else
4754
{
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)
5057
{
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.");
5259
return;
5360
}
54-
else if (s.Length != 1)
61+
else
5562
{
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;
5864
foreach (var binfile in binfiles)
5965
{
66+
if (binfile.Contains(Path.GetFileNameWithoutExtension(file)))
67+
{
68+
b = File.ReadAllText(binfile);
69+
VSUtil.LogInfo("Solidity Compiler", "======= " + file + "======= " + "\nBinary: \n" + b);
70+
}
6071
File.Delete(binfile);
6172
}
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+
6279
return;
6380
}
64-
else
65-
{
66-
var binfile = s.Single();
67-
var b = File.ReadAllText(binfile);
68-
File.Delete(binfile);
69-
VSUtil.LogInfo("Solidity Compiler", "======= " + file + "======= " +"\nBinary: \n" + b);
70-
return;
71-
}
81+
7282

7383
}
7484
}

src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Microsoft.VisualStudio.Shell.Interop;
1111
using Microsoft.VisualStudio.Workspace;
1212
using Microsoft.VisualStudio.Workspace.Extensions.VS;
13-
13+
using System.Linq;
1414

1515
namespace Stratis.VS.StratisEVM
1616
{
@@ -58,7 +58,7 @@ public Task<IReadOnlyList<IFileContextAction>> GetActionsAsync(string filePath,
5858
"Compile Solidity File" + fileContext.DisplayName,
5959
async (fCtxt, progress, ct) =>
6060
{
61-
await SolidityCompiler.CompileFileAsync(filePath);
61+
await SolidityCompiler.CompileFileAsync(filePath, fileContext.InputFiles.First());
6262
}),
6363
});
6464
}

src/Stratis.VS.StratisEVM/SolidityFileContextProviderFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task<IReadOnlyCollection<FileContext>> GetContextsForFileAsync(stri
4545
new Guid(ProviderType),
4646
new Guid(StratisEVMPackageIds.SolidityFileContextType),
4747
filePath + "\n",
48-
Array.Empty<string>()));
48+
new string[] { this.workspaceContext.Location }));
4949
}
5050

5151
return await Task.FromResult(fileContexts.ToArray());

src/Stratis.VS.StratisEVM/source.extension.vsixmanifest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="Stratis.VS.StratisEVM.09bed5a1-7734-4cff-9412-d17961f1a291" Version="0.1.1" Language="en-US" Publisher="Stratis DevEx" />
4+
<Identity Id="Stratis.VS.StratisEVM.09bed5a1-7734-4cff-9412-d17961f1a291" Version="0.1.2" Language="en-US" Publisher="Stratis DevEx" />
55
<DisplayName>StratisEVM</DisplayName>
66
<Description xml:space="preserve">StratisEVM smart contracts extension</Description>
77
<MoreInfo>https://github.com/stratisdevex/Stratis.DevEx/tree/master/src/Stratis.VS.StratisEVM</MoreInfo>
88
<License>LICENSE.txt</License>
99
<GettingStartedGuide>README.html</GettingStartedGuide>
10+
<ReleaseNotes>Correctly include node_modules dependencies dir when compiling contracts.</ReleaseNotes>
1011
<Icon>StratisLogo64x64.png</Icon>
1112
<PreviewImage>StratisLogo200x200.png</PreviewImage>
1213
<Tags>stratis,ethereum, solidity, smart contracts</Tags>

0 commit comments

Comments
 (0)