diff options
author | F. Eugene Aumson <gene@aumson.org> | 2018-08-23 05:52:28 +0800 |
---|---|---|
committer | F. Eugene Aumson <gene@aumson.org> | 2018-08-29 02:24:26 +0800 |
commit | 849e203812aacff453228a372143600b05155a2c (patch) | |
tree | 58ba6d2cda727f0f500c78aa1eac65b0369dddbf /packages | |
parent | 80ed724f3abd019dc1bcaa9e2a0f02d69c8f6649 (diff) | |
download | dexon-sol-tools-849e203812aacff453228a372143600b05155a2c.tar.gz dexon-sol-tools-849e203812aacff453228a372143600b05155a2c.tar.zst dexon-sol-tools-849e203812aacff453228a372143600b05155a2c.zip |
add interface to return compiler output...
...rather than persisting it to the filesystem.
Diffstat (limited to 'packages')
-rw-r--r-- | packages/sol-compiler/src/compiler.ts | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index cf406b583..91b17c4f2 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -159,7 +159,18 @@ export class Compiler { public async compileAsync(): Promise<void> { await createDirIfDoesNotExistAsync(this._artifactsDir); await createDirIfDoesNotExistAsync(SOLC_BIN_DIR); - await this._compileContractsAsync(this._getContractNamesToCompile()); + await this._compileContractsAsync(this._getContractNamesToCompile(), true); + } + /** + * Compiles Solidity files specified during construction, and returns the + * compiler output given by solc. Return value is an array of outputs: + * Solidity modules are batched together by version required, and each + * element of the returned array corresponds to a compiler version, and + * each element contains the output for all of the modules compiled with + * that version. + */ + public async getCompilerOutputsAsync(): Promise<solc.StandardOutput[]> { + return this._compileContractsAsync(this._getContractNamesToCompile(), false); } private _getContractNamesToCompile(): string[] { if (this._specifiedContracts === ALL_CONTRACTS_IDENTIFIER) { @@ -172,10 +183,14 @@ export class Compiler { } } /** - * Compiles contract and saves artifact to artifactsDir. + * Compiles contracts, and, if `shouldPersist` is true, saves artifacts to artifactsDir. * @param fileName Name of contract with '.sol' extension. + * @return an array of compiler outputs, where each element corresponds to a different version of solc-js. */ - private async _compileContractsAsync(contractNames: string[]): Promise<void> { + private async _compileContractsAsync( + contractNames: string[], + shouldPersist: boolean, + ): Promise<solc.StandardOutput[]> { // batch input contracts together based on the version of the compiler that they require. const versionToInputs: VersionToInputs = {}; @@ -216,6 +231,8 @@ export class Compiler { versionToInputs[solcVersion].contractsToCompile.push(contractSource.path); } + const compilerOutputs: solc.StandardOutput[] = []; + const solcVersions = _.keys(versionToInputs); for (const solcVersion of solcVersions) { const input = versionToInputs[solcVersion]; @@ -228,6 +245,7 @@ export class Compiler { const { solcInstance, fullSolcVersion } = await Compiler._getSolcAsync(solcVersion); const compilerOutput = this._compile(solcInstance, input.standardInput); + compilerOutputs.push(compilerOutput); for (const contractPath of input.contractsToCompile) { const contractName = contractPathToData[contractPath].contractName; @@ -241,16 +259,20 @@ export class Compiler { Compiler._addHexPrefixes(compiledContract); - await this._persistCompiledContractAsync( - contractPath, - contractPathToData[contractPath].currentArtifactIfExists, - contractPathToData[contractPath].sourceTreeHashHex, - contractName, - fullSolcVersion, - compilerOutput, - ); + if (shouldPersist) { + await this._persistCompiledContractAsync( + contractPath, + contractPathToData[contractPath].currentArtifactIfExists, + contractPathToData[contractPath].sourceTreeHashHex, + contractName, + fullSolcVersion, + compilerOutput, + ); + } } } + + return compilerOutputs; } private _shouldCompile(contractData: ContractData): boolean { if (_.isUndefined(contractData.currentArtifactIfExists)) { |