Skip to content

Commit 62466f1

Browse files
committed
Remove artifacts compilation
1 parent 85bcd2f commit 62466f1

File tree

4 files changed

+6
-93
lines changed

4 files changed

+6
-93
lines changed

src/Neo.Compiler.CSharp/Options.cs

-9
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,12 @@ namespace Neo.Compiler
1616
{
1717
public class Options
1818
{
19-
public enum GenerateArtifactsKind
20-
{
21-
None,
22-
Source,
23-
Library,
24-
SourceAndLibrary
25-
}
26-
2719
public string? Output { get; set; }
2820
public string? BaseName { get; set; }
2921
public NullableContextOptions Nullable { get; set; }
3022
public bool Checked { get; set; }
3123
public bool Debug { get; set; }
3224
public bool Assembly { get; set; }
33-
public GenerateArtifactsKind GenerateArtifacts { get; set; } = GenerateArtifactsKind.Source;
3425
public bool NoOptimize { get; set; }
3526
public bool NoInline { get; set; }
3627
public byte AddressVersion { get; set; }

src/Neo.Compiler.CSharp/Program.cs

+3-71
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// modifications are permitted.
1010

1111
using Microsoft.CodeAnalysis;
12-
using Microsoft.CodeAnalysis.CSharp;
13-
using Microsoft.CodeAnalysis.Emit;
1412
using Neo.IO;
1513
using Neo.Json;
1614
using Neo.Optimizer;
@@ -21,7 +19,6 @@
2119
using System.CommandLine;
2220
using System.CommandLine.Invocation;
2321
using System.CommandLine.NamingConventionBinder;
24-
using System.ComponentModel;
2522
using System.IO;
2623
using System.IO.Compression;
2724
using System.Linq;
@@ -42,7 +39,6 @@ static int Main(string[] args)
4239
new Option<bool>("--checked", "Indicates whether to check for overflow and underflow."),
4340
new Option<bool>(new[] { "-d", "--debug" }, "Indicates whether to generate debugging information."),
4441
new Option<bool>("--assembly", "Indicates whether to generate assembly."),
45-
new Option<Options.GenerateArtifactsKind>("--generate-artifacts", "Instruct the compiler how to generate artifacts."),
4642
new Option<bool>("--no-optimize", "Instruct the compiler not to optimize the code."),
4743
new Option<bool>("--no-inline", "Instruct the compiler not to insert inline code."),
4844
new Option<byte>("--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
181177
return 1;
182178
}
183179
Console.WriteLine($"Created {path}");
184-
185-
if (options.GenerateArtifacts != Options.GenerateArtifactsKind.None)
186180
{
187181
var artifact = manifest.Abi.GetArtifactsSource(baseName);
188182

189-
if (options.GenerateArtifacts == Options.GenerateArtifactsKind.SourceAndLibrary || options.GenerateArtifacts == Options.GenerateArtifactsKind.Source)
190-
{
191-
path = Path.Combine(outputFolder, $"{baseName}.artifacts.cs");
192-
File.WriteAllText(path, artifact);
193-
Console.WriteLine($"Created {path}");
194-
}
195-
196-
if (options.GenerateArtifacts == Options.GenerateArtifactsKind.SourceAndLibrary || options.GenerateArtifacts == Options.GenerateArtifactsKind.Library)
197-
{
198-
try
199-
{
200-
// Try to compile the artifacts into a dll
201-
202-
string coreDir = Path.GetDirectoryName(typeof(object).Assembly.Location)!;
203-
204-
var syntaxTree = CSharpSyntaxTree.ParseText(artifact);
205-
var references = new MetadataReference[]
206-
{
207-
MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.dll")),
208-
MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.InteropServices.dll")),
209-
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
210-
MetadataReference.CreateFromFile(typeof(DisplayNameAttribute).Assembly.Location),
211-
MetadataReference.CreateFromFile(typeof(System.Numerics.BigInteger).Assembly.Location),
212-
MetadataReference.CreateFromFile(typeof(UInt160).Assembly.Location),
213-
MetadataReference.CreateFromFile(typeof(SmartContract.Testing.SmartContract).Assembly.Location)
214-
};
215-
216-
var compilation = CSharpCompilation.Create(baseName, new[] { syntaxTree }, references,
217-
new CSharpCompilationOptions(
218-
OutputKind.DynamicallyLinkedLibrary,
219-
optimizationLevel: OptimizationLevel.Release,
220-
platform: Platform.AnyCpu,
221-
deterministic: true
222-
));
223-
224-
using var ms = new MemoryStream();
225-
EmitResult result = compilation.Emit(ms);
226-
227-
if (!result.Success)
228-
{
229-
var failures = result.Diagnostics.Where(diagnostic =>
230-
diagnostic.IsWarningAsError ||
231-
diagnostic.Severity == DiagnosticSeverity.Error);
232-
233-
foreach (var diagnostic in failures)
234-
{
235-
Console.Error.WriteLine("{0}: {1}", diagnostic.Id, diagnostic.GetMessage());
236-
}
237-
}
238-
else
239-
{
240-
ms.Seek(0, SeekOrigin.Begin);
241-
242-
// Write dll
243-
244-
path = Path.Combine(outputFolder, $"{baseName}.artifacts.dll");
245-
File.WriteAllBytes(path, ms.ToArray());
246-
Console.WriteLine($"Created {path}");
247-
}
248-
}
249-
catch
250-
{
251-
Console.Error.WriteLine("Artifacts compilation error.");
252-
}
253-
}
183+
path = Path.Combine(outputFolder, $"{baseName}.artifacts.cs");
184+
File.WriteAllText(path, artifact);
185+
Console.WriteLine($"Created {path}");
254186
}
255187
if (options.Debug)
256188
{

tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj

+1-11
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,9 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<ProjectReference Include="..\..\src\Neo.Compiler.CSharp\Neo.Compiler.CSharp.csproj" />
16-
<ProjectReference Include="..\..\src\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj">
17-
<Aliases>scfx</Aliases>
18-
</ProjectReference>
1915
<ProjectReference Include="..\..\src\Neo.SmartContract.Testing\Neo.SmartContract.Testing.csproj" />
2016
</ItemGroup>
2117

22-
<ItemGroup>
23-
<Reference Include="Nep17Contract">
24-
<HintPath>templates\neocontractnep17\Artifacts\Nep17Contract.artifacts.dll</HintPath>
25-
</Reference>
26-
</ItemGroup>
27-
2818
<ItemGroup>
2919
<None Update="templates\neocontractnep17\Artifacts\Nep17Contract.manifest.json">
3020
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -42,7 +32,7 @@
4232
<Exec Command="dotnet new uninstall Neo.SmartContract.Template" />
4333
<Exec Command="dotnet remove &quot;$(SolutionDir)src/Neo.SmartContract.Template/$(OutputPath)/Nep17Contract.csproj&quot; package Neo.SmartContract.Framework" />
4434
<Exec Command="dotnet add &quot;$(SolutionDir)src/Neo.SmartContract.Template/$(OutputPath)/Nep17Contract.csproj&quot; reference &quot;$(SolutionDir)src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj&quot;" />
45-
<Exec Command="dotnet $(SolutionDir)src/Neo.Compiler.CSharp/$(OutputPath)/nccs.dll $(NullableArgument) $(CheckedArgument) $(DebugArgument) &quot;$(SolutionDir)src/Neo.SmartContract.Template/$(OutputPath)/Nep17Contract.csproj&quot; -o &quot;$(SolutionDir)tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Artifacts&quot; --generate-artifacts library" />
35+
<Exec Command="dotnet $(SolutionDir)src/Neo.Compiler.CSharp/$(OutputPath)/nccs.dll $(NullableArgument) $(CheckedArgument) $(DebugArgument) &quot;$(SolutionDir)src/Neo.SmartContract.Template/$(OutputPath)/Nep17Contract.csproj&quot; -o &quot;$(SolutionDir)tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Artifacts&quot;" />
4636
</Target>
4737

4838
</Project>

tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace Neo.SmartContract.Template.UnitTests.templates.neocontractnep17
1111
[TestClass]
1212
public class Nep17ContractTests
1313
{
14-
private const string NefFilePath = "templates/neocontractnep17/UtArtifacts/Nep17Contract.nef";
15-
private const string ManifestPath = "templates/neocontractnep17/UtArtifacts/Nep17Contract.manifest.json";
14+
private const string NefFilePath = "templates/neocontractnep17/Artifacts/Nep17Contract.nef";
15+
private const string ManifestPath = "templates/neocontractnep17/Artifacts/Nep17Contract.manifest.json";
1616

1717
private readonly TestEngine Engine;
1818
private readonly Nep17Contract Nep17;

0 commit comments

Comments
 (0)