Skip to content

Commit

Permalink
Fix bug with compier bin files. Correctly include node_modules depend…
Browse files Browse the repository at this point in the history
…encies dir when compiling contracts.
  • Loading branch information
allisterb committed Sep 5, 2024
1 parent be490c9 commit ffc7769
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
42 changes: 26 additions & 16 deletions src/Stratis.VS.StratisEVM/SolidityCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ namespace Stratis.VS.StratisEVM
{
public class SolidityCompiler : Runtime
{
public static async Task CompileFileAsync(string file)
public static async Task CompileFileAsync(string file, string workspaceDir)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
VSUtil.ShowLogOutputWindowPane(ServiceProvider.GlobalProvider, "Solidity Compiler");
VSUtil.LogInfo("Solidity Compiler", string.Format("Compiling {0} in {1}...", file, workspaceDir));
var binfiles = Directory.GetFiles(AssemblyLocation, "*.bin", SearchOption.TopDirectoryOnly);
foreach ( var binfile in binfiles )
{
File.Delete(binfile);
}


var cmd = "cmd.exe";
var args = "/c node " + Path.Combine("node_modules", "solc", "solc.js") + " \"" + file + "\" --bin";
var args = "/c node " + Path.Combine("node_modules", "solc", "solc.js") + " --base-path=\"" + workspaceDir + "\"" + " \"" + file + "\" --bin";
if (Directory.Exists(Path.Combine(workspaceDir, "node_modules")))
{
args += " --include-path=" + Path.Combine(workspaceDir, "node_modules");
}
var output = await ThreadHelper.JoinableTaskFactory.RunAsync(async () => await RunCmdAsync(cmd, args, AssemblyLocation));
if (CheckRunCmdError(output))
{
Expand All @@ -45,30 +52,33 @@ public static async Task CompileFileAsync(string file)
}
else
{
var s = Directory.GetFiles(AssemblyLocation, "*.bin", SearchOption.TopDirectoryOnly);
if (s is null || s.Length == 0)
binfiles = Directory.GetFiles(AssemblyLocation, "*.bin", SearchOption.TopDirectoryOnly);
if (binfiles is null || binfiles.Length == 0)
{
VSUtil.LogError("Solidity Compiler", "Could not read Solidity compiler output file.");
VSUtil.LogError("Solidity Compiler", "Could not read Solidity compiler output. No compiler output files found.");
return;
}
else if (s.Length != 1)
else
{
VSUtil.LogError("Solidity Compiler", "Error reading Solidity compiler output file: more than one output file found.");
binfiles = Directory.GetFiles(AssemblyLocation, "*.bin", SearchOption.TopDirectoryOnly);
string b = null;
foreach (var binfile in binfiles)
{
if (binfile.Contains(Path.GetFileNameWithoutExtension(file)))
{
b = File.ReadAllText(binfile);
VSUtil.LogInfo("Solidity Compiler", "======= " + file + "======= " + "\nBinary: \n" + b);
}
File.Delete(binfile);
}
if (b == null)
{
VSUtil.LogError("Solidity Compiler", "Error reading Solidity compiler output: could not find compiler output file for " + file + ".");

}

return;
}
else
{
var binfile = s.Single();
var b = File.ReadAllText(binfile);
File.Delete(binfile);
VSUtil.LogInfo("Solidity Compiler", "======= " + file + "======= " +"\nBinary: \n" + b);
return;
}


}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Workspace;
using Microsoft.VisualStudio.Workspace.Extensions.VS;

using System.Linq;

namespace Stratis.VS.StratisEVM
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public Task<IReadOnlyList<IFileContextAction>> GetActionsAsync(string filePath,
"Compile Solidity File" + fileContext.DisplayName,
async (fCtxt, progress, ct) =>
{
await SolidityCompiler.CompileFileAsync(filePath);
await SolidityCompiler.CompileFileAsync(filePath, fileContext.InputFiles.First());
}),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<IReadOnlyCollection<FileContext>> GetContextsForFileAsync(stri
new Guid(ProviderType),
new Guid(StratisEVMPackageIds.SolidityFileContextType),
filePath + "\n",
Array.Empty<string>()));
new string[] { this.workspaceContext.Location }));
}

return await Task.FromResult(fileContexts.ToArray());
Expand Down
3 changes: 2 additions & 1 deletion src/Stratis.VS.StratisEVM/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<Metadata>
<Identity Id="Stratis.VS.StratisEVM.09bed5a1-7734-4cff-9412-d17961f1a291" Version="0.1.1" Language="en-US" Publisher="Stratis DevEx" />
<Identity Id="Stratis.VS.StratisEVM.09bed5a1-7734-4cff-9412-d17961f1a291" Version="0.1.2" Language="en-US" Publisher="Stratis DevEx" />
<DisplayName>StratisEVM</DisplayName>
<Description xml:space="preserve">StratisEVM smart contracts extension</Description>
<MoreInfo>https://github.com/stratisdevex/Stratis.DevEx/tree/master/src/Stratis.VS.StratisEVM</MoreInfo>
<License>LICENSE.txt</License>
<GettingStartedGuide>README.html</GettingStartedGuide>
<ReleaseNotes>Correctly include node_modules dependencies dir when compiling contracts.</ReleaseNotes>
<Icon>StratisLogo64x64.png</Icon>
<PreviewImage>StratisLogo200x200.png</PreviewImage>
<Tags>stratis,ethereum, solidity, smart contracts</Tags>
Expand Down

0 comments on commit ffc7769

Please sign in to comment.