@markw65/monkeyc-optimizer 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/build/api.cjs +254 -75
- package/build/optimizer.cjs +220 -143
- package/build/sdk-util.cjs +2 -2
- package/build/src/api.d.ts +5 -4
- package/build/src/build.d.ts +2 -2
- package/build/src/jungles.d.ts +1 -1
- package/build/src/manifest.d.ts +3 -3
- package/build/src/mc-rewrite.d.ts +3 -3
- package/build/src/optimizer.d.ts +23 -15
- package/build/src/sdk-util.d.ts +1 -0
- package/build/src/util.d.ts +2 -3
- package/build/util.cjs +1 -14
- package/package.json +2 -2
package/build/optimizer.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {copyRecursiveAsNeeded,launchSimulator,
|
|
1
|
+
0 && (module.exports = {copyRecursiveAsNeeded,get_jungle,launchSimulator,manifestProducts,mctree,simulateProgram,defaultConfig,isErrorWithLocation,buildOptimizedProject,generateOptimizedProject,getProjectAnalysis,generateApiMirTests});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
@@ -9829,18 +9829,22 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
9829
9829
|
"generateOptimizedProject": () => (/* binding */ generateOptimizedProject),
|
|
9830
9830
|
"getProjectAnalysis": () => (/* binding */ getProjectAnalysis),
|
|
9831
9831
|
"get_jungle": () => (/* reexport */ get_jungle),
|
|
9832
|
+
"isErrorWithLocation": () => (/* binding */ isErrorWithLocation),
|
|
9832
9833
|
"launchSimulator": () => (/* reexport */ launchSimulator),
|
|
9834
|
+
"manifestProducts": () => (/* reexport */ manifestProducts),
|
|
9833
9835
|
"mctree": () => (/* reexport */ prettier_plugin_monkeyc_namespaceObject.mctree),
|
|
9834
9836
|
"simulateProgram": () => (/* reexport */ simulateProgram)
|
|
9835
9837
|
});
|
|
9836
9838
|
|
|
9839
|
+
;// CONCATENATED MODULE: external "@markw65/prettier-plugin-monkeyc"
|
|
9840
|
+
const prettier_plugin_monkeyc_namespaceObject = require("@markw65/prettier-plugin-monkeyc");
|
|
9841
|
+
var prettier_plugin_monkeyc_default = /*#__PURE__*/__webpack_require__.n(prettier_plugin_monkeyc_namespaceObject);
|
|
9837
9842
|
;// CONCATENATED MODULE: external "crypto"
|
|
9838
9843
|
const external_crypto_namespaceObject = require("crypto");
|
|
9839
9844
|
;// CONCATENATED MODULE: external "fs/promises"
|
|
9840
9845
|
const promises_namespaceObject = require("fs/promises");
|
|
9841
9846
|
// EXTERNAL MODULE: external "path"
|
|
9842
9847
|
var external_path_ = __webpack_require__(1423);
|
|
9843
|
-
var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_);
|
|
9844
9848
|
;// CONCATENATED MODULE: external "./api.cjs"
|
|
9845
9849
|
const external_api_cjs_namespaceObject = require("./api.cjs");
|
|
9846
9850
|
;// CONCATENATED MODULE: external "./sdk-util.cjs"
|
|
@@ -9911,7 +9915,6 @@ async function build_project(product, options, lineCallback) {
|
|
|
9911
9915
|
|
|
9912
9916
|
// EXTERNAL MODULE: ./node_modules/extract-zip/index.js
|
|
9913
9917
|
var extract_zip = __webpack_require__(2106);
|
|
9914
|
-
var extract_zip_default = /*#__PURE__*/__webpack_require__.n(extract_zip);
|
|
9915
9918
|
// EXTERNAL MODULE: ./node_modules/xml2js/lib/xml2js.js
|
|
9916
9919
|
var xml2js = __webpack_require__(5055);
|
|
9917
9920
|
;// CONCATENATED MODULE: ./build/jungle.js
|
|
@@ -9932,7 +9935,7 @@ async function writeManifest(filename, xml) {
|
|
|
9932
9935
|
function manifestProducts(manifest) {
|
|
9933
9936
|
const app = manifest["iq:manifest"]["iq:application"] ||
|
|
9934
9937
|
manifest["iq:manifest"]["iq:barrel"];
|
|
9935
|
-
return (
|
|
9938
|
+
return (app?.[0]["iq:products"]?.[0]["iq:product"] || [])
|
|
9936
9939
|
.map((p) => p.$.id)
|
|
9937
9940
|
.sort()
|
|
9938
9941
|
.filter((p, i, a) => !i || p !== a[i - 1]);
|
|
@@ -9953,7 +9956,10 @@ function manifestBarrels(manifest) {
|
|
|
9953
9956
|
return [];
|
|
9954
9957
|
}
|
|
9955
9958
|
function manifestDropBarrels(manifest) {
|
|
9956
|
-
|
|
9959
|
+
const app = manifest["iq:manifest"]["iq:application"];
|
|
9960
|
+
if (!app)
|
|
9961
|
+
return;
|
|
9962
|
+
delete app[0]["iq:barrels"];
|
|
9957
9963
|
}
|
|
9958
9964
|
function manifestBarrelName(manifestName, manifest) {
|
|
9959
9965
|
const barrel = manifest["iq:manifest"]["iq:barrel"];
|
|
@@ -9964,7 +9970,7 @@ function manifestBarrelName(manifestName, manifest) {
|
|
|
9964
9970
|
function manifestAnnotations(manifest) {
|
|
9965
9971
|
const barrel = manifest["iq:manifest"]["iq:barrel"];
|
|
9966
9972
|
if (!barrel)
|
|
9967
|
-
return
|
|
9973
|
+
return undefined;
|
|
9968
9974
|
const annotations = barrel[0]["iq:annotations"];
|
|
9969
9975
|
return annotations && annotations[0]["iq:annotation"];
|
|
9970
9976
|
}
|
|
@@ -9994,9 +10000,13 @@ async function checkManifest(manifest, products) {
|
|
|
9994
10000
|
if (JSON.stringify(allowedProducts) !=
|
|
9995
10001
|
JSON.stringify(manifestProducts(manifest))) {
|
|
9996
10002
|
ok = false;
|
|
9997
|
-
elm["iq:products"]
|
|
9998
|
-
|
|
9999
|
-
|
|
10003
|
+
elm["iq:products"] = [
|
|
10004
|
+
{
|
|
10005
|
+
"iq:product": allowedProducts.map((id) => {
|
|
10006
|
+
return { $: { id } };
|
|
10007
|
+
}),
|
|
10008
|
+
},
|
|
10009
|
+
];
|
|
10000
10010
|
}
|
|
10001
10011
|
Object.keys(elm).forEach((key) => {
|
|
10002
10012
|
if (![
|
|
@@ -10081,7 +10091,7 @@ function process_assignments(assignments, current) {
|
|
|
10081
10091
|
r.dotnames = [];
|
|
10082
10092
|
}
|
|
10083
10093
|
return r;
|
|
10084
|
-
}, { node: state, dot:
|
|
10094
|
+
}, { node: state, dot: undefined, dotnames: [] });
|
|
10085
10095
|
// an assignment to a node overwrites its old value
|
|
10086
10096
|
Object.keys(node).forEach((k) => delete node[k]);
|
|
10087
10097
|
const process_list = (values) => {
|
|
@@ -10155,7 +10165,9 @@ function evaluate_locals(assignments) {
|
|
|
10155
10165
|
}
|
|
10156
10166
|
async function parse_one(file) {
|
|
10157
10167
|
const [fileName, grammarSource] = Array.isArray(file) ? file : [file, file];
|
|
10158
|
-
const source = await promises_namespaceObject.readFile(fileName)
|
|
10168
|
+
const source = await promises_namespaceObject.readFile(fileName).catch(() => {
|
|
10169
|
+
throw new Error(`Couldn't read jungle file '${fileName}`);
|
|
10170
|
+
});
|
|
10159
10171
|
const assignments = peg$parse(source.toString(), { grammarSource });
|
|
10160
10172
|
return evaluate_locals(assignments);
|
|
10161
10173
|
}
|
|
@@ -10210,24 +10222,49 @@ function check_non_leaf_dot(dot, path = null, i = 0) {
|
|
|
10210
10222
|
// return the resolved node at path
|
|
10211
10223
|
function resolve_node_by_path(state, path) {
|
|
10212
10224
|
return path.reduce((s, n, i) => {
|
|
10225
|
+
if (!s || Array.isArray(s)) {
|
|
10226
|
+
return s;
|
|
10227
|
+
}
|
|
10213
10228
|
if (!s[n] && s["."]) {
|
|
10214
10229
|
const sdot = s["."];
|
|
10215
|
-
let resolved = resolve_node_list(state, sdot)
|
|
10216
|
-
if (resolved
|
|
10217
|
-
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10230
|
+
let resolved = resolve_node_list(state, sdot);
|
|
10231
|
+
if (!resolved.length)
|
|
10232
|
+
return undefined;
|
|
10233
|
+
const r = resolved[0][n];
|
|
10234
|
+
if (!r && sdot.every((e) => e.type == "Literal")) {
|
|
10235
|
+
/*
|
|
10236
|
+
* We had something like:
|
|
10237
|
+
*
|
|
10238
|
+
* foo = whatever
|
|
10239
|
+
* bar = $(foo.resourcePath)
|
|
10240
|
+
*
|
|
10241
|
+
* and its supposed to work as if you'd left out the (obviously
|
|
10242
|
+
* incorrect) ".resourcePath"
|
|
10243
|
+
*/
|
|
10221
10244
|
return s;
|
|
10222
10245
|
}
|
|
10246
|
+
/*
|
|
10247
|
+
* This is a pretty unusual edge case.
|
|
10248
|
+
*
|
|
10249
|
+
* If we do something like:
|
|
10250
|
+
*
|
|
10251
|
+
* fenix6 = $(base)
|
|
10252
|
+
* fenix5.sourcePath = $(fenix6.sourcePath)
|
|
10253
|
+
*
|
|
10254
|
+
* and fenix5 gets resolved before fenix6 (which it will,
|
|
10255
|
+
* currently, because products are resolved in lexicographical
|
|
10256
|
+
* order), we'll end up here when we try to resolve
|
|
10257
|
+
* fenix6.sourcePath.
|
|
10258
|
+
*/
|
|
10223
10259
|
check_non_leaf_dot(sdot, path, i);
|
|
10260
|
+
return r;
|
|
10224
10261
|
}
|
|
10225
10262
|
return s[n];
|
|
10226
10263
|
}, state);
|
|
10227
10264
|
}
|
|
10228
10265
|
// fully resolve the given node, and all its children
|
|
10229
10266
|
function resolve_node(state, node) {
|
|
10230
|
-
if (node
|
|
10267
|
+
if (node === undefined || Array.isArray(node)) {
|
|
10231
10268
|
// an already optimized leaf node
|
|
10232
10269
|
return node;
|
|
10233
10270
|
}
|
|
@@ -10293,9 +10330,10 @@ async function resolve_literals(qualifier, default_source) {
|
|
|
10293
10330
|
}
|
|
10294
10331
|
}))).filter((name) => name != null);
|
|
10295
10332
|
const resolve_one_file_list = async (base, name) => {
|
|
10296
|
-
|
|
10333
|
+
const bname = base[name];
|
|
10334
|
+
if (!bname)
|
|
10297
10335
|
return;
|
|
10298
|
-
const result = await resolve_file_list(
|
|
10336
|
+
const result = await resolve_file_list(bname);
|
|
10299
10337
|
if (!result || !result.length) {
|
|
10300
10338
|
delete base[name];
|
|
10301
10339
|
}
|
|
@@ -10453,14 +10491,15 @@ function identify_optimizer_groups(targets, options) {
|
|
|
10453
10491
|
if (excludeAnnotations && ignoredExcludeAnnotations) {
|
|
10454
10492
|
excludeAnnotations = getStrsWithIgnore(excludeAnnotations, ignoredExcludeAnnotations);
|
|
10455
10493
|
}
|
|
10456
|
-
|
|
10457
|
-
|
|
10458
|
-
|
|
10459
|
-
|
|
10460
|
-
|
|
10494
|
+
annotations &&
|
|
10495
|
+
Object.entries(annotations).forEach(([key, value]) => {
|
|
10496
|
+
if (ignoredAnnotations) {
|
|
10497
|
+
annotations[key] = getStrsWithIgnore(value, ignoredAnnotations);
|
|
10498
|
+
}
|
|
10499
|
+
});
|
|
10461
10500
|
if (ignoredSourcePaths) {
|
|
10462
10501
|
sourcePath = sourcePath
|
|
10463
|
-
|
|
10502
|
+
?.map((path) => Object.keys(ignoredSourcePaths[path]))
|
|
10464
10503
|
.flat()
|
|
10465
10504
|
.sort()
|
|
10466
10505
|
.filter((v, i, a) => i === 0 || v !== a[i - 1]);
|
|
@@ -10556,9 +10595,11 @@ function resolve_barrel(barrel, barrelDir, products, options) {
|
|
|
10556
10595
|
.then((localStat) => !localStat.isDirectory() ||
|
|
10557
10596
|
promises_namespaceObject.stat(barrel)
|
|
10558
10597
|
.then((barrelStat) => localStat.mtimeMs < barrelStat.mtimeMs), () => true)
|
|
10559
|
-
.then((needsUpdate) =>
|
|
10560
|
-
|
|
10561
|
-
.
|
|
10598
|
+
.then((needsUpdate) => {
|
|
10599
|
+
needsUpdate &&
|
|
10600
|
+
promises_namespaceObject.rm(localPath, { recursive: true, force: true })
|
|
10601
|
+
.then(() => extract_zip(barrel, { dir: localPath }));
|
|
10602
|
+
}));
|
|
10562
10603
|
}
|
|
10563
10604
|
return promise
|
|
10564
10605
|
.then(() => get_jungle_and_barrels(rawBarrel, products, options))
|
|
@@ -10622,9 +10663,10 @@ function resolve_barrels(product, qualifier, barrels, products, options) {
|
|
|
10622
10663
|
const name = manifestBarrelName(resolvedBarrel.manifest, resolvedBarrel.xml);
|
|
10623
10664
|
if (!(0,external_api_cjs_namespaceObject.hasProperty)(barrelMap, name))
|
|
10624
10665
|
return;
|
|
10625
|
-
|
|
10666
|
+
const bmapName = barrelMap[name];
|
|
10667
|
+
if (bmapName) {
|
|
10626
10668
|
const bname = (r) => r.jungles.join(";");
|
|
10627
|
-
throw new Error(`Barrel ${name} already resolved to ${bname(
|
|
10669
|
+
throw new Error(`Barrel ${name} already resolved to ${bname(bmapName)}; can't also resolve to ${bname(resolvedBarrel)}`);
|
|
10628
10670
|
}
|
|
10629
10671
|
barrelMap[name] = resolvedBarrel;
|
|
10630
10672
|
});
|
|
@@ -10636,10 +10678,11 @@ function resolve_barrels(product, qualifier, barrels, products, options) {
|
|
|
10636
10678
|
.map(([name]) => name)
|
|
10637
10679
|
.join(",")}`);
|
|
10638
10680
|
}
|
|
10681
|
+
const finalMap = barrelMap;
|
|
10639
10682
|
if (!cache.barrelMap)
|
|
10640
10683
|
cache.barrelMap = {};
|
|
10641
|
-
cache.barrelMap[barrelMapKey] =
|
|
10642
|
-
setBarrelMap(
|
|
10684
|
+
cache.barrelMap[barrelMapKey] = finalMap;
|
|
10685
|
+
setBarrelMap(finalMap);
|
|
10643
10686
|
});
|
|
10644
10687
|
}
|
|
10645
10688
|
/**
|
|
@@ -10679,7 +10722,7 @@ async function get_jungle_and_barrels(jungleFiles, defaultProducts, options) {
|
|
|
10679
10722
|
if (products.length === 0)
|
|
10680
10723
|
products.push(...defaultProducts);
|
|
10681
10724
|
let promise = Promise.resolve();
|
|
10682
|
-
const add_one = (product, shape =
|
|
10725
|
+
const add_one = (product, shape = undefined) => {
|
|
10683
10726
|
const rawQualifier = resolve_node(state, state[product]);
|
|
10684
10727
|
if (!rawQualifier || Array.isArray(rawQualifier))
|
|
10685
10728
|
return;
|
|
@@ -10688,7 +10731,8 @@ async function get_jungle_and_barrels(jungleFiles, defaultProducts, options) {
|
|
|
10688
10731
|
.then((qualifier) => {
|
|
10689
10732
|
targets.push({ product, qualifier, shape });
|
|
10690
10733
|
return resolve_barrels(product, qualifier, barrels, products, options);
|
|
10691
|
-
})
|
|
10734
|
+
})
|
|
10735
|
+
.then(() => { });
|
|
10692
10736
|
};
|
|
10693
10737
|
products.forEach((product) => {
|
|
10694
10738
|
if ((0,external_api_cjs_namespaceObject.hasProperty)(state, product)) {
|
|
@@ -10723,7 +10767,7 @@ const external_child_process_namespaceObject = require("child_process");
|
|
|
10723
10767
|
|
|
10724
10768
|
function launchSimulator() {
|
|
10725
10769
|
return (0,external_sdk_util_cjs_namespaceObject.getSdkPath)().then((sdk) => {
|
|
10726
|
-
const child = (0,external_child_process_namespaceObject.execFile)(
|
|
10770
|
+
const child = (0,external_child_process_namespaceObject.execFile)(external_path_.resolve(sdk, "bin", external_sdk_util_cjs_namespaceObject.isWin ? "simulator" : "connectiq"));
|
|
10727
10771
|
child.unref();
|
|
10728
10772
|
});
|
|
10729
10773
|
}
|
|
@@ -10731,12 +10775,9 @@ function simulateProgram(prg, device, test) {
|
|
|
10731
10775
|
const args = [prg, device];
|
|
10732
10776
|
if (test)
|
|
10733
10777
|
args.push("-t");
|
|
10734
|
-
return (0,external_sdk_util_cjs_namespaceObject.getSdkPath)().then((sdk) => (0,external_util_cjs_namespaceObject.spawnByLine)(
|
|
10778
|
+
return (0,external_sdk_util_cjs_namespaceObject.getSdkPath)().then((sdk) => (0,external_util_cjs_namespaceObject.spawnByLine)(external_path_.resolve(sdk, "bin", "monkeydo"), args, (line) => console.log(line)).then(() => { }));
|
|
10735
10779
|
}
|
|
10736
10780
|
|
|
10737
|
-
;// CONCATENATED MODULE: external "@markw65/prettier-plugin-monkeyc"
|
|
10738
|
-
const prettier_plugin_monkeyc_namespaceObject = require("@markw65/prettier-plugin-monkeyc");
|
|
10739
|
-
var prettier_plugin_monkeyc_default = /*#__PURE__*/__webpack_require__.n(prettier_plugin_monkeyc_namespaceObject);
|
|
10740
10781
|
;// CONCATENATED MODULE: ./src/mc-rewrite.ts
|
|
10741
10782
|
|
|
10742
10783
|
|
|
@@ -10744,16 +10785,17 @@ var prettier_plugin_monkeyc_default = /*#__PURE__*/__webpack_require__.n(prettie
|
|
|
10744
10785
|
|
|
10745
10786
|
function processImports(allImports, lookup) {
|
|
10746
10787
|
allImports.forEach(({ node, stack }) => {
|
|
10747
|
-
const [name, module] = lookup(node.id, "as" in node && node.as && node.as.name, stack);
|
|
10788
|
+
const [name, module] = lookup(node.id, ("as" in node && node.as && node.as.name) || null, stack);
|
|
10748
10789
|
if (name && module) {
|
|
10749
10790
|
const [parent] = stack.slice(-1);
|
|
10750
10791
|
if (!parent.decls)
|
|
10751
10792
|
parent.decls = {};
|
|
10793
|
+
const decls = parent.decls;
|
|
10752
10794
|
if (!(0,external_api_cjs_namespaceObject.hasProperty)(parent.decls, name))
|
|
10753
10795
|
parent.decls[name] = [];
|
|
10754
10796
|
module.forEach((m) => {
|
|
10755
10797
|
if ((0,external_api_cjs_namespaceObject.isStateNode)(m) && m.type == "ModuleDeclaration") {
|
|
10756
|
-
(0,external_util_cjs_namespaceObject.pushUnique)(
|
|
10798
|
+
(0,external_util_cjs_namespaceObject.pushUnique)(decls[name], m);
|
|
10757
10799
|
}
|
|
10758
10800
|
});
|
|
10759
10801
|
}
|
|
@@ -10824,7 +10866,7 @@ async function analyze(fnMap) {
|
|
|
10824
10866
|
let excludeAnnotations;
|
|
10825
10867
|
let hasTests = false;
|
|
10826
10868
|
const allImports = [];
|
|
10827
|
-
const
|
|
10869
|
+
const preState = {
|
|
10828
10870
|
allFunctions: [],
|
|
10829
10871
|
allClasses: [],
|
|
10830
10872
|
shouldExclude(node) {
|
|
@@ -10848,7 +10890,7 @@ async function analyze(fnMap) {
|
|
|
10848
10890
|
}
|
|
10849
10891
|
return null;
|
|
10850
10892
|
},
|
|
10851
|
-
post(node) {
|
|
10893
|
+
post(node, state) {
|
|
10852
10894
|
switch (node.type) {
|
|
10853
10895
|
case "FunctionDeclaration":
|
|
10854
10896
|
case "ClassDeclaration": {
|
|
@@ -10867,10 +10909,13 @@ async function analyze(fnMap) {
|
|
|
10867
10909
|
case "ImportModule":
|
|
10868
10910
|
allImports.push({ node, stack: state.stack.slice() });
|
|
10869
10911
|
return null;
|
|
10912
|
+
default:
|
|
10913
|
+
return null;
|
|
10870
10914
|
}
|
|
10871
10915
|
},
|
|
10872
10916
|
};
|
|
10873
|
-
await (0,external_api_cjs_namespaceObject.getApiMapping)(
|
|
10917
|
+
await (0,external_api_cjs_namespaceObject.getApiMapping)(preState);
|
|
10918
|
+
const state = preState;
|
|
10874
10919
|
// Mark all functions from api.mir as "special" by
|
|
10875
10920
|
// setting their bodies to null. In api.mir, they're
|
|
10876
10921
|
// all empty, which makes it look like they're
|
|
@@ -10879,7 +10924,7 @@ async function analyze(fnMap) {
|
|
|
10879
10924
|
if (node.type == "FunctionDeclaration") {
|
|
10880
10925
|
node.node.body = null;
|
|
10881
10926
|
}
|
|
10882
|
-
if (
|
|
10927
|
+
if ((0,external_api_cjs_namespaceObject.isStateNode)(node) && node.decls) {
|
|
10883
10928
|
Object.values(node.decls).forEach((v) => v.forEach(markApi));
|
|
10884
10929
|
}
|
|
10885
10930
|
};
|
|
@@ -10933,6 +10978,8 @@ function getLiteralFromDecls(decls) {
|
|
|
10933
10978
|
return null;
|
|
10934
10979
|
}
|
|
10935
10980
|
function getLiteralNode(node) {
|
|
10981
|
+
if (node == null)
|
|
10982
|
+
return null;
|
|
10936
10983
|
if (node.type == "Literal")
|
|
10937
10984
|
return node;
|
|
10938
10985
|
if (node.type == "BinaryExpression" && node.operator == "as") {
|
|
@@ -10971,11 +11018,11 @@ function getNodeValue(node) {
|
|
|
10971
11018
|
}
|
|
10972
11019
|
let type = node.value === null ? "Null" : typeof node.value;
|
|
10973
11020
|
if (type === "number") {
|
|
10974
|
-
const match = prettier_plugin_monkeyc_namespaceObject.LiteralIntegerRe.exec(node.raw);
|
|
11021
|
+
const match = node.raw && prettier_plugin_monkeyc_namespaceObject.LiteralIntegerRe.exec(node.raw);
|
|
10975
11022
|
if (match) {
|
|
10976
11023
|
type = match[2] == "l" ? "Long" : "Number";
|
|
10977
11024
|
}
|
|
10978
|
-
else if (node.raw.endsWith("d")) {
|
|
11025
|
+
else if (node.raw && node.raw.endsWith("d")) {
|
|
10979
11026
|
type = "Double";
|
|
10980
11027
|
}
|
|
10981
11028
|
else {
|
|
@@ -11098,11 +11145,12 @@ function evaluateFunction(func, args) {
|
|
|
11098
11145
|
default:
|
|
11099
11146
|
throw new Error("Bad node type");
|
|
11100
11147
|
}
|
|
11101
|
-
}, args
|
|
11102
|
-
|
|
11148
|
+
}, !args
|
|
11149
|
+
? undefined
|
|
11150
|
+
: (node) => {
|
|
11103
11151
|
switch (node.type) {
|
|
11104
11152
|
case "ReturnStatement":
|
|
11105
|
-
ret = node.argument;
|
|
11153
|
+
ret = node.argument || null;
|
|
11106
11154
|
return null;
|
|
11107
11155
|
case "BlockStatement":
|
|
11108
11156
|
case "Literal":
|
|
@@ -11119,7 +11167,7 @@ function evaluateFunction(func, args) {
|
|
|
11119
11167
|
throw new Error("Didn't optimize");
|
|
11120
11168
|
}
|
|
11121
11169
|
}
|
|
11122
|
-
})
|
|
11170
|
+
});
|
|
11123
11171
|
return ret;
|
|
11124
11172
|
}
|
|
11125
11173
|
catch (e) {
|
|
@@ -11127,7 +11175,12 @@ function evaluateFunction(func, args) {
|
|
|
11127
11175
|
}
|
|
11128
11176
|
}
|
|
11129
11177
|
async function optimizeMonkeyC(fnMap) {
|
|
11130
|
-
const state =
|
|
11178
|
+
const state = {
|
|
11179
|
+
...(await analyze(fnMap)),
|
|
11180
|
+
localsStack: [{}],
|
|
11181
|
+
exposed: {},
|
|
11182
|
+
calledFunctions: {},
|
|
11183
|
+
};
|
|
11131
11184
|
const replace = (node, obj) => {
|
|
11132
11185
|
for (const k of Object.keys(node)) {
|
|
11133
11186
|
delete node[k];
|
|
@@ -11156,6 +11209,7 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11156
11209
|
replace(node, obj);
|
|
11157
11210
|
return true;
|
|
11158
11211
|
};
|
|
11212
|
+
const topLocals = () => state.localsStack[state.localsStack.length - 1];
|
|
11159
11213
|
/*
|
|
11160
11214
|
* Might this function be called from somewhere, including
|
|
11161
11215
|
* callbacks from the api (eg getSettingsView, etc).
|
|
@@ -11193,17 +11247,15 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11193
11247
|
f.type == "FunctionDeclaration" &&
|
|
11194
11248
|
maybeCalled(f.node))) ||
|
|
11195
11249
|
(sc.superClass && checkInherited(sc, name)));
|
|
11196
|
-
state.localsStack = [{}];
|
|
11197
|
-
state.exposed = {};
|
|
11198
|
-
state.calledFunctions = {};
|
|
11199
11250
|
state.pre = (node) => {
|
|
11200
11251
|
switch (node.type) {
|
|
11201
11252
|
case "ConditionalExpression":
|
|
11202
11253
|
case "IfStatement":
|
|
11203
11254
|
case "DoWhileStatement":
|
|
11204
11255
|
case "WhileStatement":
|
|
11205
|
-
state.traverse(node.test)
|
|
11206
|
-
|
|
11256
|
+
const test = (state.traverse(node.test) ||
|
|
11257
|
+
node.test);
|
|
11258
|
+
const [value, type] = getNodeValue(test);
|
|
11207
11259
|
if (value) {
|
|
11208
11260
|
let result = null;
|
|
11209
11261
|
if (type === "Null") {
|
|
@@ -11215,25 +11267,16 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11215
11267
|
result = !!value.value;
|
|
11216
11268
|
}
|
|
11217
11269
|
if (result !== null) {
|
|
11270
|
+
node.test = { type: "Literal", value: result };
|
|
11218
11271
|
if (node.type === "IfStatement" ||
|
|
11219
11272
|
node.type === "ConditionalExpression") {
|
|
11220
|
-
|
|
11221
|
-
node.consequent = null;
|
|
11222
|
-
}
|
|
11223
|
-
else {
|
|
11224
|
-
node.alternate = null;
|
|
11225
|
-
}
|
|
11226
|
-
node.test = null;
|
|
11273
|
+
return [result ? "consequent" : "alternate"];
|
|
11227
11274
|
}
|
|
11228
11275
|
else if (node.type === "WhileStatement") {
|
|
11229
|
-
|
|
11230
|
-
node.body = null;
|
|
11231
|
-
}
|
|
11276
|
+
return result === false ? [] : ["body"];
|
|
11232
11277
|
}
|
|
11233
11278
|
else if (node.type === "DoWhileStatement") {
|
|
11234
|
-
|
|
11235
|
-
node.test = null;
|
|
11236
|
-
}
|
|
11279
|
+
return ["body"];
|
|
11237
11280
|
}
|
|
11238
11281
|
else {
|
|
11239
11282
|
throw new Error("Unexpected Node type");
|
|
@@ -11244,14 +11287,14 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11244
11287
|
case "EnumDeclaration":
|
|
11245
11288
|
return false;
|
|
11246
11289
|
case "ForStatement": {
|
|
11247
|
-
const map =
|
|
11290
|
+
const map = topLocals().map;
|
|
11248
11291
|
if (map) {
|
|
11249
11292
|
state.localsStack.push({ node, map: { ...map } });
|
|
11250
11293
|
}
|
|
11251
11294
|
break;
|
|
11252
11295
|
}
|
|
11253
11296
|
case "VariableDeclarator": {
|
|
11254
|
-
const locals =
|
|
11297
|
+
const locals = topLocals();
|
|
11255
11298
|
const { map } = locals;
|
|
11256
11299
|
if (map) {
|
|
11257
11300
|
const declName = (0,external_api_cjs_namespaceObject.variableDeclarationName)(node.id);
|
|
@@ -11269,9 +11312,10 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11269
11312
|
// find all the names declared in this scope, to avoid
|
|
11270
11313
|
// more conflicts
|
|
11271
11314
|
locals.inners = {};
|
|
11315
|
+
const inners = locals.inners;
|
|
11272
11316
|
(0,external_api_cjs_namespaceObject.traverseAst)(locals.node, (node) => {
|
|
11273
11317
|
if (node.type === "VariableDeclarator") {
|
|
11274
|
-
|
|
11318
|
+
inners[(0,external_api_cjs_namespaceObject.variableDeclarationName)(node.id)] = true;
|
|
11275
11319
|
}
|
|
11276
11320
|
});
|
|
11277
11321
|
}
|
|
@@ -11292,7 +11336,8 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11292
11336
|
break;
|
|
11293
11337
|
}
|
|
11294
11338
|
}
|
|
11295
|
-
else if (elm.node
|
|
11339
|
+
else if (elm.node &&
|
|
11340
|
+
elm.node.type === "FunctionDeclaration") {
|
|
11296
11341
|
ok = true;
|
|
11297
11342
|
}
|
|
11298
11343
|
}
|
|
@@ -11331,7 +11376,7 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11331
11376
|
}
|
|
11332
11377
|
break;
|
|
11333
11378
|
case "Identifier": {
|
|
11334
|
-
const map =
|
|
11379
|
+
const map = topLocals().map;
|
|
11335
11380
|
if (map) {
|
|
11336
11381
|
if ((0,external_api_cjs_namespaceObject.hasProperty)(map, node.name)) {
|
|
11337
11382
|
const name = map[node.name];
|
|
@@ -11362,7 +11407,7 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11362
11407
|
}
|
|
11363
11408
|
break;
|
|
11364
11409
|
case "BlockStatement": {
|
|
11365
|
-
const map =
|
|
11410
|
+
const map = topLocals().map;
|
|
11366
11411
|
if (map) {
|
|
11367
11412
|
state.localsStack.push({
|
|
11368
11413
|
node,
|
|
@@ -11397,7 +11442,7 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11397
11442
|
return null;
|
|
11398
11443
|
};
|
|
11399
11444
|
state.post = (node) => {
|
|
11400
|
-
if (
|
|
11445
|
+
if (topLocals().node === node) {
|
|
11401
11446
|
state.localsStack.pop();
|
|
11402
11447
|
}
|
|
11403
11448
|
const opt = optimizeNode(node);
|
|
@@ -11408,20 +11453,23 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11408
11453
|
switch (node.type) {
|
|
11409
11454
|
case "ConditionalExpression":
|
|
11410
11455
|
case "IfStatement":
|
|
11411
|
-
if (node.test ===
|
|
11412
|
-
|
|
11456
|
+
if (node.test.type === "Literal" &&
|
|
11457
|
+
typeof node.test.value === "boolean") {
|
|
11458
|
+
const rep = node.test.value ? node.consequent : node.alternate;
|
|
11413
11459
|
if (!rep)
|
|
11414
11460
|
return false;
|
|
11415
11461
|
replace(node, rep);
|
|
11416
11462
|
}
|
|
11417
11463
|
break;
|
|
11418
11464
|
case "WhileStatement":
|
|
11419
|
-
if (
|
|
11465
|
+
if (node.test.type === "Literal" && node.test.value === false) {
|
|
11420
11466
|
return false;
|
|
11467
|
+
}
|
|
11421
11468
|
break;
|
|
11422
11469
|
case "DoWhileStatement":
|
|
11423
|
-
if (
|
|
11470
|
+
if (node.test.type === "Literal" && node.test.value === false) {
|
|
11424
11471
|
return node.body;
|
|
11472
|
+
}
|
|
11425
11473
|
break;
|
|
11426
11474
|
case "CallExpression": {
|
|
11427
11475
|
const [name, callees] = state.lookup(node.callee);
|
|
@@ -11443,7 +11491,8 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11443
11491
|
}
|
|
11444
11492
|
if (callees.length == 1) {
|
|
11445
11493
|
const callee = (0,external_api_cjs_namespaceObject.isStateNode)(callees[0]) && callees[0].node;
|
|
11446
|
-
if (callee
|
|
11494
|
+
if (callee &&
|
|
11495
|
+
callee.type == "FunctionDeclaration" &&
|
|
11447
11496
|
callee.optimizable &&
|
|
11448
11497
|
!callee.hasOverride &&
|
|
11449
11498
|
node.arguments.every((n) => getNodeValue(n)[0] !== null)) {
|
|
@@ -11467,7 +11516,7 @@ async function optimizeMonkeyC(fnMap) {
|
|
|
11467
11516
|
(0,external_api_cjs_namespaceObject.collectNamespaces)(f.ast, state);
|
|
11468
11517
|
});
|
|
11469
11518
|
Object.values(fnMap).forEach((f) => {
|
|
11470
|
-
(0,external_api_cjs_namespaceObject.traverseAst)(f.ast,
|
|
11519
|
+
(0,external_api_cjs_namespaceObject.traverseAst)(f.ast, undefined, (node) => {
|
|
11471
11520
|
switch (node.type) {
|
|
11472
11521
|
case "EnumStringBody":
|
|
11473
11522
|
if (node.members.every((m) => {
|
|
@@ -11565,6 +11614,9 @@ const defaultConfig = {
|
|
|
11565
11614
|
outputPath: "bin/optimized",
|
|
11566
11615
|
workspace: "./",
|
|
11567
11616
|
};
|
|
11617
|
+
function isErrorWithLocation(e) {
|
|
11618
|
+
return (0,external_api_cjs_namespaceObject.hasProperty)(e, "location");
|
|
11619
|
+
}
|
|
11568
11620
|
/**
|
|
11569
11621
|
* @param {BuildConfig} options
|
|
11570
11622
|
* @returns {Promise<BuildConfig>}
|
|
@@ -11621,14 +11673,14 @@ async function buildOptimizedProject(product, options) {
|
|
|
11621
11673
|
if (product) {
|
|
11622
11674
|
product = config.products[0];
|
|
11623
11675
|
if (config.simulatorBuild === false) {
|
|
11624
|
-
bin =
|
|
11676
|
+
bin = external_path_.join(bin, product);
|
|
11625
11677
|
}
|
|
11626
11678
|
}
|
|
11627
11679
|
else {
|
|
11628
|
-
bin =
|
|
11680
|
+
bin = external_path_.join(bin, "exported");
|
|
11629
11681
|
name = `${program}.iq`;
|
|
11630
11682
|
}
|
|
11631
|
-
config.program =
|
|
11683
|
+
config.program = external_path_.join(bin, name);
|
|
11632
11684
|
if (!hasTests)
|
|
11633
11685
|
delete config.testBuild;
|
|
11634
11686
|
return build_project(product, config).then((result) => ({
|
|
@@ -11654,7 +11706,7 @@ async function buildOptimizedProject(product, options) {
|
|
|
11654
11706
|
* @param {Target[]} targets
|
|
11655
11707
|
*/
|
|
11656
11708
|
async function createLocalBarrels(targets, options) {
|
|
11657
|
-
if (targets.every((target) => !target.group
|
|
11709
|
+
if (targets.every((target) => !target.group?.optimizerConfig.barrelMap ||
|
|
11658
11710
|
Object.values(target.group.optimizerConfig.barrelMap).every((resolvedBarrel) => !resolvedBarrel.qualifier.resourcePath))) {
|
|
11659
11711
|
// there are no barrels, or every barrel has no resources.
|
|
11660
11712
|
// we can drop any barrels altogether (we'll need to drop them
|
|
@@ -11662,8 +11714,10 @@ async function createLocalBarrels(targets, options) {
|
|
|
11662
11714
|
return null;
|
|
11663
11715
|
}
|
|
11664
11716
|
// where to create the local barrel projects.
|
|
11665
|
-
const barrelDir =
|
|
11717
|
+
const barrelDir = external_path_.resolve(options.workspace, options.outputPath, "opt-barrels");
|
|
11666
11718
|
return targets.reduce((promise, target) => {
|
|
11719
|
+
if (!target.group)
|
|
11720
|
+
return promise;
|
|
11667
11721
|
const barrelMap = target.group.optimizerConfig.barrelMap;
|
|
11668
11722
|
if (!barrelMap || target.group.optimizerConfig.optBarrels) {
|
|
11669
11723
|
return promise;
|
|
@@ -11671,13 +11725,13 @@ async function createLocalBarrels(targets, options) {
|
|
|
11671
11725
|
const optBarrels = (target.group.optimizerConfig.optBarrels = {});
|
|
11672
11726
|
return Object.entries(barrelMap).reduce((promise, [barrel, resolvedBarrel]) => {
|
|
11673
11727
|
const { manifest, jungles } = resolvedBarrel;
|
|
11674
|
-
const rawBarrelDir =
|
|
11675
|
-
const rawJungles = jungles.map((jungle) =>
|
|
11728
|
+
const rawBarrelDir = external_path_.dirname(jungles[0]);
|
|
11729
|
+
const rawJungles = jungles.map((jungle) => external_path_.relative(rawBarrelDir, jungle));
|
|
11676
11730
|
const sha1 = external_crypto_namespaceObject.createHash("sha1")
|
|
11677
11731
|
.update(rawBarrelDir, "binary")
|
|
11678
11732
|
.digest("base64")
|
|
11679
11733
|
.replace(/[\/=+]/g, "");
|
|
11680
|
-
const optBarrelDir =
|
|
11734
|
+
const optBarrelDir = external_path_.resolve(barrelDir, `${barrel}-${sha1}`);
|
|
11681
11735
|
if (!(0,external_api_cjs_namespaceObject.hasProperty)(optBarrels, barrel)) {
|
|
11682
11736
|
optBarrels[barrel] = {
|
|
11683
11737
|
rawBarrelDir,
|
|
@@ -11690,22 +11744,28 @@ async function createLocalBarrels(targets, options) {
|
|
|
11690
11744
|
if (optBarrels[barrel].manifest !== manifest ||
|
|
11691
11745
|
optBarrels[barrel].optBarrelDir !== optBarrelDir ||
|
|
11692
11746
|
optBarrels[barrel].rawBarrelDir != rawBarrelDir) {
|
|
11693
|
-
throw new Error(`For device ${target.product}, barrel ${barrel} was mapped to both ${
|
|
11747
|
+
throw new Error(`For device ${target.product}, barrel ${barrel} was mapped to both ${external_path_.relative(optBarrels[barrel].rawBarrelDir, optBarrels[barrel].manifest)} in ${optBarrels[barrel].rawBarrelDir} and ${external_path_.relative(rawBarrelDir, manifest)} in ${rawBarrelDir}.`);
|
|
11694
11748
|
}
|
|
11695
11749
|
optBarrels[barrel].jungleFiles.push(...rawJungles);
|
|
11696
11750
|
return promise;
|
|
11697
11751
|
}, promise);
|
|
11698
11752
|
}, Promise.resolve());
|
|
11699
11753
|
}
|
|
11700
|
-
/**
|
|
11701
|
-
*
|
|
11702
|
-
* @param {BuildConfig} options
|
|
11703
|
-
* @returns
|
|
11704
|
-
*/
|
|
11705
11754
|
async function generateOptimizedProject(options) {
|
|
11706
11755
|
const config = await getConfig(options);
|
|
11707
11756
|
const workspace = config.workspace;
|
|
11708
11757
|
const { manifest, targets, xml, jungles } = await get_jungle(config.jungleFiles, config);
|
|
11758
|
+
if (!xml["iq:manifest"]["iq:application"]) {
|
|
11759
|
+
const error = new Error(xml["iq:manifest"]["iq:barrel"]
|
|
11760
|
+
? "Optimize the project that uses this barrel, not the barrel itself"
|
|
11761
|
+
: "Manifest is missing an `iq:application` tag");
|
|
11762
|
+
error.location = {
|
|
11763
|
+
start: { line: 1, column: 1 },
|
|
11764
|
+
end: { line: 1, column: 1 },
|
|
11765
|
+
source: manifest,
|
|
11766
|
+
};
|
|
11767
|
+
throw error;
|
|
11768
|
+
}
|
|
11709
11769
|
const dependencyFiles = [manifest, ...jungles];
|
|
11710
11770
|
await createLocalBarrels(targets, options);
|
|
11711
11771
|
const buildConfigs = {};
|
|
@@ -11718,12 +11778,15 @@ async function generateOptimizedProject(options) {
|
|
|
11718
11778
|
}
|
|
11719
11779
|
return {
|
|
11720
11780
|
jungleFiles: config.jungleFiles,
|
|
11721
|
-
program:
|
|
11781
|
+
program: external_path_.basename(external_path_.dirname(manifest)),
|
|
11722
11782
|
};
|
|
11723
11783
|
}
|
|
11724
11784
|
let dropBarrels = false;
|
|
11725
11785
|
const configKey = (p) => p.group.key + (config.releaseBuild ? "-release" : "-debug");
|
|
11726
11786
|
targets.forEach((p) => {
|
|
11787
|
+
if (!p.group) {
|
|
11788
|
+
throw new Error(`Missing group in build target ${p.product}`);
|
|
11789
|
+
}
|
|
11727
11790
|
const key = configKey(p);
|
|
11728
11791
|
if (!(0,external_api_cjs_namespaceObject.hasProperty)(buildConfigs, key)) {
|
|
11729
11792
|
p.group.dir = key;
|
|
@@ -11752,9 +11815,9 @@ async function generateOptimizedProject(options) {
|
|
|
11752
11815
|
}
|
|
11753
11816
|
});
|
|
11754
11817
|
// console.log(JSON.stringify(targets));
|
|
11755
|
-
const jungle_dir =
|
|
11818
|
+
const jungle_dir = external_path_.resolve(workspace, config.outputPath);
|
|
11756
11819
|
await promises_namespaceObject.mkdir(jungle_dir, { recursive: true });
|
|
11757
|
-
const relative_path = (s) =>
|
|
11820
|
+
const relative_path = (s) => external_path_.relative(jungle_dir, s);
|
|
11758
11821
|
let relative_manifest = relative_path(manifest);
|
|
11759
11822
|
const manifestOk = (!config.checkManifest ||
|
|
11760
11823
|
(await checkManifest(xml, targets.map((t) => t.product)))) &&
|
|
@@ -11764,7 +11827,7 @@ async function generateOptimizedProject(options) {
|
|
|
11764
11827
|
.sort()
|
|
11765
11828
|
.map((key) => {
|
|
11766
11829
|
const buildConfig = buildConfigs[key];
|
|
11767
|
-
const outputPath =
|
|
11830
|
+
const outputPath = external_path_.join(config.outputPath, key);
|
|
11768
11831
|
return buildConfig
|
|
11769
11832
|
? generateOneConfig(buildConfig, dependencyFiles, {
|
|
11770
11833
|
...config,
|
|
@@ -11778,7 +11841,7 @@ async function generateOptimizedProject(options) {
|
|
|
11778
11841
|
throw e;
|
|
11779
11842
|
})
|
|
11780
11843
|
.then((t) => t && (hasTests = true))
|
|
11781
|
-
: promises_namespaceObject.rm(
|
|
11844
|
+
: promises_namespaceObject.rm(external_path_.resolve(workspace, outputPath), {
|
|
11782
11845
|
recursive: true,
|
|
11783
11846
|
force: true,
|
|
11784
11847
|
});
|
|
@@ -11787,29 +11850,33 @@ async function generateOptimizedProject(options) {
|
|
|
11787
11850
|
if (dropBarrels) {
|
|
11788
11851
|
manifestDropBarrels(xml);
|
|
11789
11852
|
}
|
|
11790
|
-
const manifestFile =
|
|
11853
|
+
const manifestFile = external_path_.join(jungle_dir, "manifest.xml");
|
|
11791
11854
|
promises.push(writeManifest(manifestFile, xml));
|
|
11792
11855
|
relative_manifest = "manifest.xml";
|
|
11793
11856
|
}
|
|
11794
11857
|
const parts = [`project.manifest=${relative_manifest}`];
|
|
11795
11858
|
const process_field = (prefix, base, name, mapper = null) => {
|
|
11796
|
-
|
|
11859
|
+
const obj = base[name];
|
|
11860
|
+
if (!obj)
|
|
11797
11861
|
return;
|
|
11798
11862
|
const map_one = (s) => (mapper ? mapper(s) : s);
|
|
11799
11863
|
const map = (s) => Array.isArray(s) ? `[${s.map(map_one).join(";")}]` : map_one(s);
|
|
11800
|
-
parts.push(`${prefix}${name} = ${
|
|
11864
|
+
parts.push(`${prefix}${name} = ${obj.map(map).join(";")}`);
|
|
11801
11865
|
};
|
|
11802
|
-
targets.forEach((
|
|
11803
|
-
if (!buildConfigs[configKey(
|
|
11866
|
+
targets.forEach((target) => {
|
|
11867
|
+
if (!buildConfigs[configKey(target)])
|
|
11804
11868
|
return;
|
|
11805
|
-
const { product, qualifier, group } =
|
|
11869
|
+
const { product, qualifier, group } = target;
|
|
11870
|
+
if (!group) {
|
|
11871
|
+
throw new Error(`Missing group in target ${target.product}`);
|
|
11872
|
+
}
|
|
11806
11873
|
const prefix = `${product}.`;
|
|
11807
|
-
process_field(prefix, qualifier, "sourcePath", (s) =>
|
|
11874
|
+
process_field(prefix, qualifier, "sourcePath", (s) => external_path_.join(group.dir, "source", relative_path_no_dotdot(external_path_.relative(workspace, s)))
|
|
11808
11875
|
.replace(/([\\\/]\*\*)[\\\/]\*/g, "$1"));
|
|
11809
11876
|
if (group.optimizerConfig.optBarrels) {
|
|
11810
11877
|
parts.push(`${prefix}barrelPath = ${Object.values(group.optimizerConfig.optBarrels)
|
|
11811
11878
|
.map((value) => `[${value.jungleFiles
|
|
11812
|
-
.map((j) => relative_path(
|
|
11879
|
+
.map((j) => relative_path(external_path_.join(value.optBarrelDir, j)))
|
|
11813
11880
|
.join(";")}]`)
|
|
11814
11881
|
.join(";")}`);
|
|
11815
11882
|
}
|
|
@@ -11817,8 +11884,8 @@ async function generateOptimizedProject(options) {
|
|
|
11817
11884
|
parts.push(`${prefix}sourcePath = ${[`$(${prefix}sourcePath)`]
|
|
11818
11885
|
.concat(Object.entries(group.optimizerConfig.barrelMap)
|
|
11819
11886
|
.map(([barrel, resolvedBarrel]) => {
|
|
11820
|
-
const root =
|
|
11821
|
-
return (resolvedBarrel.qualifier.sourcePath || []).map((s) =>
|
|
11887
|
+
const root = external_path_.dirname(resolvedBarrel.jungles[0]);
|
|
11888
|
+
return (resolvedBarrel.qualifier.sourcePath || []).map((s) => external_path_.join(group.dir, "barrels", barrel, external_path_.relative(root, s))
|
|
11822
11889
|
.replace(/([\\\/]\*\*)[\\\/]\*/g, "$1"));
|
|
11823
11890
|
})
|
|
11824
11891
|
.flat()
|
|
@@ -11829,29 +11896,31 @@ async function generateOptimizedProject(options) {
|
|
|
11829
11896
|
// annotations were handled via source transformations.
|
|
11830
11897
|
process_field(prefix, qualifier, "resourcePath", relative_path);
|
|
11831
11898
|
process_field(prefix, qualifier, "excludeAnnotations");
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11899
|
+
const qlang = qualifier.lang;
|
|
11900
|
+
if (qlang) {
|
|
11901
|
+
Object.keys(qlang).forEach((key) => {
|
|
11902
|
+
process_field(`${prefix}lang.`, qlang, key, relative_path);
|
|
11835
11903
|
});
|
|
11836
11904
|
}
|
|
11837
11905
|
});
|
|
11838
|
-
const jungleFiles =
|
|
11906
|
+
const jungleFiles = external_path_.join(jungle_dir, `${config.releaseBuild ? "release" : "debug"}.jungle`);
|
|
11839
11907
|
promises.push(promises_namespaceObject.writeFile(jungleFiles, parts.join("\n")));
|
|
11840
11908
|
await Promise.all(promises);
|
|
11841
11909
|
return {
|
|
11842
11910
|
jungleFiles,
|
|
11843
|
-
|
|
11911
|
+
xml,
|
|
11912
|
+
program: external_path_.basename(external_path_.dirname(manifest)),
|
|
11844
11913
|
hasTests,
|
|
11845
11914
|
};
|
|
11846
11915
|
}
|
|
11847
11916
|
async function fileInfoFromConfig(workspace, output, buildConfig, extraExcludes) {
|
|
11848
|
-
const paths = (await Promise.all(buildConfig.sourcePath
|
|
11917
|
+
const paths = (await Promise.all(buildConfig.sourcePath?.map((pattern) => (0,external_util_cjs_namespaceObject.globa)(pattern, { cwd: workspace, mark: true })) || [])).flat();
|
|
11849
11918
|
const files = (await Promise.all(paths.map((path) => path.endsWith("/")
|
|
11850
11919
|
? (0,external_util_cjs_namespaceObject.globa)(`${path}**/*.mc`, { cwd: workspace, mark: true })
|
|
11851
11920
|
: path)))
|
|
11852
11921
|
.flat()
|
|
11853
11922
|
.filter((file) => file.endsWith(".mc") &&
|
|
11854
|
-
!
|
|
11923
|
+
!external_path_.relative(workspace, file).startsWith("bin") &&
|
|
11855
11924
|
(!buildConfig.sourceExcludes ||
|
|
11856
11925
|
!buildConfig.sourceExcludes.includes(file)));
|
|
11857
11926
|
const excludeAnnotations = Object.assign(buildConfig.excludeAnnotations
|
|
@@ -11861,7 +11930,7 @@ async function fileInfoFromConfig(workspace, output, buildConfig, extraExcludes)
|
|
|
11861
11930
|
fnMap: Object.fromEntries(files.map((file) => [
|
|
11862
11931
|
file,
|
|
11863
11932
|
{
|
|
11864
|
-
output:
|
|
11933
|
+
output: external_path_.join(output, relative_path_no_dotdot(external_path_.relative(workspace, file))),
|
|
11865
11934
|
excludeAnnotations,
|
|
11866
11935
|
},
|
|
11867
11936
|
])),
|
|
@@ -11896,7 +11965,7 @@ const configOptionsToCheck = [
|
|
|
11896
11965
|
*/
|
|
11897
11966
|
async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
11898
11967
|
const { workspace } = config;
|
|
11899
|
-
const output =
|
|
11968
|
+
const output = external_path_.join(workspace, config.outputPath);
|
|
11900
11969
|
const buildModeExcludes = {
|
|
11901
11970
|
// note: exclude debug in release builds, and release in debug builds
|
|
11902
11971
|
[config.releaseBuild ? "debug" : "release"]: true,
|
|
@@ -11904,12 +11973,12 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
11904
11973
|
if (!config.testBuild) {
|
|
11905
11974
|
buildModeExcludes.test = true;
|
|
11906
11975
|
}
|
|
11907
|
-
const { fnMap } = await fileInfoFromConfig(workspace,
|
|
11976
|
+
const { fnMap } = await fileInfoFromConfig(workspace, external_path_.join(output, "source"), buildConfig, buildModeExcludes);
|
|
11908
11977
|
if (buildConfig.barrelMap) {
|
|
11909
11978
|
const barrelFnMaps = await Promise.all(Object.entries(buildConfig.barrelMap)
|
|
11910
11979
|
.map(([barrel, resolvedBarrel]) => {
|
|
11911
11980
|
dependencyFiles = dependencyFiles.concat(resolvedBarrel.jungles, resolvedBarrel.manifest);
|
|
11912
|
-
return fileInfoFromConfig(
|
|
11981
|
+
return fileInfoFromConfig(external_path_.dirname(resolvedBarrel.jungles[0]), external_path_.join(output, "barrels", barrel), resolvedBarrel.qualifier, {
|
|
11913
11982
|
...buildModeExcludes,
|
|
11914
11983
|
...excludesFromAnnotations(barrel, buildConfig.annotations, resolvedBarrel),
|
|
11915
11984
|
}).then(({ fnMap }) => fnMap);
|
|
@@ -11917,10 +11986,10 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
11917
11986
|
.flat());
|
|
11918
11987
|
barrelFnMaps.forEach((barrelFnMap) => Object.assign(fnMap, barrelFnMap));
|
|
11919
11988
|
}
|
|
11920
|
-
const actualOptimizedFiles = (await (0,external_util_cjs_namespaceObject.globa)(
|
|
11989
|
+
const actualOptimizedFiles = (await (0,external_util_cjs_namespaceObject.globa)(external_path_.join(output, "**", "*.mc"), { mark: true }))
|
|
11921
11990
|
.filter((file) => !file.endsWith("/"))
|
|
11922
11991
|
.sort();
|
|
11923
|
-
const { hasTests, ...prevOptions } = JSON.parse(await promises_namespaceObject.readFile(
|
|
11992
|
+
const { hasTests, ...prevOptions } = JSON.parse(await promises_namespaceObject.readFile(external_path_.join(output, "build-info.json"), "utf-8")
|
|
11924
11993
|
.catch(() => "{}"));
|
|
11925
11994
|
// check that the set of files thats actually there is the same as the
|
|
11926
11995
|
// set of files we're going to generate (in case eg a jungle file change
|
|
@@ -11937,7 +12006,7 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
11937
12006
|
// the oldest optimized file, we don't need to regenerate
|
|
11938
12007
|
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
|
|
11939
12008
|
const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
|
|
11940
|
-
if (source_time < opt_time &&
|
|
12009
|
+
if (source_time < opt_time && 1653671578547 < opt_time) {
|
|
11941
12010
|
return hasTests;
|
|
11942
12011
|
}
|
|
11943
12012
|
}
|
|
@@ -11946,14 +12015,14 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
11946
12015
|
await optimizeMonkeyC(fnMap);
|
|
11947
12016
|
return Promise.all(Object.values(fnMap).map(async (info) => {
|
|
11948
12017
|
const name = info.output;
|
|
11949
|
-
const dir =
|
|
12018
|
+
const dir = external_path_.dirname(name);
|
|
11950
12019
|
await promises_namespaceObject.mkdir(dir, { recursive: true });
|
|
11951
12020
|
const opt_source = (0,external_api_cjs_namespaceObject.formatAst)(info.ast, info.monkeyCSource);
|
|
11952
12021
|
await promises_namespaceObject.writeFile(name, opt_source);
|
|
11953
12022
|
return info.hasTests;
|
|
11954
12023
|
})).then((results) => {
|
|
11955
12024
|
const hasTests = results.some((v) => v);
|
|
11956
|
-
return promises_namespaceObject.writeFile(
|
|
12025
|
+
return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
|
|
11957
12026
|
hasTests,
|
|
11958
12027
|
...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
|
|
11959
12028
|
}))
|
|
@@ -11963,6 +12032,7 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
11963
12032
|
async function getProjectAnalysis(targets, analysis, options) {
|
|
11964
12033
|
const sourcePath = targets
|
|
11965
12034
|
.map(({ qualifier: { sourcePath } }) => sourcePath)
|
|
12035
|
+
.filter((sp) => sp != null)
|
|
11966
12036
|
.flat()
|
|
11967
12037
|
.sort()
|
|
11968
12038
|
.filter((s, i, arr) => !i || s !== arr[i - 1]);
|
|
@@ -11993,21 +12063,28 @@ async function generateApiMirTests(options) {
|
|
|
11993
12063
|
const config = { ...defaultConfig, ...(options || {}) };
|
|
11994
12064
|
const tests = [];
|
|
11995
12065
|
const api = await (0,external_api_cjs_namespaceObject.getApiMapping)();
|
|
12066
|
+
if (!api) {
|
|
12067
|
+
throw new Error("Failed to read api.mir");
|
|
12068
|
+
}
|
|
11996
12069
|
const findConstants = (node) => {
|
|
11997
|
-
|
|
11998
|
-
|
|
11999
|
-
|
|
12000
|
-
|
|
12001
|
-
|
|
12002
|
-
|
|
12003
|
-
|
|
12004
|
-
(d.type === "
|
|
12005
|
-
|
|
12006
|
-
|
|
12007
|
-
|
|
12008
|
-
|
|
12009
|
-
|
|
12010
|
-
|
|
12070
|
+
node.decls &&
|
|
12071
|
+
Object.entries(node.decls).forEach(([key, decl]) => {
|
|
12072
|
+
if (decl.length > 1)
|
|
12073
|
+
throw `Bad decl length:${node.fullName}.${key}`;
|
|
12074
|
+
if (decl.length != 1)
|
|
12075
|
+
return;
|
|
12076
|
+
const d = decl[0];
|
|
12077
|
+
if (d.type === "EnumStringMember" ||
|
|
12078
|
+
(d.type === "VariableDeclarator" && d.kind === "const")) {
|
|
12079
|
+
if (!d.init) {
|
|
12080
|
+
throw new Error(`Missing init for ${node.fullName}.${key}`);
|
|
12081
|
+
}
|
|
12082
|
+
tests.push([`${node.fullName}.${key}`, (0,external_api_cjs_namespaceObject.formatAst)(d.init)]);
|
|
12083
|
+
}
|
|
12084
|
+
else if ((0,external_api_cjs_namespaceObject.isStateNode)(d)) {
|
|
12085
|
+
findConstants(d);
|
|
12086
|
+
}
|
|
12087
|
+
});
|
|
12011
12088
|
};
|
|
12012
12089
|
findConstants(api);
|
|
12013
12090
|
function hasTests(name) {
|