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

feat: implement flattening api [APE-794] #107

Merged
merged 31 commits into from
Jun 28, 2023

Conversation

z80dev
Copy link
Contributor

@z80dev z80dev commented Jun 5, 2023

What I did

fixes: APE-794

How I did it

Recursively get the contents of imported files, then concatenate all into one output.

This matches hardhat's behavior of not processing the files in certain ways required for actual compilation, for example removing multiple (and sometimes conflicting) SPDX license lines

How to verify it

tests WIP

Checklist

  • Passes all linting checks (pre-commit and CI jobs)
  • New test cases have been added and are passing
  • Documentation has been updated
  • PR title follows Conventional Commit standard (will be automatically included in the changelog)

@vany365 vany365 changed the title implement flattening api implement flattening api [APE-1017] Jun 5, 2023
@z80dev z80dev changed the title implement flattening api [APE-1017] feat: implement flattening api [APE-1017] Jun 6, 2023
@z80dev
Copy link
Contributor Author

z80dev commented Jun 15, 2023

Much closer now. Added the following features:

  • Remove 'import' statements from flattened output
  • Include original filename in comment (i.e. // File: @devorg/contracts/CoolContract.sol before the contents from that file)

Missing: Everything around handling the license issue, I will begin by implementing license conflict detection and warning in the case of multiple licenses. In the case of only one license, I'll strip all the SPDX statements and leave one at the top of the file

Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

talked offline, but thinking we could do a reverse look-up for the File comment to get the path you need

ape_solidity/compiler.py Outdated Show resolved Hide resolved
ape_solidity/compiler.py Outdated Show resolved Hide resolved
ape_solidity/compiler.py Outdated Show resolved Hide resolved
ape_solidity/compiler.py Outdated Show resolved Hide resolved
Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

this looking close!

when you get a chance, can you start the test? i would like to see what a flattened Imports.sol looks like

ape_solidity/compiler.py Outdated Show resolved Hide resolved
ape_solidity/compiler.py Outdated Show resolved Hide resolved
@vany365 vany365 changed the title feat: implement flattening api [APE-1017] feat: implement flattening api [APE-794] Jun 21, 2023
@antazoey
Copy link
Member

Looks like a test needs updating! See it failing in CI. It is from the newly added import, you just need to add it to the expected fields, or adjust the test.

@z80dev z80dev marked this pull request as ready for review June 22, 2023 18:45
@z80dev z80dev enabled auto-merge (squash) June 22, 2023 19:02
Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

mainly wondering about multiple pragmas now

tests/data/ImportsFlattened.sol.txt Show resolved Hide resolved
ape_solidity/compiler.py Outdated Show resolved Hide resolved
@z80dev
Copy link
Contributor Author

z80dev commented Jun 26, 2023

Weird unrelated test error occuring on python 3.8, tests run locally on my machine with 3.10 all pass. index out of bounds error

any ideas @antazoey ?

@antazoey
Copy link
Member

any ideas @antazoey ?

I am pretty sure I ran into this on a separate branch and fixed it there. I just merged that PR and then updated your branch here and so no we will see if that fixes it.

@z80dev z80dev merged commit dc6cdea into ApeWorX:main Jun 28, 2023
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.

2 participants