Skip to content

Commit

Permalink
Now generating compiler output to subdirectory in .lamington so it …
Browse files Browse the repository at this point in the history
…can be reliably .gitignored.
  • Loading branch information
thekevinbrown committed May 9, 2019
1 parent f94ddb4 commit 78205d3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <github.com/thekevinbrown>
* @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 <github.com/thekevinbrown>
* @author Mitch Pierias <github.com/MitchPierias>
* @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(
Expand All @@ -367,7 +377,7 @@ export const compileContract = async (contractPath: string) => {
'bin',
'project',
contractPath
)}" "${fullPath}" "${basename}"`
)}" "${outputPath}" "${basename}"`
)
.catch(err => {
spinner.fail('Failed to compile');
Expand Down
12 changes: 10 additions & 2 deletions src/contracts/contractDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/contracts/typeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}'`);
Expand Down

0 comments on commit 78205d3

Please sign in to comment.