From 116286a11aa538705c0f2b794abbdbcc6dec33ef Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 25 Dec 2023 10:58:09 +0300 Subject: [PATCH] #216: relative --- package.json | 1 + src/commands/assemble.js | 5 ++++- src/commands/clean.js | 5 +++-- src/commands/compile.js | 3 ++- src/commands/foreign.js | 3 ++- src/commands/link.js | 4 +++- src/commands/parse.js | 4 +++- src/commands/phi.js | 12 +++++++++--- src/commands/print.js | 7 ++++--- src/commands/register.js | 3 ++- src/commands/sodg.js | 3 ++- src/commands/transpile.js | 3 ++- src/commands/unphi.js | 7 ++++--- src/commands/verify.js | 3 ++- src/mvnw.js | 9 +++++++-- test/commands/test_compile.js | 3 ++- test/commands/test_dataize.js | 3 ++- 17 files changed, 54 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index f429da2..f066809 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "commander": "11.1.0", "fast-xml-parser": "4.3.2", "node": "21.2.0", + "relative": "3.0.2", "sync-request": "6.1.0", "xmlhttprequest": "1.8.0" }, diff --git a/src/commands/assemble.js b/src/commands/assemble.js index 8dd65e2..a4874b2 100644 --- a/src/commands/assemble.js +++ b/src/commands/assemble.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); @@ -31,8 +32,10 @@ const {mvnw, flags} = require('../mvnw'); * @return {Promise} of assemble task */ module.exports = function(opts) { + const target = path.resolve(opts.target); + console.info('Assembling into %s', rel(target)); return mvnw(['eo:assemble'].concat(flags(opts)), opts.target, opts.batch).then((r) => { - console.info('EO program assembled in %s', path.resolve(opts.target)); + console.info('EO program assembled in %s', rel(target)); return r; }); }; diff --git a/src/commands/clean.js b/src/commands/clean.js index 131f260..6f43341 100644 --- a/src/commands/clean.js +++ b/src/commands/clean.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const fs = require('fs'); const path = require('path'); const os = require('os'); @@ -33,12 +34,12 @@ const os = require('os'); module.exports = function(opts) { const home = path.resolve(opts.target); fs.rmSync(home, {recursive: true, force: true}); - console.info('The directory %s deleted', home); + console.info('The directory %s deleted', rel(home)); if (opts.cached) { const eo = path.join(os.homedir(), '.eo'); if (fs.existsSync(eo)) { fs.rmSync(eo, {recursive: true}); - console.info('The directory ~/.eo was deleted'); + console.info('The directory %s was deleted', eo); } } }; diff --git a/src/commands/compile.js b/src/commands/compile.js index da256cd..2a7078f 100644 --- a/src/commands/compile.js +++ b/src/commands/compile.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const {mvnw, flags} = require('../mvnw'); const path = require('path'); @@ -33,7 +34,7 @@ const path = require('path'); module.exports = function(opts) { const target = path.resolve(opts.target); return mvnw(['compiler:compile'].concat(flags(opts)), opts.target, opts.batch).then((r) => { - console.info('Java .class files compiled into %s', target); + console.info('Java .class files compiled into %s', rel(target)); return r; }); }; diff --git a/src/commands/foreign.js b/src/commands/foreign.js index 85421d6..bb25140 100644 --- a/src/commands/foreign.js +++ b/src/commands/foreign.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const fs = require('fs'); @@ -32,7 +33,7 @@ const fs = require('fs'); module.exports = function(opts) { const file = path.resolve(opts.target, 'eo-foreign.json'); const all = JSON.parse(fs.readFileSync(file, 'utf8')); - console.info('There are %d objects in %s:', all.length, file); + console.info('There are %d objects in %s:', all.length, rel(file)); all.forEach((obj) => { console.info(' %s', obj['id']); }); diff --git a/src/commands/link.js b/src/commands/link.js index 87a5eb5..31a3ea4 100644 --- a/src/commands/link.js +++ b/src/commands/link.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const {mvnw, flags} = require('../mvnw'); const path = require('path'); @@ -31,8 +32,9 @@ const path = require('path'); * @return {Promise} of link task */ module.exports = function(opts) { + const jar = path.resolve(opts.target, 'eoc.jar'); return mvnw(['jar:jar'].concat(flags(opts)), opts.target, opts.batch).then((r) => { - console.info('Executable JAR created at %s', path.resolve(opts.target, 'eoc.jar')); + console.info('Executable JAR created at %s', rel(jar)); return r; }); }; diff --git a/src/commands/parse.js b/src/commands/parse.js index 7b1e7d4..ac6c797 100644 --- a/src/commands/parse.js +++ b/src/commands/parse.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); @@ -31,8 +32,9 @@ const {mvnw, flags} = require('../mvnw'); * @return {Promise} of assemble task */ module.exports = function(opts) { + const target = path.resolve(opts.target); return mvnw(['eo:parse'].concat(flags(opts)), opts.target, opts.batch).then((r) => { - console.info('EO sources parsed in %s', path.resolve(opts.target)); + console.info('EO sources parsed in %s', rel(target)); return r; }); }; diff --git a/src/commands/phi.js b/src/commands/phi.js index e80677e..f5d8df6 100644 --- a/src/commands/phi.js +++ b/src/commands/phi.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); @@ -31,18 +32,23 @@ const {mvnw, flags} = require('../mvnw'); * @return {Promise} of assemble task */ module.exports = function(opts) { + const target = path.resolve(opts.target); + const input = path.resolve(opts.target, '2-optimize'); + console.debug('Reading .XMIR files from %s', rel(input)); + const output = path.resolve(opts.target, 'phi'); + console.debug('Writing .PHI files to %s', rel(output)); return mvnw( ['eo:xmir-to-phi'] .concat(flags(opts)) .concat( [ - `-DphiInputDir=${path.resolve(opts.target, '2-optimize')}`, - `-DphiOutputDir=${path.resolve(opts.target, 'phi')}`, + `-DphiInputDir=${input}`, + `-DphiOutputDir=${output}`, ] ), opts.target, opts.batch ).then((r) => { - console.info('XMIR files converted into PHI files at %s', path.resolve(opts.target)); + console.info('XMIR files converted into PHI files at %s', rel(target)); return r; }); }; diff --git a/src/commands/print.js b/src/commands/print.js index a0eb1ce..59a149d 100644 --- a/src/commands/print.js +++ b/src/commands/print.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); @@ -32,9 +33,9 @@ const {mvnw, flags} = require('../mvnw'); */ module.exports = function(opts) { const input = path.resolve(opts.target, '2-optimize'); - console.debug('Reading from %s', input); + console.debug('Reading from %s', rel(input)); const output = path.resolve(opts.target, 'print'); - console.debug('Writing into %s', output); + console.debug('Writing into %s', rel(output)); return mvnw( ['eo:print'] .concat(flags(opts)) @@ -46,7 +47,7 @@ module.exports = function(opts) { ), opts.target, opts.batch ).then((r) => { - console.info('XMIR files converted into EO files at %s', output); + console.info('XMIR files converted into EO files at %s', rel(output)); return r; }); }; diff --git a/src/commands/register.js b/src/commands/register.js index 057ff95..06c62a7 100644 --- a/src/commands/register.js +++ b/src/commands/register.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const {mvnw, flags} = require('../mvnw'); const path = require('path'); @@ -33,7 +34,7 @@ const path = require('path'); module.exports = function(opts) { const foreign = path.resolve(opts.target, 'eo-foreign.json'); return mvnw(['eo:register'].concat(flags(opts)), opts.target, opts.batch).then((r) => { - console.info('EO objects registered in %s', foreign); + console.info('EO objects registered in %s', rel(foreign)); return r; }); }; diff --git a/src/commands/sodg.js b/src/commands/sodg.js index 0488801..d4eb64a 100644 --- a/src/commands/sodg.js +++ b/src/commands/sodg.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); @@ -55,7 +56,7 @@ module.exports = function(opts) { argv.push('-Deo.generateDotFiles'); } return mvnw(argv, opts.target, opts.batch).then((r) => { - console.info('SODG files generated in %s', path.resolve(opts.target)); + console.info('SODG files generated in %s', rel(path.resolve(opts.target))); return r; }); }; diff --git a/src/commands/transpile.js b/src/commands/transpile.js index 24eaadb..7828627 100644 --- a/src/commands/transpile.js +++ b/src/commands/transpile.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const {mvnw, flags} = require('../mvnw'); const path = require('path'); @@ -33,7 +34,7 @@ const path = require('path'); module.exports = function(opts) { const sources = path.resolve(opts.target, 'generated-sources'); return mvnw(['eo:transpile'].concat(flags(opts)), opts.target, opts.batch).then((r) => { - console.info('Java sources generated in %s', sources); + console.info('Java sources generated in %s', rel(sources)); return r; }); }; diff --git a/src/commands/unphi.js b/src/commands/unphi.js index 30ec573..09c062d 100644 --- a/src/commands/unphi.js +++ b/src/commands/unphi.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); @@ -32,9 +33,9 @@ const {mvnw, flags} = require('../mvnw'); */ module.exports = function(opts) { const input = path.resolve(opts.target, 'phi'); - console.debug('Reading from %s', input); + console.debug('Reading .PHI files from %s', rel(input)); const output = path.resolve(opts.target, 'unphi'); - console.debug('Writing into %s', output); + console.debug('Writing .XMIR files to %s', rel(output)); return mvnw( ['eo:phi-to-xmir'] .concat(flags(opts)) @@ -46,7 +47,7 @@ module.exports = function(opts) { ), opts.target, opts.batch ).then((r) => { - console.info('PHI files converted into XMIR files at %s', output); + console.info('PHI files converted into XMIR files at %s', rel(output)); return r; }); }; diff --git a/src/commands/verify.js b/src/commands/verify.js index c8bd5db..8710191 100644 --- a/src/commands/verify.js +++ b/src/commands/verify.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); @@ -32,7 +33,7 @@ const {mvnw, flags} = require('../mvnw'); */ module.exports = function(opts) { return mvnw(['eo:verify'].concat(flags(opts)), opts.target, opts.batch).then((r) => { - console.info('EO program verified in %s', path.resolve(opts.target)); + console.info('EO program verified in %s', rel(path.resolve(opts.target))); return r; }); }; diff --git a/src/mvnw.js b/src/mvnw.js index 74f33ea..84d0c59 100644 --- a/src/mvnw.js +++ b/src/mvnw.js @@ -24,6 +24,7 @@ const path = require('path'); const fs = require('fs'); +const rel = require('relative'); const readline = require('readline'); const {spawn} = require('child_process'); const colors = require('colors'); @@ -49,14 +50,18 @@ let beginning; * @return {Array} of Maven options */ module.exports.flags = function(opts) { + const sources = path.resolve(opts.sources); + console.debug('Sources in %s', rel(sources)); + const target = path.resolve(opts.target); + console.debug('Target in %s', rel(target)); return [ '-Deo.version=' + opts.parser, '-Deo.hash=' + (opts.hash ? opts.hash : opts.parser), opts.verbose ? '--errors' : '', opts.verbose ? '' : '--quiet', opts.debug ? '--debug' : '', - `-Deo.sourcesDir=${path.resolve(opts.sources)}`, - `-Deo.targetDir=${path.resolve(opts.target)}`, + `-Deo.sourcesDir=${sources}`, + `-Deo.targetDir=${target}`, `-Deo.outputDir=${path.resolve(opts.target, 'classes')}`, `-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`, `-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`, diff --git a/test/commands/test_compile.js b/test/commands/test_compile.js index a933e83..aad07cc 100644 --- a/test/commands/test_compile.js +++ b/test/commands/test_compile.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); @@ -100,7 +101,7 @@ describe('compile', function() { '-s', path.resolve(home, 'src'), '-t', path.resolve(home, 'target'), ]); - assert(stdout.includes(`The directory ${path.resolve(home, 'target')} deleted`), stdout); + assert(stdout.includes(`The directory ${rel(path.resolve(home, 'target'))} deleted`), stdout); done(); }); }); diff --git a/test/commands/test_dataize.js b/test/commands/test_dataize.js index 21fa1a5..056d195 100644 --- a/test/commands/test_dataize.js +++ b/test/commands/test_dataize.js @@ -22,6 +22,7 @@ * SOFTWARE. */ +const rel = require('relative'); const fs = require('fs'); const assert = require('assert'); const path = require('path'); @@ -53,7 +54,7 @@ describe('dataize', function() { '-t', path.resolve(home, 'target'), ]); assert(stdout.includes('Hello, world!'), stdout); - assert(stdout.includes(`The directory ${path.resolve(home, 'target')} deleted`), stdout); + assert(stdout.includes(`The directory ${rel(path.resolve(home, 'target'))} deleted`), stdout); assert(!fs.existsSync(path.resolve('../../mvnw/target'))); done(); });