Merge solc output selection config#6605
Merge solc output selection config#6605ItsNickBarry wants to merge 11 commits intoNomicFoundation:v-nextfrom
Conversation
|
I suppose the object keys also need to be sorted, but the default is not sorted. |
|
This would be useful as an exported helper function so that plugins can make additions to the output selection without overwriting. |
zoeyTM
left a comment
There was a problem hiding this comment.
Will approve after a couple of minor changes, but this looks great overall. Thanks!
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compilation-job.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compilation-job.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compilation-job.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compilation-job.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Zoey <probablyzoey+github@gmail.com>
|
|
@zoeyTM I think this should be exported as a helper function. Plugins often need to add output selection. They could copy/paste this code, but it's ugly and should be hidden behind a function. Otherwise I think they might do it incorrectly and potentially clash with each other. However, I don't know where to put such a function. |
| const configFileOutputSelection = configOutputSelection[fileKey] ?? {}; | ||
| outputSelection[fileKey] ??= {}; | ||
|
|
||
| for (const contractKey of Object.keys(configFileOutputSelection).sort()) { |
There was a problem hiding this comment.
I don't think sorting the keys is strictly necessary because they order of keys isn't expected to change, but it's better to keep the object in a normalized state.
There was a problem hiding this comment.
Maybe not, actually. I can't quite contrive a situation in which a plugin would reasonably change key order without adding or removing keys.
|
@zoeyTM What do you think of this? Everything is sorted and empty entries are ignored. const configOutputSelection = settings.outputSelection ?? {};
const outputSelection: typeof defaultOutputSelection = {};
const fileKeys = Array.from(
new Set([
...Object.keys(defaultOutputSelection),
...Object.keys(configOutputSelection),
]),
).sort();
for (const fileKey of fileKeys) {
const contractKeys = Array.from(
new Set([
...Object.keys(defaultOutputSelection[fileKey] ?? {}),
...Object.keys(configOutputSelection[fileKey] ?? {}),
]),
).sort();
for (const contractKey of contractKeys) {
const values = Array.from(
new Set([
...(defaultOutputSelection[fileKey]?.[contractKey] ?? []),
...(configOutputSelection[fileKey]?.[contractKey] ?? []),
]),
).sort();
if (values.length > 0) {
outputSelection[fileKey] = {};
outputSelection[fileKey][contractKey] = values;
}
}
} |
|
Shouldn't all of this go in the config hook? |
|
I think this can be simplified, and @zoeyTM should have some time to do it now. The reason that I think this could be simpler that all we need from Hardhat's point of view is ensure that these are set, as both Hardhat and EDR need them: So we can just clone whatever the user provides, and add those selectors if not present. If that's the case, do you think you'd need a helper? can you explain the use case? Wouldn't just getting the build project from |
|
I was thinking that both users and plugin developers would expect to be able to pass in an output selection object with the same standard structure. The object isn't even documented (argotorg/solidity#15744), so it's uncomfortable to manipulate directly. The HH solidity module is also a plugin, and doesn't need to behave any differently. Isn't this a config resolution problem that should be done in the resolveConfig hook? This is what the code looks like without a helper: const settings = compiler.settings;
settings.outputSelection ??= {};
settings.outputSelection['*'] ??= {};
settings.outputSelection['*']['*'] ??= [];
if (!settings.outputSelection['*']['*'].includes('storageLayout')) {
settings.outputSelection['*']['*'].push('storageLayout');
}It's not that bad, but needs to be duplicated in at least 4 places:
I'd rather do something like this: const STORAGE_LAYOUT_OUTPUT_SELECTION = { '*': { '*': ['storageLayout'] } };
settings.outputSelection = mergeOutputSelection(settings.outputSelection, STORAGE_LAYOUT_OUTPUT_SELECTION);Then, nobody has to think about any of these issues:
|
|
I am closing this PR, thanks @ItsNickBarry, the approach was encoded in these two PRs:
The discussion around exposing the helper function to plugin authors I am going to capture in a separate issue: #6704. |
closes #6551