This repository was archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
99 lines (82 loc) · 2.9 KB
/
Copy pathindex.js
File metadata and controls
99 lines (82 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Compiler for PHP (aka KPHP) tools
// Copyright (c) 2020 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt
/*
`kphp-diff-comparator` - a console tool to compare 2 KPHP outputs (folders with .cpp/.h files generated from PHP code).
Useful for KPHP development: you generate your site with stable (master) KPHP, change KPHP sources re-generate —
and compare previous vs current: to ensure there is no diff or there is diff exactly as expected.
For every diff file, we print its name to console and invoke `diff` to --diff folder.
*/
var fs = require('fs');
var env = require('./src/env');
var treeWalkAndLogAllDiff = require('./src/diff-finder');
function parseConsoleArgv(argv) {
for (var i = 0; i < argv.length; ++i) {
switch (argv[i]) {
case '--master':
case '—master':
env.RUN_ARGV.KPHP_MASTER_ROOT = argv[i + 1];
break;
case '--cmp':
case '—cmp':
env.RUN_ARGV.KPHP_CMP_ROOT = argv[i + 1];
break;
case '--diff':
case '—diff':
env.RUN_ARGV.DETAILED_DIFF_ROOT = argv[i + 1];
break;
case '--skip-comments':
env.RUN_ARGV.SKIP_ONLY_COMMENTS_DIFF = true;
break;
case '-v':
case '--version':
env.RUN_ARGV.JUST_SHOW_VERSION = true;
break;
case '-h':
case '--h':
case '--help':
env.RUN_ARGV.JUST_SHOW_HELP = true;
break;
}
}
}
function checkRunArgv() {
let checkDir = (dir, errIfIncorrect) => {
if (!dir || !fs.statSync(dir).isDirectory()) {
throw errIfIncorrect;
}
};
checkDir(env.RUN_ARGV.KPHP_MASTER_ROOT, "invalid --master cmd argument");
checkDir(env.RUN_ARGV.KPHP_CMP_ROOT, "invalid --cmp cmd argument");
checkDir(env.RUN_ARGV.DETAILED_DIFF_ROOT, "invalid --diff cmd argument");
}
// ——————————————————————
function onDoneAll({ start, totalCount, inessentialDiffCount, importantDiffCount }) {
var duration = ((new Date) - start).valueOf();
console.log(`\nfinished ${totalCount} cpp/h files in ${duration} msec`);
console.log(`${inessentialDiffCount} known differences (vars.cpp, etc)`);
console.log(`${importantDiffCount} important differences`);
}
function main() {
try {
parseConsoleArgv(process.argv);
checkRunArgv();
} catch (err) {
console.error(err);
process.exit(1);
}
// just help and exit
if (env.RUN_ARGV.JUST_SHOW_HELP) {
console.log("Specify --master and --cmp as input C++ generated folders, --diff as output folder.\nSee README.md for details.");
return;
}
// just show version and exit
if (env.RUN_ARGV.JUST_SHOW_VERSION) {
console.log("kphp-diff-comparator v" + env.VERSION);
return;
}
console.log('\nStart comparing kphp outputs:');
console.log(env.RUN_ARGV.KPHP_MASTER_ROOT, ' -vs- ', env.RUN_ARGV.KPHP_CMP_ROOT, "\n");
treeWalkAndLogAllDiff(onDoneAll);
}
main();