Fixed failed compilation of projects that depend on external har

Issue: #IAESVY

Signed-off-by: wuhailong <wuhailong22@huawei.com>
Change-Id: I61672653d424f718a4bcf1f3fe11434d033c830b
This commit is contained in:
wuhailong 2024-07-22 22:10:22 +08:00
parent b7f015f8a8
commit 4b87649ad0
3 changed files with 17 additions and 8 deletions

View File

@ -737,9 +737,16 @@ export class ModuleMode extends CommonMode {
}
private genFileCachePath(filePath: string, projectRootPath: string, cachePath: string, metaInfo: Object): string {
const sufStr: string = toUnixPath(filePath).startsWith(toUnixPath(projectRootPath)) ?
toUnixPath(filePath).replace(toUnixPath(projectRootPath) + '/', '') :
toUnixPath(filePath).replace(toUnixPath(metaInfo.belongProjectPath) + '/', '');
filePath = toUnixPath(filePath);
let sufStr: string = '';
// Only the files of the third-party package will not have the belongProjectPath field in metaInfo.
// If both branches are not satisfied, the compilation process will not go here,
// and an error will be reported when the cache file is written to the disk(in the genTemporaryPath method).
if (metaInfo && metaInfo.belongProjectPath) {
sufStr = filePath.replace(toUnixPath(metaInfo.belongProjectPath) + '/', '');
} else if (filePath.startsWith(toUnixPath(projectRootPath))) {
sufStr = filePath.replace(toUnixPath(projectRootPath) + '/', '');
}
const output: string = path.join(cachePath, sufStr);
return output;
}

View File

@ -346,10 +346,11 @@ export function genTemporaryPath(filePath: string, projectPath: string, buildPat
const reset: string = '\u001b[39m';
projectRootPath = toUnixPath(buildInHar ? projectPath : projectRootPath);
let relativeFilePath: string = '';
if (filePath.startsWith(projectRootPath)) {
relativeFilePath = filePath.replace(projectRootPath, '');
} else if (metaInfo && metaInfo.belongProjectPath) {
// Only the files of the third-party package will not have the belongProjectPath field in metaInfo.
if (metaInfo && metaInfo.belongProjectPath) {
relativeFilePath = filePath.replace(toUnixPath(metaInfo.belongProjectPath), '');
} else if (filePath.startsWith(projectRootPath)) {
relativeFilePath = filePath.replace(projectRootPath, '');
} else {
logger.error(red, 'ARKTS:INTERNAL ERROR\n' +
`Error Message: Failed to generate the cache path corresponding to file ${filePath}.\n` +

View File

@ -15,7 +15,8 @@
import {
MODULE_ID_ROLLUP_PLACEHOLDER,
PROJECT_ROOT
PROJECT_ROOT,
DEFAULT_PROJECT
} from '../rollup_mock/path_config';
class Meta {
@ -36,7 +37,7 @@ class Meta {
this.isNodeEntryFile = false;
this.pkgPath = modulePath;
this.dependencyPkgInfo = undefined;
this.belongProjectPath = PROJECT_ROOT;
this.belongProjectPath = `${PROJECT_ROOT}/${DEFAULT_PROJECT}`;
}
};