mirror of
https://gitee.com/openharmony/developtools_ace_js2bundle
synced 2024-11-27 01:20:27 +00:00
Modify ark compiler exectue mode of ts2abc
Issue: I65HT5 Signed-off-by: zhangrengao <zhangrengao1@huawei.com> Change-Id: I24158de0b4e874a52d1463a8f8ae58cba25e9870
This commit is contained in:
parent
6b5f8b5607
commit
34f85a6dec
@ -20,8 +20,6 @@ const SUCCESS = 0;
|
||||
const FAIL = 1;
|
||||
const red = '\u001b[31m';
|
||||
const reset = '\u001b[39m';
|
||||
const TS2ABC = 'ts2abc';
|
||||
const ES2ABC = 'es2abc';
|
||||
|
||||
function js2abcByWorkers(jsonInput, cmd) {
|
||||
const inputPaths = JSON.parse(jsonInput);
|
||||
|
@ -60,13 +60,11 @@ const NODE_MODULES = 'node_modules';
|
||||
const TEMPORARY = 'temporary';
|
||||
const TS2ABC = 'ts2abc';
|
||||
const ES2ABC = 'es2abc';
|
||||
let previewCount = 0;
|
||||
let compileCount = 0;
|
||||
const WINDOWS = 'Windows_NT';
|
||||
const LINUX = 'Linux';
|
||||
const MAC = 'Darwin';
|
||||
const FILESINFO_TXT = 'filesInfo.txt';
|
||||
const BUNDLE_CACHE = 'bundle.cache';
|
||||
const manageBunldeWorkersScript = 'manage-bundle-workers.js';
|
||||
|
||||
class GenAbcPlugin {
|
||||
constructor(output_, arkDir_, nodeJs_, workerFile_, isDebug_) {
|
||||
@ -129,12 +127,7 @@ class GenAbcPlugin {
|
||||
|
||||
function processMultiThreadEntry() {
|
||||
if (isTs2Abc() || process.env.minPlatformVersion === "8") {
|
||||
if (previewCount == compileCount) {
|
||||
previewCount++;
|
||||
invokeWorkerToGenAbc();
|
||||
} else {
|
||||
previewCount++;
|
||||
}
|
||||
} else if (isEs2Abc()) {
|
||||
generateAbcByEs2AbcOfBundleMode(intermediateJsBundle);
|
||||
} else {
|
||||
@ -264,73 +257,17 @@ function invokeWorkerToGenAbc() {
|
||||
const splitedBundles = splitJsBundlesBySize(fileterIntermediateJsBundle, maxWorkerNumber);
|
||||
const workerNumber = maxWorkerNumber < splitedBundles.length ? maxWorkerNumber : splitedBundles.length;
|
||||
|
||||
const clusterNewApiVersion = 16;
|
||||
const currentNodeVersion = parseInt(process.version.split('.')[0]);
|
||||
const useNewApi = currentNodeVersion >= clusterNewApiVersion ? true : false;
|
||||
|
||||
if ((useNewApi && cluster.isPrimary) || (!useNewApi && cluster.isMaster)) {
|
||||
if (useNewApi) {
|
||||
cluster.setupPrimary({
|
||||
exec: path.resolve(__dirname, genAbcScript)
|
||||
});
|
||||
try {
|
||||
if (process.env.isPreview === 'true') {
|
||||
processWorkersOfPreviewMode(splitedBundles, cmdPrefix, workerNumber);
|
||||
} else {
|
||||
cluster.setupMaster({
|
||||
exec: path.resolve(__dirname, genAbcScript)
|
||||
});
|
||||
processWorkersOfBuildMode(splitedBundles, cmdPrefix, workerNumber);
|
||||
}
|
||||
|
||||
if (workerNumber === 0) {
|
||||
if (process.env.isPreview === 'true' && compileCount < previewCount) {
|
||||
compileCount++;
|
||||
processExtraAssetForBundle();
|
||||
if (compileCount >= previewCount) {
|
||||
return;
|
||||
}
|
||||
invokeWorkerToGenAbc();
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < workerNumber; ++i) {
|
||||
let workerData = {
|
||||
"inputs": JSON.stringify(splitedBundles[i]),
|
||||
"cmd": cmdPrefix
|
||||
}
|
||||
cluster.fork(workerData);
|
||||
}
|
||||
|
||||
let count_ = 0;
|
||||
if (process.env.isPreview === 'true') {
|
||||
process.removeAllListeners("exit");
|
||||
cluster.removeAllListeners("exit");
|
||||
}
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
if (code === FAIL) {
|
||||
process.exitCode = FAIL;
|
||||
}
|
||||
count_++;
|
||||
if (count_ === workerNumber) {
|
||||
// for preview of with incre compile
|
||||
if (process.env.isPreview === "true" && compileCount < previewCount) {
|
||||
compileCount++;
|
||||
processExtraAssetForBundle();
|
||||
if (code === SUCCESS) {
|
||||
console.log(blue, 'COMPILE RESULT:SUCCESS ', reset);
|
||||
} else {
|
||||
console.log(blue, 'COMPILE RESULT:FAIL ', reset);
|
||||
}
|
||||
if (compileCount >= previewCount) {
|
||||
return;
|
||||
}
|
||||
invokeWorkerToGenAbc();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (process.env.isPreview !== "true") {
|
||||
process.on('exit', (code) => {
|
||||
// for build options
|
||||
processExtraAssetForBundle();
|
||||
});
|
||||
} catch (e) {
|
||||
console.debug(red, `ERROR failed to generate abc. Error message: ${e} `, reset);
|
||||
process.env.abcCompileSuccess = 'false';
|
||||
if (process.env.isPreview !== 'true') {
|
||||
process.exit(FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -632,10 +569,11 @@ function generateAbcByEs2AbcOfBundleMode(inputPaths) {
|
||||
try {
|
||||
if (process.env.isPreview === 'true') {
|
||||
childProcess.execSync(genAbcCmd);
|
||||
processExtraAssetForBundle();
|
||||
} else {
|
||||
const child = childProcess.exec(genAbcCmd);
|
||||
child.on('exit', (code) => {
|
||||
if (code === 1) {
|
||||
if (code === FAIL) {
|
||||
console.debug(red, "ERROR failed to execute es2abc", reset);
|
||||
process.exit(FAIL);
|
||||
}
|
||||
@ -665,7 +603,6 @@ function generateAbcByEs2AbcOfBundleMode(inputPaths) {
|
||||
if (process.env.cachePath === undefined) {
|
||||
unlinkSync(filesInfoPath);
|
||||
}
|
||||
processExtraAssetForBundle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -728,4 +665,55 @@ function initCmdPrefix(abcArgs) {
|
||||
}
|
||||
|
||||
return cmdPrefix;
|
||||
}
|
||||
|
||||
function processWorkersOfPreviewMode(splittedData, cmdPrefix, workerNumber) {
|
||||
let envParams = {
|
||||
'splittedData': JSON.stringify(splittedData),
|
||||
'cmdPrefix': cmdPrefix,
|
||||
'workerNumber': workerNumber.toString()
|
||||
};
|
||||
|
||||
let genAbcCmd = `${nodeJs} ${path.resolve(__dirname, manageBunldeWorkersScript)}`;
|
||||
childProcess.execSync(genAbcCmd, {env: envParams});
|
||||
processExtraAssetForBundle();
|
||||
}
|
||||
|
||||
function processWorkersOfBuildMode(splittedData, cmdPrefix, workerNumber) {
|
||||
const clusterNewApiVersion = 16;
|
||||
const currentNodeVersion = parseInt(process.version.split(".")[0]);
|
||||
const useNewApi = currentNodeVersion >= clusterNewApiVersion;
|
||||
|
||||
if (useNewApi && cluster.isPrimary || !useNewApi && cluster.isMaster) {
|
||||
if (useNewApi) {
|
||||
cluster.setupPrimary({
|
||||
exec: path.resolve(__dirname, genAbcScript)
|
||||
});
|
||||
} else {
|
||||
cluster.setupMaster({
|
||||
exec: path.resolve(__dirname, genAbcScript)
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < workerNumber; ++i) {
|
||||
let workerData = {
|
||||
'inputs': JSON.stringify(splittedData[i]),
|
||||
'cmd': cmdPrefix
|
||||
};
|
||||
cluster.fork(workerData);
|
||||
}
|
||||
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
if (code === FAIL) {
|
||||
process.exitCode = FAIL;
|
||||
}
|
||||
console.debug(`worker ${worker.process.pid} finished`);
|
||||
});
|
||||
|
||||
process.on('exit', (code) => {
|
||||
if (process.exitCode !== FAIL && process.env.isPreview !== 'true') {
|
||||
processExtraAssetForBundle();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
58
ace-loader/src/manage-bundle-workers.js
Normal file
58
ace-loader/src/manage-bundle-workers.js
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as path from "path";
|
||||
import cluster from "cluster";
|
||||
import process from "process";
|
||||
const genAbcScript = "gen-abc.js";
|
||||
const FAIL = 1;
|
||||
|
||||
if (process.env["workerNumber"] !== undefined &&
|
||||
process.env["splittedData"] !== undefined &&
|
||||
process.env["cmdPrefix"] !== undefined
|
||||
) {
|
||||
const clusterNewApiVersion = 16;
|
||||
const currentNodeVersion = parseInt(process.version.split(".")[0]);
|
||||
const useNewApi = currentNodeVersion >= clusterNewApiVersion;
|
||||
|
||||
let workerNumber = parseInt(process.env.workerNumber);
|
||||
let splittedData = JSON.parse(process.env.splittedData);
|
||||
let cmdPrefix = process.env.cmdPrefix;
|
||||
|
||||
if ((useNewApi && cluster.isPrimary) || (!useNewApi && cluster.isMaster)) {
|
||||
if (useNewApi) {
|
||||
cluster.setupPrimary({
|
||||
exec: path.resolve(__dirname, genAbcScript),
|
||||
});
|
||||
} else {
|
||||
cluster.setupMaster({
|
||||
exec: path.resolve(__dirname, genAbcScript),
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < workerNumber; ++i) {
|
||||
const workerData = {
|
||||
inputs: JSON.stringify(splittedData[i]),
|
||||
cmd: cmdPrefix,
|
||||
};
|
||||
cluster.fork(workerData);
|
||||
}
|
||||
cluster.on("exit", (worker, code, signal) => {
|
||||
if (code === FAIL) {
|
||||
process.exit(FAIL);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user