Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Replace project directory in metadata with "project://" #4137

Merged
merged 3 commits into from
Jun 29, 2021

Conversation

haltman-at
Copy link
Contributor

Addresses #4119.

Per discussion there, this PR changes our input to the Solidity compiler so that the Truffle project directory will be replaced (in input to the Solidity compiler) with "project://". In addition to affecting the metadata, this also affects the absolutePath field on the AST, although we don't currently using that. It does not affect the sourcePath field in the artifacts.

Note that this only affects sources that live in the project directory. Sources imported from, e.g., NPM, will be unaffected. However, since sources imported from NPM will be given by an NPM path rather than an absolute file path, this is fine.

What about FS sources living outside the project directory? Well, those probably just won't work anymore, as the compiler won't be able to find them.

To implement this, I reused existing functionality from compile-vyper. (Well, the functionality lives in compile-common, but it was added for Vyper purposes.) We already do something similar for Vyper, although slightly differently and for different reasons. I just expanded the functionality to cover replacing a prefix instead of just removing a prefix, and invoked it in compile-solidity as well.

I also added a test, and moved a comment I noticed was in the wrong place.

rawSources,
options.compilationTargets,
options.working_directory,
"project:/" //only one slash, other will already be present
Copy link
Contributor

@eggplantzzz eggplantzzz Jun 24, 2021

Choose a reason for hiding this comment

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

Maybe this is a little pedantic but is it technically more proper to have this argument be the complete replacement string? Then we should strip off the relative path portion and replace it with "exactly" what we will be using? Like what if (and yeah, I think this is pretty pedantic) one day we decide to use "project::" instead of "project:/"?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree about replacement style - better to replace the whole thing

Copy link
Member

Choose a reason for hiding this comment

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

+1 on that as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I've changed this.

@eggplantzzz
Copy link
Contributor

eggplantzzz commented Jun 24, 2021

I find it pretty surprising, but cool, that this is already supported by the Solidity compiler.

Copy link
Member

@cds-amal cds-amal left a comment

Choose a reason for hiding this comment

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

Looks good @haltman-at

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

Successfully merging this pull request may close these issues.

None yet

4 participants