1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* External Imports */
import fsExtra from 'fs-extra'
import { internalTask } from '@nomiclabs/buidler/config'
import { pluralize } from '@nomiclabs/buidler/internal/util/strings'
import {
getArtifactFromContractOutput,
saveArtifact,
} from '@nomiclabs/buidler/internal/artifacts'
import {
TASK_COMPILE_GET_COMPILER_INPUT,
TASK_BUILD_ARTIFACTS,
TASK_COMPILE_GET_SOURCE_PATHS,
TASK_COMPILE_CHECK_CACHE,
TASK_COMPILE_COMPILE,
} from '@nomiclabs/buidler/builtin-tasks/task-names'
internalTask(
TASK_COMPILE_GET_COMPILER_INPUT,
async (_, { config, run }, runSuper) => {
const input = await runSuper()
// Insert the "storageLayout" input option.
input.settings.outputSelection['*']['*'].push('storageLayout')
return input
}
)
internalTask(TASK_BUILD_ARTIFACTS).setAction(
async ({ force }, { config, run }) => {
const sources = await run(TASK_COMPILE_GET_SOURCE_PATHS)
if (sources.length === 0) {
console.log('No Solidity source file available.')
return
}
const isCached: boolean = await run(TASK_COMPILE_CHECK_CACHE, { force })
if (isCached) {
console.log(
'All contracts have already been compiled, skipping compilation.'
)
return
}
const compilationOutput = await run(TASK_COMPILE_COMPILE)
if (compilationOutput === undefined) {
return
}
await fsExtra.ensureDir(config.paths.artifacts)
let numberOfContracts = 0
for (const file of Object.values<any>(compilationOutput.contracts)) {
for (const [contractName, contractOutput] of Object.entries(file)) {
const artifact: any = getArtifactFromContractOutput(
contractName,
contractOutput
)
numberOfContracts += 1
// Only difference here, set the "storageLayout" field of the artifact.
artifact.storageLayout = (contractOutput as any).storageLayout
await saveArtifact(config.paths.artifacts, artifact)
}
}
console.log(
'Compiled',
numberOfContracts,
pluralize(numberOfContracts, 'contract'),
'successfully'
)
}
)