Skip to content

Commit

Permalink
Properly add BindingsNS property to project file. Output bindings NS …
Browse files Browse the repository at this point in the history
…according to this property.
  • Loading branch information
allisterb committed Dec 11, 2024
1 parent 4ab63e7 commit fbc4df6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 66 deletions.
21 changes: 12 additions & 9 deletions src/Stratis.VS.SolidityProjectBuildTasks/CompileContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

using Microsoft.Build.Framework;
Expand All @@ -24,25 +25,27 @@ public class CompileContracts : Task
public ITaskItem[] Contracts { get; set; }

[Required]
public string OutputPath { get; set; }
public string OutputPath { get; set; }

public string BindingsNS { get; set; } = "Ethereum";

public Dictionary<string, Source> Sources => Contracts.ToDictionary(k => k.GetMetadata("Filename"), v => new Source() { Urls = new[] { Path.Combine(v.GetMetadata("RelativeDir"), v.ItemSpec) } });

public override bool Execute()
{
if (!File.Exists(Path.Combine(ProjectDir, "node_modules", "solc", "solc.js")))
if (File.Exists(Path.Combine(ProjectDir, "package.json")) && !File.Exists(Path.Combine(ProjectDir, "node_modules", "solc", "solc.js")))
{
Log.LogMessage(MessageImportance.High, "Installing NPM dependencies in project directory {0}...", ProjectDir);

var npmoutput = RunCmd("cmd.exe", "/c npm install", ProjectDir);
if (CheckRunCmdError(npmoutput))
if (!CheckRunCmdError(npmoutput) && CheckRunCmdOutput(npmoutput, "packages audited"))
{
Log.LogError("Could not install NPM dependencies: " + GetRunCmdError(npmoutput));
Log.LogMessage(MessageImportance.High, ((string)npmoutput["stdout"]).Trim());

}
else
{
Log.LogMessage(MessageImportance.High, ((string)npmoutput["stdout"]).Trim());
Log.LogError("Could not install NPM dependencies: " + GetRunCmdError(npmoutput));
}
}
var solcpath = File.Exists(Path.Combine(ProjectDir, "node_modules", "solc", "solc.js")) ? Path.Combine(ProjectDir, "node_modules", "solc", "solc.js") :
Expand Down Expand Up @@ -201,7 +204,7 @@ public override bool Execute()
}
if (cs.evm.gasEstimates != null)
{
File.WriteAllText(Path.Combine(outputdir, c.Key + ".gas.txt"), Serialize(cs.evm.gasEstimates));
File.WriteAllText(Path.Combine(outputdir, c.Key + ".gas.json"), Serialize(cs.evm.gasEstimates));
}
if (cs.abi != null)
{
Expand All @@ -227,7 +230,7 @@ public override bool Execute()
{
if (cs.evm.bytecode._object != null && cs.abi != null)
{
if (CheckRunCmdOutput(RunCmd("cmd.exe", $"/c dotnet Nethereum.Generator.Console generate from-abi -abi {Path.Combine(outputdir, c.Key + ".abi")} -bin {Path.Combine(outputdir, c.Key + ".bin")} -o bindings -ns Ethereum", ProjectDir), ""))
if (CheckRunCmdOutput(RunCmd("cmd.exe", $"/c dotnet Nethereum.Generator.Console generate from-abi -abi {Path.Combine(outputdir, c.Key + ".abi")} -bin {Path.Combine(outputdir, c.Key + ".bin")} -o bindings -ns {BindingsNS}", ProjectDir), ""))
{
Log.LogMessage(MessageImportance.High, $"Created .NET bindings for {c.Key} contract at {Path.Combine(ProjectDir, "bindings", c.Key)}.");
}
Expand Down Expand Up @@ -319,7 +322,6 @@ protected bool InstallNethereumGeneratorToolIfNotPresent()
return false;
}
}

return true;
}

Expand Down Expand Up @@ -368,7 +370,7 @@ public Dictionary<string, object> RunCmd(string filename, string arguments, stri
public bool CheckRunCmdError(Dictionary<string, object> output) => output.ContainsKey("error") || output.ContainsKey("exception");

public string GetRunCmdError(Dictionary<string, object> output) => (output.ContainsKey("error") ? (string)output["error"] : "")
+ (output.ContainsKey("exception") ? (string)output["exception"] : "");
+ (output.ContainsKey("exception") ? (string)output["exception"] : "" + (output.ContainsKey("stderr") ? (string)output["stderr"] : ""));

public bool CheckRunCmdOutput(Dictionary<string, object> output, string checktext)
{
Expand All @@ -390,6 +392,7 @@ public bool CheckRunCmdOutput(Dictionary<string, object> output, string checktex
{
var stderr = (string)output["stderr"];
Log.LogMessage(MessageImportance.High, stderr);
return false;
}
if (output.ContainsKey("stdout"))
{
Expand Down
5 changes: 4 additions & 1 deletion src/Stratis.VS.SolidityProjectBuildTasks/Test.testproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<ItemGroup>
<Compile Include="SmartContract1.sol" />
</ItemGroup>
<PropertyGroup>
<BindingsNS>TestNS</BindingsNS>
</PropertyGroup>
<Target Name="Build">
<CompileContracts Contracts="@(Compile)" ExtDir="C:\Users\Allister\AppData\Local\Microsoft\VisualStudio\17.0_c69ae1a2Exp\Extensions\Stratis DevEx\StratisEVM\0.1.4" ProjectDir="$(MSBuildProjectDirectory)" OutputPath="bin\solidity"/>
<CompileContracts Contracts="@(Compile)" ExtDir="C:\Users\Allister\AppData\Local\Microsoft\VisualStudio\17.0_c69ae1a2Exp\Extensions\Stratis DevEx\StratisEVM\0.1.4" ProjectDir="$(MSBuildProjectDirectory)" OutputPath="bin\solidity" BindingsNS="$(BindingsNS)"/>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PropertyGroup>
<CompilerVersion>$soliditycompilerversion$</CompilerVersion>
<ConfigurationFile>$solidityconfigfile$</ConfigurationFile>
<BindingsNS>Ethereum</BindingsNS>
</PropertyGroup>
<ItemGroup>
<Contract Include="SmartContract1.sol" />
Expand Down
8 changes: 7 additions & 1 deletion src/Stratis.VS.StratisEVM/BuildSystem/Rules/general.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
<EnumValue Name="0.8.26" />
<EnumValue Name="0.8.27" />
</EnumProperty>


<StringProperty Name="BindingsNS" DisplayName=".NET Bindings Namespace">
<StringProperty.DataSource>
<DataSource Persistence="ProjectFile" HasConfigurationCondition="False" />
</StringProperty.DataSource>
</StringProperty>

<StringProperty Name="ProjectGuid" Visible="False">
<StringProperty.DataSource>
<DataSource Persistence="ProjectFile" Label="Globals" HasConfigurationCondition="False" />
Expand Down
3 changes: 1 addition & 2 deletions src/Stratis.VS.StratisEVM/BuildSystem/Solidity.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<ProjectCapability Include="Solidity" />
<ProjectCapability Include="UseFileGlobs" />
<ProjectCapability Include="OpenProjectFile" />
<ProjectCapability Include="HandlesOwnReload" />
<ProjectCapability Include="ProjectConfigurationsDeclaredAsItems" />
</ItemGroup>

Expand Down Expand Up @@ -74,7 +73,7 @@

<UsingTask TaskName="CompileContracts" AssemblyFile="$(LocalAppData)\CustomProjectSystems\Solidity\Tools\Stratis.VS.SolidityProjectBuildTasks.dll"/>
<Target Name="Build">
<CompileContracts ExtDir="$(ExtDir)" ProjectDir="$(MSBuildProjectDirectory)" OutputPath="$(OutputPath)" Contracts="@(Contract)" />
<CompileContracts ExtDir="$(ExtDir)" ProjectDir="$(MSBuildProjectDirectory)" OutputPath="$(OutputPath)" BindingsNS="$(BindingsNS)" Contracts="@(Contract)" />
</Target>

<Target Name="Rebuild">
Expand Down
106 changes: 53 additions & 53 deletions src/Stratis.VS.StratisEVM/SolidityProjectWizardDialogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
Background="{DynamicResource {x:Static vs:ThemedDialogColors.WindowPanelBrushKey}}"
Foreground="{DynamicResource {x:Static vs:ThemedDialogColors.WindowPanelTextBrushKey}}"
SnapsToDevicePixels="True"
SnapsToDevicePixels="False"
UseLayoutRounding="True"
WindowStartupLocation="CenterOwner"
WindowStyle="None"
Expand All @@ -14,68 +14,68 @@



Width="500"
Height="200"
MinWidth="500"
Width="452"
Height="184"
MinWidth="462"
MinHeight="200">
<WindowChrome.WindowChrome>
<WindowChrome
CaptionHeight="0"
ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="10" />
</Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.WindowPanelTextBrushKey}}" />
<Setter Property="Margin" Value="0,3,5,5" />
<Setter Property="Padding" Value="0,0,0,5" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,0,0,5" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>

<Grid.Resources>
<Style TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="10" />
</Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.WindowPanelTextBrushKey}}" />
<Setter Property="Margin" Value="0,3,5,5" />
<Setter Property="Padding" Value="0,0,0,5" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,0,0,5" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ListBoxTextBrushKey}}" />

</Style>
<Style TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="70" />
<Setter Property="Height" Value="25" />
<Setter Property="Margin" Value="5,0,0,0" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ActionButtonTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ActionButtonBackgroundBrushKey}}" />
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="70" />
<Setter Property="Height" Value="25" />
<Setter Property="Margin" Value="5,0,0,0" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ActionButtonTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ActionButtonBackgroundBrushKey}}" />
</Style>
</Grid.Resources>
</Grid.Resources>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

</Grid.RowDefinitions>

<Image Grid.Column="1" Grid.Row="0" Width="64" Height="64" HorizontalAlignment="Right" Source="https://stratisdevex.gallerycdn.vsassets.io/extensions/stratisdevex/stratisevm/0.1.3/1725544756658/Microsoft.VisualStudio.Services.Icons.Default" />
<Label Grid.Column="0" Grid.Row="0" FontSize="21"> Configure your Solidity Project</Label>

<Label Grid.Column="0" Grid.Row="0" FontSize="21">Configure your Solidity Project</Label>
<Label Grid.Column="0" Grid.Row="1">Solidity project configuration file:</Label>
<ComboBox
VerticalAlignment="Center"
Expand Down Expand Up @@ -107,14 +107,14 @@
</ComboBox>

<!-- Top Margin -->

<!-- Accept or Cancel -->
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Margin="0,10,0,10" Grid.Row="4">
<Button Name="okButton" Click="okButton_Click" IsDefault="True">OK</Button>
<Button Name="cancelButton" IsCancel="True">Cancel</Button>
</StackPanel>

</Grid >
<!-- Accept or Cancel -->
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Margin="0,10,0,10" Grid.Row="4">
<Button Name="okButton" Click="okButton_Click" IsDefault="True">OK</Button>
<Button Name="cancelButton" IsCancel="True">Cancel</Button>
</StackPanel>

</Grid >

</vs:DialogWindow>

0 comments on commit fbc4df6

Please sign in to comment.