From 78205d3e5164c1fdbccbb4f55ff56ecc9b3b4a20 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Thu, 9 May 2019 14:17:42 +1000 Subject: [PATCH] Now generating compiler output to subdirectory in `.lamington` so it can be reliably .gitignored. --- src/cli/utils.ts | 18 ++++++++++++++---- src/contracts/contractDeployer.ts | 12 ++++++++++-- src/contracts/typeGenerator.ts | 6 +++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/cli/utils.ts b/src/cli/utils.ts index 1096892..9f988be 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -345,18 +345,28 @@ export const build = async (contractPath: string) => { } }; +/** + * Determines the output location for a contract based on the full path of its C++ file. + * @author Kevin Brown + * @param contractPath Full path to C++ contract file + * @returns Output path for contract compilation artefacts + */ +export const outputPathForContract = (contractPath: string) => + path.join(ConfigManager.outDir, 'compiled_contracts', path.dirname(contractPath)); + /** * Compiles a C++ EOSIO smart contract at path * @author Kevin Brown * @author Mitch Pierias - * @param contractPath Fullpath to C++ contract file + * @param contractPath Full path to C++ contract file */ export const compileContract = async (contractPath: string) => { // Begin logs spinner.create(`Compiling contract`); - // Get the base filename from path and log status + const basename = path.basename(contractPath, '.cpp'); - const fullPath = path.join(ConfigManager.outDir, path.dirname(contractPath)); + const outputPath = outputPathForContract(contractPath); + // Pull docker images await docker .command( @@ -367,7 +377,7 @@ export const compileContract = async (contractPath: string) => { 'bin', 'project', contractPath - )}" "${fullPath}" "${basename}"` + )}" "${outputPath}" "${basename}"` ) .catch(err => { spinner.fail('Failed to compile'); diff --git a/src/contracts/contractDeployer.ts b/src/contracts/contractDeployer.ts index 0e20aef..627031a 100644 --- a/src/contracts/contractDeployer.ts +++ b/src/contracts/contractDeployer.ts @@ -39,8 +39,16 @@ export class ContractDeployer { textDecoder: EOSManager.api.textDecoder, }); // Construct resource paths - const abiPath = path.join(ConfigManager.outDir, `${contractIdentifier}.abi`); - const wasmPath = path.join(ConfigManager.outDir, `${contractIdentifier}.wasm`); + const abiPath = path.join( + ConfigManager.outDir, + 'compiled_contracts', + `${contractIdentifier}.abi` + ); + const wasmPath = path.join( + ConfigManager.outDir, + 'compiled_contracts', + `${contractIdentifier}.wasm` + ); // Read resources files for paths let abi = JSON.parse(await readFile(abiPath, 'utf8')); const wasm = await readFile(wasmPath); diff --git a/src/contracts/typeGenerator.ts b/src/contracts/typeGenerator.ts index 49f346f..2d9c740 100644 --- a/src/contracts/typeGenerator.ts +++ b/src/contracts/typeGenerator.ts @@ -50,7 +50,11 @@ export const generateAllTypes = async () => { export const generateTypes = async (contractIdentifier: string) => { // Create contract details const contractName = path.basename(contractIdentifier); - const abiPath = path.join(ConfigManager.outDir, `${contractIdentifier}.abi`); + const abiPath = path.join( + ConfigManager.outDir, + 'compiled_contracts', + `${contractIdentifier}.abi` + ); // Handle ABI file loading if (!fs.existsSync(path.resolve(abiPath))) throw new Error(`Missing ABI file at path '${path.resolve(abiPath)}'`);