Skip to content

Commit

Permalink
#216: relative
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 25, 2023
1 parent c2604e2 commit 116286a
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
5 changes: 4 additions & 1 deletion src/commands/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');

Expand All @@ -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;
});
};
5 changes: 3 additions & 2 deletions src/commands/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const fs = require('fs');
const path = require('path');
const os = require('os');
Expand All @@ -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);
}
}
};
3 changes: 2 additions & 1 deletion src/commands/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

Expand All @@ -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;
});
};
3 changes: 2 additions & 1 deletion src/commands/foreign.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const fs = require('fs');

Expand All @@ -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']);
});
Expand Down
4 changes: 3 additions & 1 deletion src/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

Expand All @@ -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;
});
};
4 changes: 3 additions & 1 deletion src/commands/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');

Expand All @@ -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;
});
};
12 changes: 9 additions & 3 deletions src/commands/phi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');

Expand All @@ -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;
});
};
7 changes: 4 additions & 3 deletions src/commands/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');

Expand All @@ -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))
Expand All @@ -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;
});
};
3 changes: 2 additions & 1 deletion src/commands/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

Expand All @@ -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;
});
};
3 changes: 2 additions & 1 deletion src/commands/sodg.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');

Expand Down Expand Up @@ -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;
});
};
3 changes: 2 additions & 1 deletion src/commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

Expand All @@ -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;
});
};
7 changes: 4 additions & 3 deletions src/commands/unphi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');

Expand All @@ -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))
Expand All @@ -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;
});
};
3 changes: 2 additions & 1 deletion src/commands/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');

Expand All @@ -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;
});
};
9 changes: 7 additions & 2 deletions src/mvnw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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')}`,
Expand Down
3 changes: 2 additions & 1 deletion test/commands/test_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -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();
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/commands/test_dataize.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

const rel = require('relative');
const fs = require('fs');
const assert = require('assert');
const path = require('path');
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 116286a

Please sign in to comment.