mirror of
https://gitee.com/openharmony/developtools_ace_ets2bundle
synced 2024-11-23 08:29:55 +00:00
Fix remaining problem for printer optimization
Issue: https://gitee.com/openharmony/developtools_ace_ets2bundle/issues/IB1TNU Test: ut & arkut Signed-off-by: dengxinyu <dengxinyu4@huawei.com> Change-Id: Ifd1082ca5ff04e5238a843aa501ae0601c6bdecd
This commit is contained in:
parent
c00853c3f5
commit
11bc224aa2
@ -24,7 +24,11 @@ import {
|
||||
nameCacheMap,
|
||||
unobfuscationNamesObj,
|
||||
performancePrinter,
|
||||
EventList
|
||||
EventList,
|
||||
endFilesEvent,
|
||||
endSingleFileEvent,
|
||||
startFilesEvent,
|
||||
startSingleFileEvent,
|
||||
} from 'arkguard';
|
||||
import {
|
||||
OH_MODULES,
|
||||
@ -514,11 +518,11 @@ export interface ModuleInfo {
|
||||
export async function writeObfuscatedSourceCode(moduleInfo: ModuleInfo, logger: Object,
|
||||
projectConfig: Object, rollupNewSourceMaps: Object = {}): Promise<void> {
|
||||
if (compileToolIsRollUp() && projectConfig.arkObfuscator) {
|
||||
performancePrinter?.filesPrinter?.startEvent(moduleInfo.buildFilePath);
|
||||
startFilesEvent(moduleInfo.buildFilePath);
|
||||
MemoryUtils.tryGC();
|
||||
await writeArkguardObfuscatedSourceCode(moduleInfo, logger, projectConfig, rollupNewSourceMaps);
|
||||
MemoryUtils.tryGC();
|
||||
performancePrinter?.filesPrinter?.endEvent(moduleInfo.buildFilePath, undefined, true);
|
||||
endFilesEvent(moduleInfo.buildFilePath, undefined, true);
|
||||
return;
|
||||
}
|
||||
mkdirsSync(path.dirname(moduleInfo.buildFilePath));
|
||||
@ -576,10 +580,10 @@ export async function writeArkguardObfuscatedSourceCode(moduleInfo: ModuleInfo,
|
||||
} = { packageDir, projectRootPath, localPackageSet, useNormalized, useTsHar };
|
||||
let filePathObj = { buildFilePath: moduleInfo.buildFilePath, relativeFilePath: moduleInfo.relativeSourceFilePath };
|
||||
try {
|
||||
performancePrinter?.singleFilePrinter?.startEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter, filePathObj.buildFilePath);
|
||||
startSingleFileEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter, filePathObj.buildFilePath);
|
||||
mixedInfo = await arkObfuscator.obfuscate(moduleInfo.content, filePathObj, previousStageSourceMap,
|
||||
historyNameCache, moduleInfo.originSourceFilePath, projectInfo);
|
||||
performancePrinter?.singleFilePrinter?.endEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter);
|
||||
endSingleFileEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter);
|
||||
} catch (err) {
|
||||
logger.error(red, `ArkTS:INTERNAL ERROR: Failed to obfuscate file '${moduleInfo.relativeSourceFilePath}' with arkguard. ${err}`);
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ import {
|
||||
deleteLineInfoForNameString,
|
||||
mangleFilePath,
|
||||
unobfuscationNamesObj,
|
||||
EventList
|
||||
EventList,
|
||||
endSingleFileEvent,
|
||||
startSingleFileEvent
|
||||
} from 'arkguard';
|
||||
import type {
|
||||
ArkObfuscator,
|
||||
@ -149,17 +151,6 @@ function getFileNamesForScanningWhitelist(mergedObConfig: MergedConfig, allKeepF
|
||||
return keepFilesAndDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable performance printer when the build mode is debug
|
||||
*/
|
||||
export function disablePerformancePrinter(): void {
|
||||
if (performancePrinter !== undefined) {
|
||||
performancePrinter.filesPrinter = undefined;
|
||||
performancePrinter.singleFilePrinter = undefined;
|
||||
performancePrinter.timeSumPrinter = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get namecache by path
|
||||
*
|
||||
@ -230,8 +221,8 @@ export function setUnobfuscationNames(
|
||||
* Write out obfuscated files
|
||||
*/
|
||||
export function writeObfuscatedFile(newFilePath: string, content: string): void {
|
||||
performancePrinter?.singleFilePrinter?.startEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter);
|
||||
startSingleFileEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter);
|
||||
mkdirsSync(path.dirname(newFilePath));
|
||||
fs.writeFileSync(newFilePath, content);
|
||||
performancePrinter?.singleFilePrinter?.endEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter, false, true);
|
||||
endSingleFileEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter, false, true);
|
||||
}
|
@ -20,7 +20,10 @@ import {
|
||||
initObfuscationConfig,
|
||||
readProjectPropertiesByCollectedPaths,
|
||||
performancePrinter,
|
||||
EventList
|
||||
EventList,
|
||||
blockPrinter,
|
||||
endFilesEvent,
|
||||
startFilesEvent,
|
||||
} from 'arkguard';
|
||||
|
||||
import {
|
||||
@ -45,7 +48,7 @@ import {
|
||||
import { getArkBuildDir } from '../../../ark_utils';
|
||||
import { checkAotConfig } from '../../../gen_aot';
|
||||
import { projectConfig as mainProjectConfig } from '../../../../main';
|
||||
import { disablePerformancePrinter, type MergedConfig } from './ob_config_resolver';
|
||||
import type { MergedConfig } from './ob_config_resolver';
|
||||
import type { ReseverdSetForArkguard } from 'arkguard';
|
||||
|
||||
type ArkConfig = {
|
||||
@ -176,12 +179,12 @@ export function initArkProjectConfig(share: Object): Object {
|
||||
if (!isDebug(projectConfig)) {
|
||||
arkProjectConfig.useTsHar = mainProjectConfig.useTsHar;
|
||||
const logger: any = share.getLogger(OBFUSCATION_TOOL);
|
||||
performancePrinter?.filesPrinter?.startEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter);
|
||||
startFilesEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter);
|
||||
initObfuscationConfig(projectConfig, arkProjectConfig, logger);
|
||||
performancePrinter?.filesPrinter?.endEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter);
|
||||
endFilesEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter);
|
||||
} else {
|
||||
// Set performance printer to undefined in case we cannot disable it without obfuscation initialization
|
||||
disablePerformancePrinter();
|
||||
blockPrinter();
|
||||
}
|
||||
return arkProjectConfig;
|
||||
}
|
||||
|
@ -66,7 +66,14 @@ import {
|
||||
localPackageSet
|
||||
} from '../../../ets_checker';
|
||||
import { projectConfig } from '../../../../main';
|
||||
import { performancePrinter, EventList } from 'arkguard';
|
||||
import {
|
||||
EventList,
|
||||
endFilesEvent,
|
||||
performancePrinter,
|
||||
printTimeSumData,
|
||||
printTimeSumInfo,
|
||||
startFilesEvent
|
||||
} from 'arkguard';
|
||||
const ROLLUP_IMPORT_NODE: string = 'ImportDeclaration';
|
||||
const ROLLUP_EXPORTNAME_NODE: string = 'ExportNamedDeclaration';
|
||||
const ROLLUP_EXPORTALL_NODE: string = 'ExportAllDeclaration';
|
||||
@ -305,7 +312,7 @@ export class ModuleSourceFile {
|
||||
}
|
||||
|
||||
collectAllFiles(undefined, rollupObject.getModuleIds(), rollupObject);
|
||||
performancePrinter?.filesPrinter?.startEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter);
|
||||
startFilesEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter);
|
||||
let sourceProjectConfig: Object = ModuleSourceFile.projectConfig;
|
||||
// obfuscation initialization, include collect file, resolve denpendency, read source
|
||||
if (compileToolIsRollUp()) {
|
||||
@ -316,9 +323,9 @@ export class ModuleSourceFile {
|
||||
readProjectAndLibsSource(allSourceFilePaths, obfuscationConfig, sourceProjectConfig.arkObfuscator,
|
||||
sourceProjectConfig.compileHar, keepFilesAndDependencies);
|
||||
}
|
||||
performancePrinter?.filesPrinter?.endEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter);
|
||||
endFilesEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter);
|
||||
|
||||
performancePrinter?.filesPrinter?.startEvent(EventList.ALL_FILES_OBFUSCATION);
|
||||
startFilesEvent(EventList.ALL_FILES_OBFUSCATION);
|
||||
let byteCodeHar = false;
|
||||
if (Object.prototype.hasOwnProperty.call(sourceProjectConfig, 'byteCodeHar')) {
|
||||
byteCodeHar = sourceProjectConfig.byteCodeHar;
|
||||
@ -342,9 +349,9 @@ export class ModuleSourceFile {
|
||||
if (compileToolIsRollUp() && rollupObject.share.arkProjectConfig.compileMode === ESMODULE) {
|
||||
await mangleDeclarationFileName(ModuleSourceFile.logger, rollupObject.share.arkProjectConfig, sourceFileBelongProject);
|
||||
}
|
||||
performancePrinter?.timeSumPrinter?.print('All files obfuscation:');
|
||||
performancePrinter?.timeSumPrinter?.summarizeEventDuration();
|
||||
performancePrinter?.filesPrinter?.endEvent(EventList.ALL_FILES_OBFUSCATION);
|
||||
printTimeSumInfo('All files obfuscation:');
|
||||
printTimeSumData();
|
||||
endFilesEvent(EventList.ALL_FILES_OBFUSCATION);
|
||||
|
||||
const eventObfuscatedCode = createAndStartEvent(parentEvent, 'write obfuscation name cache');
|
||||
const needToWriteCache = compileToolIsRollUp() && sourceProjectConfig.arkObfuscator && sourceProjectConfig.obfuscationOptions;
|
||||
|
Loading…
Reference in New Issue
Block a user