1
1
import type { CompilationJob , CompilerInput } from "../../types/index.js" ;
2
2
3
+ const defaultSolcOutputSelection = {
4
+ "*" : {
5
+ "*" : [
6
+ "abi" ,
7
+ "evm.bytecode" ,
8
+ "evm.deployedBytecode" ,
9
+ "evm.methodIdentifiers" ,
10
+ "metadata" ,
11
+ ] ,
12
+ "" : [ "ast" ] ,
13
+ } ,
14
+ } as const ;
15
+
3
16
export function getInputFromCompilationJob (
4
17
compilationJob : CompilationJob ,
5
18
) : CompilerInput {
@@ -18,9 +31,50 @@ export function getInputFromCompilationJob(
18
31
19
32
const { settings } = compilationJob . getSolcConfig ( ) ;
20
33
21
- return {
34
+ const result = {
22
35
language : "Solidity" ,
23
36
sources,
24
- settings,
37
+ settings : settings ?? { } ,
38
+ } ;
39
+
40
+ // This code is pulled in from `resolveCompiler` in
41
+ // `packages/hardhat-core/src/internal/core/config/config-resolution.ts`
42
+ //
43
+ // In v2 the config loading sets the default values that will be passed
44
+ // to the compiler. I am pulling it to here for the moment to keep
45
+ // the build system encapsulated.
46
+ result . settings . optimizer = {
47
+ enabled : false ,
48
+ runs : 200 ,
49
+ ...result . settings . optimizer ,
25
50
} ;
51
+
52
+ if ( result . settings . outputSelection === undefined ) {
53
+ result . settings . outputSelection = { } ;
54
+ }
55
+
56
+ for ( const [ file , contractSelection ] of Object . entries (
57
+ defaultSolcOutputSelection ,
58
+ ) ) {
59
+ if ( result . settings . outputSelection [ file ] === undefined ) {
60
+ result . settings . outputSelection [ file ] = { } ;
61
+ }
62
+
63
+ for ( const [ contract , outputs ] of Object . entries ( contractSelection ) ) {
64
+ if ( result . settings . outputSelection [ file ] [ contract ] === undefined ) {
65
+ result . settings . outputSelection [ file ] [ contract ] = [ ] ;
66
+ }
67
+
68
+ for ( const output of outputs ) {
69
+ const includesOutput : boolean =
70
+ result . settings . outputSelection [ file ] [ contract ] . includes ( output ) ;
71
+
72
+ if ( ! includesOutput ) {
73
+ result . settings . outputSelection [ file ] [ contract ] . push ( output ) ;
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ return result ;
26
80
}
0 commit comments