Browse Source

Improved build script to write merged build artifact

master
Tal Kol 3 years ago
parent
commit
53da0e23e5
  1. 3
      build/.gitignore
  2. 21
      build/build.ts

3
build/.gitignore vendored

@ -1 +1,2 @@
*.fif *.fif
*.fc

21
build/build.ts

@ -30,9 +30,15 @@ for (const rootContract of rootContracts) {
const contractName = path.parse(rootContract).name; const contractName = path.parse(rootContract).name;
// delete existing build artifacts // delete existing build artifacts
if (fs.existsSync(`build/${contractName}.fif`)) { const fiftArtifact = `build/${contractName}.fif`;
console.log(` - Deleting old build artifact 'build/${contractName}.fif'`); if (fs.existsSync(fiftArtifact)) {
fs.unlinkSync(`build/${contractName}.fif`); 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 // 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}'`); console.log(` - Adding the contract itself '${rootContract}'`);
sourceToCompile += `${fs.readFileSync(rootContract).toString()}\n`; sourceToCompile += `${fs.readFileSync(rootContract).toString()}\n`;
fs.writeFileSync(mergedFuncArtifact, sourceToCompile);
// debug - uncomment the next line if you can't understand weird compilation errors console.log(` - Build artifact created '${mergedFuncArtifact}'`);
// fs.writeFileSync(`build/${contractName}.merged.fc`, sourceToCompile);
// run the compiler // run the compiler
console.log(` - Trying to compile with 'func' compiler..`); console.log(` - Trying to compile '${mergedFuncArtifact}' with 'func' compiler..`);
const buildErrors = child_process.execSync(`func -APSI -o build/${contractName}.fif 2>&1`, { input: sourceToCompile }).toString(); const buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1`).toString();
if (buildErrors.length > 0) { if (buildErrors.length > 0) {
console.log(` - OH NO! Compilation Errors! The compiler output was:`); console.log(` - OH NO! Compilation Errors! The compiler output was:`);
console.log(`\n${buildErrors}`); console.log(`\n${buildErrors}`);

Loading…
Cancel
Save