From 62466f14c3bce3bb50ddcde1b50ccbf145963544 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Tue, 13 Feb 2024 14:17:46 +0100 Subject: [PATCH] Remove artifacts compilation --- src/Neo.Compiler.CSharp/Options.cs | 9 --- src/Neo.Compiler.CSharp/Program.cs | 74 +------------------ ...eo.SmartContract.Template.UnitTests.csproj | 12 +-- .../neocontractnep17/Nep17ContractTests.cs | 4 +- 4 files changed, 6 insertions(+), 93 deletions(-) diff --git a/src/Neo.Compiler.CSharp/Options.cs b/src/Neo.Compiler.CSharp/Options.cs index 204a6b5c5..19a2c449b 100644 --- a/src/Neo.Compiler.CSharp/Options.cs +++ b/src/Neo.Compiler.CSharp/Options.cs @@ -16,21 +16,12 @@ namespace Neo.Compiler { public class Options { - public enum GenerateArtifactsKind - { - None, - Source, - Library, - SourceAndLibrary - } - public string? Output { get; set; } public string? BaseName { get; set; } public NullableContextOptions Nullable { get; set; } public bool Checked { get; set; } public bool Debug { get; set; } public bool Assembly { get; set; } - public GenerateArtifactsKind GenerateArtifacts { get; set; } = GenerateArtifactsKind.Source; public bool NoOptimize { get; set; } public bool NoInline { get; set; } public byte AddressVersion { get; set; } diff --git a/src/Neo.Compiler.CSharp/Program.cs b/src/Neo.Compiler.CSharp/Program.cs index 6c7fa3527..d58e42083 100644 --- a/src/Neo.Compiler.CSharp/Program.cs +++ b/src/Neo.Compiler.CSharp/Program.cs @@ -9,8 +9,6 @@ // modifications are permitted. using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Emit; using Neo.IO; using Neo.Json; using Neo.Optimizer; @@ -21,7 +19,6 @@ using System.CommandLine; using System.CommandLine.Invocation; using System.CommandLine.NamingConventionBinder; -using System.ComponentModel; using System.IO; using System.IO.Compression; using System.Linq; @@ -42,7 +39,6 @@ static int Main(string[] args) new Option("--checked", "Indicates whether to check for overflow and underflow."), new Option(new[] { "-d", "--debug" }, "Indicates whether to generate debugging information."), new Option("--assembly", "Indicates whether to generate assembly."), - new Option("--generate-artifacts", "Instruct the compiler how to generate artifacts."), new Option("--no-optimize", "Instruct the compiler not to optimize the code."), new Option("--no-inline", "Instruct the compiler not to insert inline code."), new Option("--address-version", () => ProtocolSettings.Default.AddressVersion, "Indicates the address version used by the compiler.") @@ -181,76 +177,12 @@ private static int ProcessOutputs(Options options, string folder, CompilationCon return 1; } Console.WriteLine($"Created {path}"); - - if (options.GenerateArtifacts != Options.GenerateArtifactsKind.None) { var artifact = manifest.Abi.GetArtifactsSource(baseName); - if (options.GenerateArtifacts == Options.GenerateArtifactsKind.SourceAndLibrary || options.GenerateArtifacts == Options.GenerateArtifactsKind.Source) - { - path = Path.Combine(outputFolder, $"{baseName}.artifacts.cs"); - File.WriteAllText(path, artifact); - Console.WriteLine($"Created {path}"); - } - - if (options.GenerateArtifacts == Options.GenerateArtifactsKind.SourceAndLibrary || options.GenerateArtifacts == Options.GenerateArtifactsKind.Library) - { - try - { - // Try to compile the artifacts into a dll - - string coreDir = Path.GetDirectoryName(typeof(object).Assembly.Location)!; - - var syntaxTree = CSharpSyntaxTree.ParseText(artifact); - var references = new MetadataReference[] - { - MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.dll")), - MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.InteropServices.dll")), - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(DisplayNameAttribute).Assembly.Location), - MetadataReference.CreateFromFile(typeof(System.Numerics.BigInteger).Assembly.Location), - MetadataReference.CreateFromFile(typeof(UInt160).Assembly.Location), - MetadataReference.CreateFromFile(typeof(SmartContract.Testing.SmartContract).Assembly.Location) - }; - - var compilation = CSharpCompilation.Create(baseName, new[] { syntaxTree }, references, - new CSharpCompilationOptions( - OutputKind.DynamicallyLinkedLibrary, - optimizationLevel: OptimizationLevel.Release, - platform: Platform.AnyCpu, - deterministic: true - )); - - using var ms = new MemoryStream(); - EmitResult result = compilation.Emit(ms); - - if (!result.Success) - { - var failures = result.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || - diagnostic.Severity == DiagnosticSeverity.Error); - - foreach (var diagnostic in failures) - { - Console.Error.WriteLine("{0}: {1}", diagnostic.Id, diagnostic.GetMessage()); - } - } - else - { - ms.Seek(0, SeekOrigin.Begin); - - // Write dll - - path = Path.Combine(outputFolder, $"{baseName}.artifacts.dll"); - File.WriteAllBytes(path, ms.ToArray()); - Console.WriteLine($"Created {path}"); - } - } - catch - { - Console.Error.WriteLine("Artifacts compilation error."); - } - } + path = Path.Combine(outputFolder, $"{baseName}.artifacts.cs"); + File.WriteAllText(path, artifact); + Console.WriteLine($"Created {path}"); } if (options.Debug) { diff --git a/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj b/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj index 2810aaaee..bb3af2fd8 100644 --- a/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj +++ b/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj @@ -12,19 +12,9 @@ - - - scfx - - - - templates\neocontractnep17\Artifacts\Nep17Contract.artifacts.dll - - - PreserveNewest @@ -42,7 +32,7 @@ - + diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs index f9e952d9e..6056dd05d 100644 --- a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs @@ -11,8 +11,8 @@ namespace Neo.SmartContract.Template.UnitTests.templates.neocontractnep17 [TestClass] public class Nep17ContractTests { - private const string NefFilePath = "templates/neocontractnep17/UtArtifacts/Nep17Contract.nef"; - private const string ManifestPath = "templates/neocontractnep17/UtArtifacts/Nep17Contract.manifest.json"; + private const string NefFilePath = "templates/neocontractnep17/Artifacts/Nep17Contract.nef"; + private const string ManifestPath = "templates/neocontractnep17/Artifacts/Nep17Contract.manifest.json"; private readonly TestEngine Engine; private readonly Nep17Contract Nep17;