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 #131

Merged
merged 24 commits into from Nov 17, 2019
Merged

Conversation

shargon
Copy link
Member

@shargon shargon commented Nov 8, 2019

Close #132

  • This PR Allow to compile c# and VB scripts from it source

Without arguments

Neo.Compiler.MSIL 2.4.1
2015-2019 The Neo Project

ERROR(S):
  Required option 'f, file' is missing.

  -f, --file          Required. Specify the file to compile to NEF file

  -r, --references    Compilation references

  --help              Display this help screen.

  --version           Display version information.

Compile from source

-f "V:\Temp\sc.cs" -r "Neo.SmartContract.Framework.dll"

Neo.Compiler.MSIL console app v2.4.1.0
Auto Insert entrypoint.
convert succ
gen abi succ
write:sc.nef
write:sc.abi.json
write:sc.manifest.json
SUCC

Compile as usual

-f "V:\Temp\sc.dll"

Neo.Compiler.MSIL console app v2.4.1.0
Auto Insert entrypoint.
convert succ
gen abi succ
write:sc.nef
write:sc.abi.json
write:sc.manifest.json
SUCC

Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

Hi @shargon it is passing UT but the code is not working.
Can we make the Neo.SmartContract.Framework to be automatically referenced?

src/Neo.Compiler.MSIL/CmdOptions.cs Outdated Show resolved Hide resolved
src/Neo.Compiler.MSIL/CmdOptions.cs Outdated Show resolved Hide resolved
@lapetina9
Copy link

Neo PR Test Report

Repository: neo-devpack-dotnet
Number: 131
Title: Allow neon to compile from the source
Change description: Neon was updated to support *.cs file compilation.

Code version / branch

Neo-devpack-dotnet: shargon:compile-source

Test Results

Test Name Network OS Test Result Comments
Initial UT Windows 10 x64 OK
Compile Contract 1 from unit tests Windows 10 x64 OK
Compile Contract 2 from unit tests Windows 10 x64 NOK Conversion errors occurred during compilation. Failed identification of Smart Contract Framework method.

Additional info

We made two tests that should have the same results, but one of them failed to compile the smart-contract. We followed instructions provided in the PR.

unknown

Test List

1. Initial UT
Run solution unit tests.

2. Compile Contract 1 from unit tests

The test was to compile the same file that is used in unit tests, using the command line.
Contract code:

namespace Neo.Compiler.MSIL.TestClasses
{
    public class Contract1 : SmartContract.Framework.SmartContract
    {
        //default smartcontract entry point.
        //but the unittest can be init from anywhere
        //no need to add code in Main.
        public static object Main(string method, object[] args)
        {
            return UnitTest_001();
        }
        public static byte[] UnitTest_001()
        {
            var nb = new byte[] { 1, 2, 3, 4 };
            return nb;
        }

    }
}

Expected result:

  • File compiled sucessfully.

3. Compile Contract 2 from unit tests
The test was to compile the same file that is used in unit tests, using the command line.
Contract code:

namespace Neo.Compiler.MSIL.TestClasses
{
    public class Contract2 : SmartContract.Framework.SmartContract
    {
        //default smartcontract entry point.
        //but the unittest can be init from anywhere
        //no need to add code in Main.
        public static object Main(string method, object[] args)
        {
            Neo.SmartContract.Framework.Services.Neo.Runtime.Notify(args[0]);
            Neo.SmartContract.Framework.Services.Neo.Runtime.Notify(args[2]);
            return UnitTest_002();
        }
        public static byte UnitTest_002()
        {
            var nb = new byte[] { 1, 2, 3, 4 };
            return nb[2];
        }
    }
}

Expected result:

  • File compiled sucessfully.

Actual result:
Compilation failed caused by Neo.SmartContract.Framework not being found.

@lock9 lock9 added the NOK Didn't pass tests or require changes label Nov 8, 2019
@shargon
Copy link
Member Author

shargon commented Nov 9, 2019

Can we make the Neo.SmartContract.Framework to be automatically referenced?

If everyone want to, yes, it's easy

@shargon
Copy link
Member Author

shargon commented Nov 9, 2019

but the code is not working.

What doesn't work, could you explain it?

@shargon
Copy link
Member Author

shargon commented Nov 9, 2019

Compilation failed caused by Neo.SmartContract.Framework not being found.

That's the reason of references 😂 You obtain the same behavior in Visual Studio

@shargon shargon requested a review from lock9 November 9, 2019 10:22
@lightszero
Copy link
Member

I think build from a csproj is more better.

@shargon
Copy link
Member Author

shargon commented Nov 11, 2019

@lock9 could you review it again?

@lock9
Copy link
Contributor

lock9 commented Nov 11, 2019

@shargon we are trying to deploy a SC into neo 3 testnet but we are having several issues. I will test this later today

Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

The code is well written and it is very clear. My only suggestion would be to move the content inside that switch to methods.

src/Neo.Compiler.MSIL/Program.cs Show resolved Hide resolved
Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

Hi @shargon, please check shargon#3.
It doesn't work if we reference external dlls but this is totally acceptable.

@shargon shargon requested a review from lock9 November 13, 2019 10:25
@erikzhang
Copy link
Member

I think "Neo.SmartContract.Framework.dll" should be added as a reference by default. There is no need to add it manually.

Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

Thank you for the changes, this will help a lot to use the compiler. I'm just waiting for the Erik to check if we should use nuget or code references are ok.

src/Neo.Compiler.MSIL/Program.cs Outdated Show resolved Hide resolved
src/Neo.Compiler.MSIL/Program.cs Show resolved Hide resolved
@shargon shargon requested a review from lock9 November 15, 2019 13:20
Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

It works perfectly. Thanks!

src/Neo.Compiler.MSIL/Compiler.cs Show resolved Hide resolved
@lock9 lock9 added OK Passed tests and removed NOK Didn't pass tests or require changes labels Nov 15, 2019
@lock9 lock9 merged commit 63e90e5 into neo-project:master Nov 17, 2019
@shargon shargon deleted the compile-source branch November 17, 2019 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OK Passed tests port-to-2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Neon should be able to compile from the source
5 participants