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