Skip to content

Commit

Permalink
Adds the ability add compile time build flags via an added file with …
Browse files Browse the repository at this point in the history
…the contract to compile in the form `<contractName>.lamflags` in the same directory and the contract .cpp file.
  • Loading branch information
dallasjohnson committed Feb 9, 2020
1 parent fdee5ff commit 8e90d12
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
22 changes: 19 additions & 3 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import * as Mocha from 'mocha';
import * as mkdirpCallback from 'mkdirp';
import * as rimrafCallback from 'rimraf';
import * as qrcode from 'qrcode-terminal';
import { writeFile as writeFileCallback, exists as existsCallback } from 'fs';
import {
writeFile as writeFileCallback,
exists as existsCallback,
readFile as readFileCallback,
} from 'fs';
import * as globCallback from 'glob';
import * as path from 'path';
import { promisify } from 'util';
Expand All @@ -13,6 +17,7 @@ const glob = promisify(globCallback);
const mkdirp = promisify(mkdirpCallback);
const rimraf = promisify(rimrafCallback);
const writeFile = promisify(writeFileCallback);
const readFile = promisify(readFileCallback);

// It's nice to give people proper stack traces when they have a problem with their code.
// Trace shows async traces, and Clarify removes internal Node entries.
Expand Down Expand Up @@ -389,7 +394,7 @@ export const pathToIdentifier = (filePath: string) => filePath.substr(0, filePat
*/
export const build = async (contractPath: string) => {
// Get the base filename from path and log status
const basename = path.basename(contractPath, '.cpp');
// const basename = path.basename(contractPath, '.cpp'); // Never Used
// Compile contract at path
await compileContract(contractPath);
// Generate Typescript definitions for contract
Expand Down Expand Up @@ -433,6 +438,17 @@ export const compileContract = async (contractPath: string) => {
}

const outputPath = outputPathForContract(contractPath);
const buildFlagsPathComponents = path.parse(contractPath);
const buildFlagsPath =
buildFlagsPathComponents.dir + '/' + buildFlagsPathComponents.name + '.lamflags';
let buildFlags = '';

if (await exists(buildFlagsPath)) {
const data = await readFile(buildFlagsPath);

console.log('\n Adding build flags to compile command: ' + data.toString());
buildFlags = data.toString();
}

// Run the compile contract script inside our docker container.
await docker
Expand All @@ -444,7 +460,7 @@ export const compileContract = async (contractPath: string) => {
'bin',
'project',
contractPath
)}" "${outputPath}" "${basename}"`
)}" "${outputPath}" "${basename}" ${buildFlags}`
)
.catch(err => {
spinner.fail('Failed to compile');
Expand Down
9 changes: 6 additions & 3 deletions src/eosManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ export class EOSManager {
return value;
})
.catch(error => {
logOutput(chalk.red('Threw error: ') + error);
console.log(
chalk.cyan('Payload causing the above error: ') + JSON.stringify(transaction, null, 4)
logOutput(
chalk.red('Threw error: ') +
error +
'\n' +
chalk.cyan('Payload causing the above error: ') +
JSON.stringify(transaction, null, 4)
);
throw error;
});
Expand Down
5 changes: 4 additions & 1 deletion src/scripts/compile_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ PATH="$PATH:/opt/eosio/bin"
filename="$1"
outputPath="$2"
contractName="$3"
addedBuildFlags="$4"

# Ensure the output directory exists
mkdir -p "project/$outputPath"

# compile smart contract to wasm and abi files using EOSIO.CDT (Contract Development Toolkit)
# https://github.com/EOSIO/eosio.cdt
eosio-cpp -abigen "$filename" -o "project/$outputPath/$contractName.wasm" --contract "$contractName"
eosio-cpp -abigen "$filename" -o "project/$outputPath/$contractName.wasm" --contract "$contractName" $4


3 changes: 0 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ const assertExpectedEOSError = async (
try {
await operation;
} catch (error) {
if (verbose_logging) {
console.log('Verbose error output: ' + JSON.stringify(error, null, 4));
}
if (error.json && error.json.error && error.json.error.name) {
// Compare error and fail if the error doesn't match the expected
assert(
Expand Down

0 comments on commit 8e90d12

Please sign in to comment.