From 095b2dad00e44a1592c27d6aafd36286f43edfb9 Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 10 Oct 2018 11:15:17 +0530 Subject: [PATCH 1/3] Added forceParse and relative paths --- lib/app.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/app.js b/lib/app.js index 9b19455c..365ba487 100644 --- a/lib/app.js +++ b/lib/app.js @@ -30,17 +30,19 @@ class App { // Other this.testrpcProcess = null; // ref to testrpc server we need to close on exit - this.events = null; // ref to string array loaded from 'allFiredEvents' + this.events = null; // ref to string array loaded from 'allFiredEvents' this.testsErrored = null; // flag set to non-null if truffle tests error this.coverage = new CoverageMap(); // initialize a coverage map this.originalArtifacts = []; // Artifacts from original build (we swap these in) this.skippedFolders = []; + this.forceParseFolders = []; // Config this.config = config || {}; this.workingDir = config.dir || '.'; // Relative path to contracts folder this.accounts = config.accounts || 35; // Number of accounts to testrpc launches with this.skipFiles = config.skipFiles || []; // Which files should be skipped during instrumentation + this.forceParse = config.forceParse || []; // Which files should be force parsed during instrumentation this.norpc = config.norpc || false; // Launch testrpc-sc internally? this.port = config.port || 8555; // Port testrpc should listen on this.buildDirPath = config.buildDirPath || '/build/contracts' // Build directory path for compiled smart contracts @@ -81,6 +83,12 @@ class App { this.skippedFolders.push(item); }); + // Identify folders to force parse + this.forceParse.forEach(item => { + if (path.extname(item) !== '.sol') + this.forceParseFolders.push(item); + }); + files = files.map(file => `${this.workingDir}/${file}`); shell.mkdir(this.coverageDir); shell.cp('-R', files, this.coverageDir); @@ -143,6 +151,7 @@ class App { instrumentTarget() { this.skipFiles = this.skipFiles.map(contract => `${this.coverageDir}/contracts/${contract}`); this.skipFiles.push(`${this.coverageDir}/contracts/Migrations.sol`); + this.forceParse = this.forceParse.map(contract => `${this.coverageDir}/contracts/${contract}`); const instrumentedFiles = []; let currentFile; @@ -155,7 +164,7 @@ class App { const contractPath = this.platformNeutralPath(file); const working = this.workingDir.substring(1); - const canonicalPath = contractPath.split('/coverageEnv').join(working); + const canonicalPath = file.split('/coverageEnv').join(working); const contract = fs.readFileSync(contractPath).toString(); const instrumentedContractInfo = getInstrumentedVersion(contract, canonicalPath); fs.writeFileSync(contractPath, instrumentedContractInfo.contract); @@ -178,7 +187,7 @@ class App { .forEach(file => { // Skip post-processing of skipped files - if (this.deepSkip && (this.skipFiles.includes(file) || this.inSkippedFolder(file))) return; + if (this.deepSkip && (this.skipFiles.includes(file) || this.inSkippedFolder(file)) && !(this.forceParse.includes(file) || this.inForceParseFolder(file))) return; const contractPath = this.platformNeutralPath(file); const contract = fs.readFileSync(contractPath).toString(); @@ -415,6 +424,21 @@ class App { return shouldSkip; } + /** + * Determines if a file is in a folder marked force parse. + * @param {String} file file path + * @return {Boolean} + */ + inForceParseFolder(file){ + let shouldParse; + this.forceParseFolders.forEach(folderToParse => { + folderToParse = `${this.coverageDir}/contracts/${folderToParse}`; + if (file.indexOf(folderToParse) === 0) + shouldParse = true; + }); + return shouldParse; + } + /** * Allows config to turn logging off (for CI) * @param {Boolean} isSilent @@ -463,4 +487,4 @@ class App { } } -module.exports = App; +module.exports = App; \ No newline at end of file From 94f476109a215591c14bfaec97d5f5be7a8ffc21 Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 10 Oct 2018 13:53:38 +0530 Subject: [PATCH 2/3] Console output updated --- lib/app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/app.js b/lib/app.js index 365ba487..4a25cd49 100644 --- a/lib/app.js +++ b/lib/app.js @@ -171,8 +171,10 @@ class App { this.coverage.addContract(instrumentedContractInfo, canonicalPath); instrumentedFiles.push(file); - } else { + } else if (this.forceParse.includes(file) || this.inForceParseFolder(file)) { this.log('Skipping instrumentation of ', file); + } else { + this.log('Skipping instrumentation and processing of ', file); } }); } catch (err) { From a6921aaa8c7049bae0292b4b1d046950c167d2dc Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Fri, 4 Jan 2019 16:26:52 +0530 Subject: [PATCH 3/3] Updated console logging --- lib/app.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/app.js b/lib/app.js index 4a25cd49..af760e00 100644 --- a/lib/app.js +++ b/lib/app.js @@ -171,10 +171,8 @@ class App { this.coverage.addContract(instrumentedContractInfo, canonicalPath); instrumentedFiles.push(file); - } else if (this.forceParse.includes(file) || this.inForceParseFolder(file)) { - this.log('Skipping instrumentation of ', file); } else { - this.log('Skipping instrumentation and processing of ', file); + this.log('Skipping instrumentation of ', file); } }); } catch (err) { @@ -189,8 +187,11 @@ class App { .forEach(file => { // Skip post-processing of skipped files - if (this.deepSkip && (this.skipFiles.includes(file) || this.inSkippedFolder(file)) && !(this.forceParse.includes(file) || this.inForceParseFolder(file))) return; - + if (this.deepSkip && (this.skipFiles.includes(file) || this.inSkippedFolder(file)) && !(this.forceParse.includes(file) || this.inForceParseFolder(file))) { + this.log('Skipping post-processing of ', file); + return; + } + this.log('Post-processing ', file); const contractPath = this.platformNeutralPath(file); const contract = fs.readFileSync(contractPath).toString(); const contractProcessed = preprocessor.run(contract);