From 53da0e23e577177eb3fc423b91f0ee542ea83d9c Mon Sep 17 00:00:00 2001 From: Tal Kol Date: Fri, 29 Apr 2022 19:09:00 +0100 Subject: [PATCH] Improved build script to write merged build artifact --- build/.gitignore | 3 ++- build/build.ts | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/build/.gitignore b/build/.gitignore index 8a8659e..c9e8cd3 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1 +1,2 @@ -*.fif \ No newline at end of file +*.fif +*.fc \ No newline at end of file diff --git a/build/build.ts b/build/build.ts index 8e228ec..bd3936d 100644 --- a/build/build.ts +++ b/build/build.ts @@ -30,9 +30,15 @@ for (const rootContract of rootContracts) { const contractName = path.parse(rootContract).name; // delete existing build artifacts - if (fs.existsSync(`build/${contractName}.fif`)) { - console.log(` - Deleting old build artifact 'build/${contractName}.fif'`); - fs.unlinkSync(`build/${contractName}.fif`); + const fiftArtifact = `build/${contractName}.fif`; + if (fs.existsSync(fiftArtifact)) { + console.log(` - Deleting old build artifact '${fiftArtifact}'`); + fs.unlinkSync(fiftArtifact); + } + const mergedFuncArtifact = `build/${contractName}.merged.fc`; + if (fs.existsSync(mergedFuncArtifact)) { + console.log(` - Deleting old build artifact '${mergedFuncArtifact}'`); + fs.unlinkSync(mergedFuncArtifact); } // create one string with all source code from all merged files @@ -44,13 +50,12 @@ for (const rootContract of rootContracts) { } console.log(` - Adding the contract itself '${rootContract}'`); sourceToCompile += `${fs.readFileSync(rootContract).toString()}\n`; - - // debug - uncomment the next line if you can't understand weird compilation errors - // fs.writeFileSync(`build/${contractName}.merged.fc`, sourceToCompile); + fs.writeFileSync(mergedFuncArtifact, sourceToCompile); + console.log(` - Build artifact created '${mergedFuncArtifact}'`); // run the compiler - console.log(` - Trying to compile with 'func' compiler..`); - const buildErrors = child_process.execSync(`func -APSI -o build/${contractName}.fif 2>&1`, { input: sourceToCompile }).toString(); + console.log(` - Trying to compile '${mergedFuncArtifact}' with 'func' compiler..`); + const buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1`).toString(); if (buildErrors.length > 0) { console.log(` - OH NO! Compilation Errors! The compiler output was:`); console.log(`\n${buildErrors}`);