-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Replace project directory in metadata with "project://" #4137
Conversation
packages/compile-solidity/run.js
Outdated
rawSources, | ||
options.compilationTargets, | ||
options.working_directory, | ||
"project:/" //only one slash, other will already be present |
There was a problem hiding this comment.
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:/"?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
I find it pretty surprising, but cool, that this is already supported by the Solidity compiler. |
There was a problem hiding this 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
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 theabsolutePath
field on the AST, although we don't currently using that. It does not affect thesourcePath
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 incompile-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 incompile-solidity
as well.I also added a test, and moved a comment I noticed was in the wrong place.