Native loading strategy to support TRUFFLE_NATIVE_SOLC_PATH#6007
Native loading strategy to support TRUFFLE_NATIVE_SOLC_PATH#6007hellwolf wants to merge 6 commits intoConsenSys-archive:developfrom
Conversation
|
This would also be benefiting from #6008 |
There was a problem hiding this comment.
Thanks @hellwolf !
Apologies for the empty review summary. I accidentally submitted before going to sleep.
I think this logic belongs in @truffle/config where other such concerns are kept. @truffle/config uses a some meta-programming techniques to store and calculate default values. See here; for example, the following is an example of how the default could work, though there is a better name than nativePath 🤔 @gnidan? @eggplantzzz , @haltman-at ?
// ...
compilers: {
solc: {
nativePath: `{process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"}`
// ...Edit: Ooops.
| load() { | ||
| const versionString = this.validateAndGetSolcVersion(); | ||
| const command = "solc --standard-json"; | ||
| const command = (process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc") + " --standard-json"; |
There was a problem hiding this comment.
| const command = (process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc") + " --standard-json"; | |
| const command = `${process.env.TRUFFLE_NATIVE_SOLC_PATH ?? "solc"} --standard-json`; |
This would read easier using template literals and the nullish coalescing operator
There was a problem hiding this comment.
This is nitpicking, but if we're going to argue about || vs ??, I'd kind of prefer || because what if someone sets this variable to the empty string as a way of attempting to unset it, or something? Idk exactly what the interface is on process.env, maybe this is a non-concern, but to my mind unless there's some particular falsy value you're worried about causing problems, it makes sense ot use || instead of ??.
There was a problem hiding this comment.
I think you are right @haltman-at , that value can sometimes actually be empty string.
There was a problem hiding this comment.
I merged the suggestion but still using "||"
There was a problem hiding this comment.
Hey @hellwolf , sorry about the confusion. I requested changes for an issue I didn't document. I was tired and thought I'd comeback to it this morning, only to realize I submitted it. 😞 I updated my review.
There was a problem hiding this comment.
No worries.
But I didn't know "nativePath" was an option, I don't seem to be able to find the reference to that in code.
There was a problem hiding this comment.
But I didn't know "nativePath" was an option, I don't seem to be able to find the reference to that in code.
nativePath doesn't currently exist. However, the location I shared, is where one could define this new configuration, and set its defaults depending on the ENV. Of course, the setting will have to be consumed in loadingStrategies/Native.ts, and I still think there's a better name than nativePath.
|
Btw, this isn't actually a breaking change, right? It's marked as one, but I don't see how it would be... |
not breaking change. |
That could be a nice option! |
We wouldn't. That would work just as well as an env var for us. |
| if (version === "native") { | ||
| return new Native().load().version(); | ||
| const nativePath = TruffleConfig.default().compilers.solc.nativePath; | ||
| return new Native(nativePath).load().version(); |
There was a problem hiding this comment.
Hm, this always uses the default path. Should this function take an optional second argument so it can be more accurate, and the uses of it updated as necessary/possible?
Removing change request to expedite approval
cds-amal
left a comment
There was a problem hiding this comment.
I'm ready to approve, but want to check if others are ok with the environment override.
| }, | ||
| compilers: { | ||
| solc: { | ||
| nativePath: `${process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"}`, |
There was a problem hiding this comment.
I snuck this env override w/ my changes, and want to be sure @eggplantzzz and @haltman-at are ok with it.
PR description
Related to #4490
Todo
Testing instructions
Truffle compile to support the usage of process environment
TRUFFLE_NATIVE_SOLC_PATHwhencompilers.solc.versionis "native".Documentation
doc-change-requiredlabel to this PR if documentation updates are required.Breaking changes and new features
breaking-changeandnew-featurelabels for the appropriate packages.