Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow neon to compile from the source (2x) #142

Merged
merged 13 commits into from Dec 23, 2019

Conversation

shargon
Copy link
Member

@shargon shargon commented Nov 30, 2019

Close #78
Port of #131 to 2x

@shargon
Copy link
Member Author

shargon commented Dec 5, 2019

Any update @lock9 @devhawk ?

@devhawk
Copy link
Contributor

devhawk commented Dec 5, 2019

I'll need to take a look at this. We have other changes to the compiler (#144 as well as the temporary neon-de fork that I'm not sure how we are going to replicate going C# -> AVM directly.

@shargon
Copy link
Member Author

shargon commented Dec 14, 2019

@devhawk Some ut was wrong and fixed, please take a look

@nicolegys
Copy link

Test:

Compile from .cs: Success
image

Compile from .csproj: Fail
image

Here failed, because the value of projDefinition wasn't the content in the .csproj file.
image

In addition, could you also add some help info to make neon more friendly?

@shargon
Copy link
Member Author

shargon commented Dec 17, 2019

Can you copy your csproj file?

@nicolegys
Copy link

Sorry, I've got it wrong. projDefinition has no problem, but I found.
1.If my .csproj file has xmlns, there will be some problem when reading this file.
2.If my .csproj file doesn't have some element like PackageReference, it will throw an exception.

<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{2712642F-46ED-47B6-95D9-FB2567BFA2F5}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>NEP5</RootNamespace>
    <AssemblyName>NEP5</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>
    </DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Neo.SmartContract.Framework, Version=2.7.3.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>.\Neo.SmartContract.Framework.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Numerics" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="NEP5.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="packages.config" />
    <None Include="build.tasks" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="Neo.ConvertTask.dll" />
    <Content Include="Neo.SmartContract.Framework.dll" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="Build.tasks" />
  <Target Name="AfterBuild">
    <Message Text="Start NeoContract converter, Source File: $(TargetPath)" Importance="high">
    </Message>
    <ConvertTask DataSource="$(TargetPath)" />
  </Target>
</Project>

@shargon
Copy link
Member Author

shargon commented Dec 17, 2019

Thanks @nicolegys , could you test it again please? (If works we should port this change to 3x)

@nicolegys
Copy link

Compile from .csproj file:

image

Succeed!

shargon added a commit that referenced this pull request Dec 18, 2019
@shargon shargon mentioned this pull request Dec 18, 2019
@shargon
Copy link
Member Author

shargon commented Dec 18, 2019

Any update @lock9 @devhawk ?

@devhawk
Copy link
Contributor

devhawk commented Dec 18, 2019

Has this been tested with https://github.com/neo-project/neo-debugger? The screen shot above shows the .avmdbgnfo file getting created, so that's a good sign

var log = new DefLogger();
log.Log("Neo.Compiler.MSIL console app v" + Assembly.GetEntryAssembly().GetName().Version);

// Check argmuents
if (args.Length == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a library for command line processing? neo-express uses https://github.com/natemcmaster/CommandLineUtils and I've been pretty happy with it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we don't have a lot of arguments, only a file name, was discarded in other PR
7364563

if (args.Length == 0)
{
log.Log("You need a parameter to specify the DLL or the file name of the project.");
log.Log("Examples: ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also support single .cs files right?

We should have a --help option

@devhawk
Copy link
Contributor

devhawk commented Dec 18, 2019

looks good, a few pieces of minor feedback. I want to test to make sure it also fixes #78 before I sign off

@devhawk
Copy link
Contributor

devhawk commented Dec 18, 2019

I tried creating a contract from template and compiling it with neon built out of this PR branch and it didn't work:

C:\Users\harry\Source\neo\seattle\samples\hello2 > dotnet new neo-contract
The template "Neo Smart Contract" was created successfully.
C:\Users\harry\Source\neo\seattle\samples\hello2 > neon .\hello2.csproj
Neo.Compiler.MSIL console app v2.6.0.0
Compiling from csproj project
Unhandled exception. System.IO.FileNotFoundException: Could not find file 'C:\Users\harry\Source\neo\seattle\samples\hello2\Neo.SmartContract.Framework.dll'.
File name: 'C:\Users\harry\Source\neo\seattle\samples\hello2\Neo.SmartContract.Framework.dll'
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.OpenRead(String path)
   at Roslyn.Utilities.FileUtilities.OpenFileStream(String path)
   at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
   at Neo.Compiler.Compiler.<>c.<CreateReferences>b__6_0(String u) in C:\Users\harry\Source\neo\official\devpack-dotnet\Neo.Compiler.MSIL\Compiler.cs:line 195
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at Neo.Compiler.Compiler.CreateReferences(String[] references) in C:\Users\harry\Source\neo\official\devpack-dotnet\Neo.Compiler.MSIL\Compiler.cs:line 195
   at Neo.Compiler.Compiler.CompileCSFile(String[] filenames, String[] references, Boolean releaseMode) in C:\Users\harry\Source\neo\official\devpack-dotnet\Neo.Compiler.MSIL\Compiler.cs:line 175
   at Neo.Compiler.Compiler.CompileCSProj(String filename, Boolean releaseMode) in C:\Users\harry\Source\neo\official\devpack-dotnet\Neo.Compiler.MSIL\Compiler.cs:line 77
   at Neo.Compiler.Program.Main(String[] args) in C:\Users\harry\Source\neo\official\devpack-dotnet\Neo.Compiler.MSIL\Program.cs:line 105

default:
{
log.Log("File format not supported by neon: " + path);
Environment.Exit(-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, should just return -1 instead of using environment exit

<PackageReference Include="Neo.VM" Version="2.4.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good idea. Today, the Neo.SmartContract.Framework versions independently from NEON. With this change, the version of Neo.SmartContract.Framework is hardcoded into the compiler.

Unfortunately, it appears this is the change that allows NEON to compile dlls on build instead of publish.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was decided in 3x to include it to facilitate developers

Copy link
Contributor

@devhawk devhawk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't embed Neo.SmartContract.Framework in neon

@devhawk
Copy link
Contributor

devhawk commented Dec 18, 2019

FYI, I have an idea on how to locate the Neo.SmartContract.Framework assembly at runtime.

The Microsoft.Extensions.DependencyModel nuget package can be used to parse the .deps.json file that is generated by dotnet build. I built a test app that shows how to load and resolve the dependencies to file paths.

Then with Cecil, we can build a custom assembly resolver that uses the DependencyModel information to resolve assemblies (deferring to cecil's DefaultAssemblyResolver for assemblies that aren't listed in the DependencyModel).

We'd still have to figure out how to resolve the Neo.SmartContract.Framework package for compile from source. Honestly, I'm OK with having an embedded version of the Neo.SmartContract.Framework assembly in NEON as long as it's only used for compile from source scenarios.

@shargon
Copy link
Member Author

shargon commented Dec 21, 2019

I tried creating a contract from template and compiling it with neon built out of this PR branch and it didn't work:

Could you try again, I think that was fixed here ee1aa41

@shargon
Copy link
Member Author

shargon commented Dec 21, 2019

don't embed Neo.SmartContract.Framework in neon

As you can see in the thread of #131 all was agree in include in neon

@devhawk
Copy link
Contributor

devhawk commented Dec 23, 2019

don't embed Neo.SmartContract.Framework in neon

As you can see in the thread of #131 all was agree in include in neon

This is probably not as big a deal as I thought it was. We don't add new services in the blockchain very often and framework changes like FeaturesAttribute require a new version of the compiler anyway.

@shargon shargon merged commit 8a0c998 into neo-project:master-2.x Dec 23, 2019
@shargon shargon deleted the compile-source-2x branch December 23, 2019 22:46
shargon added a commit that referenced this pull request Dec 23, 2019
* Apply #142 changes

* Some fixes

* Plural
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants