diff --git a/src/Stratis.VS.StratisEVM/SolidityCompiler.cs b/src/Stratis.VS.StratisEVM/SolidityCompiler.cs index c238de2..158f690 100644 --- a/src/Stratis.VS.StratisEVM/SolidityCompiler.cs +++ b/src/Stratis.VS.StratisEVM/SolidityCompiler.cs @@ -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)) { @@ -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; - } + } } diff --git a/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs b/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs index b89b0e0..0d8508a 100644 --- a/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs +++ b/src/Stratis.VS.StratisEVM/SolidityFileContextActionsProviderFactory.cs @@ -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 { @@ -58,7 +58,7 @@ public Task> GetActionsAsync(string filePath, "Compile Solidity File" + fileContext.DisplayName, async (fCtxt, progress, ct) => { - await SolidityCompiler.CompileFileAsync(filePath); + await SolidityCompiler.CompileFileAsync(filePath, fileContext.InputFiles.First()); }), }); } diff --git a/src/Stratis.VS.StratisEVM/SolidityFileContextProviderFactory.cs b/src/Stratis.VS.StratisEVM/SolidityFileContextProviderFactory.cs index 02e1ac1..edc7b8c 100644 --- a/src/Stratis.VS.StratisEVM/SolidityFileContextProviderFactory.cs +++ b/src/Stratis.VS.StratisEVM/SolidityFileContextProviderFactory.cs @@ -45,7 +45,7 @@ public async Task> GetContextsForFileAsync(stri new Guid(ProviderType), new Guid(StratisEVMPackageIds.SolidityFileContextType), filePath + "\n", - Array.Empty())); + new string[] { this.workspaceContext.Location })); } return await Task.FromResult(fileContexts.ToArray()); diff --git a/src/Stratis.VS.StratisEVM/Stratis.VS.StratisEVM.csproj b/src/Stratis.VS.StratisEVM/Stratis.VS.StratisEVM.csproj index 9c13e95..98b3f44 100644 --- a/src/Stratis.VS.StratisEVM/Stratis.VS.StratisEVM.csproj +++ b/src/Stratis.VS.StratisEVM/Stratis.VS.StratisEVM.csproj @@ -89,19 +89,21 @@ - 17.1.68 + 17.11.32 17.1.68 - + + compile; build; native; contentfiles; analyzers; buildtransitive + 17.1.11-preview-0002 17.1.11-preview-0002 - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Stratis.VS.StratisEVM/source.extension.vsixmanifest b/src/Stratis.VS.StratisEVM/source.extension.vsixmanifest index 52b6e7f..34a11bf 100644 --- a/src/Stratis.VS.StratisEVM/source.extension.vsixmanifest +++ b/src/Stratis.VS.StratisEVM/source.extension.vsixmanifest @@ -1,12 +1,13 @@ - + StratisEVM StratisEVM smart contracts extension https://github.com/stratisdevex/Stratis.DevEx/tree/master/src/Stratis.VS.StratisEVM LICENSE.txt README.html + Correctly include node_modules dependencies dir when compiling contracts. StratisLogo64x64.png StratisLogo200x200.png stratis,ethereum, solidity, smart contracts