Skip to content

Commit a1271cd

Browse files
committed
fix: error convert '${VAR}/../A' -> 'A', use 'File.normalize' replace 'Node.normalize'
1 parent d307b1a commit a1271cd

12 files changed

Lines changed: 60 additions & 58 deletions

lib/node-utility

src/CodeBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export abstract class CodeBuilder {
402402
target: this.project.getCurrentTarget(),
403403
toolchain: toolchain.name,
404404
toolchainLocation: toolchain.getToolchainDir().path,
405-
toolchainCfgFile: NodePath.normalize(`../cfg/${toolchain.modelName}`),
405+
toolchainCfgFile: File.normalize(`../cfg/${toolchain.modelName}`),
406406
buildMode: 'fast|multhread',
407407
showRepathOnLog: settingManager.isPrintRelativePathWhenBuild(),
408408
threadNum: settingManager.getThreadNumber(),

src/DependenceManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class DependenceManager implements ManagerInterface {
6363
Init() {
6464
const rootDir = this.project.GetRootDir();
6565
this.prjType = this.project.GetConfiguration().config.type;
66-
this.depDir = File.fromArray([rootDir.path, NodePath.normalize(DependenceManager.DEPENDENCE_DIR)]);
66+
this.depDir = File.fromArray([rootDir.path, File.normalize(DependenceManager.DEPENDENCE_DIR)]);
6767
this.LoadComponents();
6868
}
6969

src/EIDEProject.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
900900
if (this.isOldVersionProject) {
901901

902902
// rename old 'deps' folder name for old eide version
903-
const depsFolder = File.fromArray([this.GetRootDir().path, NodePath.normalize(DependenceManager.DEPENDENCE_DIR)]);
903+
const depsFolder = File.fromArray([this.GetRootDir().path, File.normalize(DependenceManager.DEPENDENCE_DIR)]);
904904
if (!depsFolder.IsDir()) { // if 'deps' folder is not exist
905905

906906
// these folder is for old eide version
@@ -998,7 +998,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
998998
prjConfig.config.srcDirs = prjConfig.config.srcDirs.filter(p => File.IsDir(p));
999999

10001000
// rm prefix for out dir
1001-
prjConfig.config.outDir = NodePath.normalize(File.ToLocalPath(prjConfig.config.outDir));
1001+
prjConfig.config.outDir = File.normalize(File.ToLocalPath(prjConfig.config.outDir));
10021002

10031003
// use unix path for source path
10041004
if (this.isNewProject || this.isOldVersionProject) {
@@ -1154,8 +1154,8 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
11541154

11551155
ToAbsolutePath(path_: string, resolveEnv: boolean = true): string {
11561156
const path = resolveEnv ? this.replacePathEnv(path_.trim()) : path_.trim();
1157-
if (File.isAbsolute(path)) { return NodePath.normalize(path); }
1158-
return NodePath.normalize(File.ToLocalPath(this.GetRootDir().path + NodePath.sep + path));
1157+
if (File.isAbsolute(path)) { return File.normalize(path); }
1158+
return File.normalize(File.ToLocalPath(this.GetRootDir().path + NodePath.sep + path));
11591159
}
11601160

11611161
/**
@@ -2325,8 +2325,10 @@ class EIDEProject extends AbstractProject {
23252325

23262326
public createBase(option: CreateOptions, createNewPrjFolder: boolean = true): BaseProjectInfo {
23272327

2328-
const rootDir: File = createNewPrjFolder ?
2329-
File.fromArray([option.outDir.path, option.name]) : option.outDir;
2328+
const rootDir: File = createNewPrjFolder
2329+
? File.fromArray([option.outDir.path, option.name])
2330+
: option.outDir;
2331+
23302332
rootDir.CreateDir(true);
23312333

23322334
const wsFile = File.fromArray([rootDir.path, option.name + AbstractProject.workspaceSuffix]);
@@ -2967,7 +2969,7 @@ class EIDEProject extends AbstractProject {
29672969
this.cppToolsConfig.forcedInclude = [];
29682970

29692971
toolchain.getForceIncludeHeaders()?.forEach((f_path) => {
2970-
this.cppToolsConfig.forcedInclude?.push(NodePath.normalize(f_path));
2972+
this.cppToolsConfig.forcedInclude?.push(File.normalize(f_path));
29712973
});
29722974

29732975
SettingManager.GetInstance().getForceIncludeList().forEach((path) => {

src/EIDEProjectExplorer.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
970970
// setting: out folder
971971
iList.push(new ProjTreeItem(TreeItemType.SETTINGS_ITEM, {
972972
key: 'outDir',
973-
value: NodePath.normalize(config.config.outDir),
973+
value: File.normalize(config.config.outDir),
974974
alias: view_str$settings$outFolderName,
975975
tooltip: view_str$settings$outFolderName,
976976
projectIndex: element.val.projectIndex
@@ -1453,24 +1453,11 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
14531453
if (projectnum == 0)
14541454
throw new Error(`Not found any project in this IAR workbench ! [path]: ${option.projectFile.path}`);
14551455

1456-
// store vscode workspace
1457-
const vscWorkspaceFile = File.fromArray([ewwRoot.path, `${ewwInfo.name}.code-workspace`]);
1458-
{
1459-
const vscWorkspace = {
1460-
"folders": <any[]>[]
1461-
};
1462-
1463-
for (const projpath in ewwInfo.projects) {
1464-
const repath = ewwRoot.ToRelativePath(projpath) || projpath;
1465-
const project = ewwInfo.projects[projpath];
1466-
vscWorkspace.folders.push({
1467-
name: project.name,
1468-
path: NodePath.dirname(repath)
1469-
});
1470-
}
1456+
const vscWorkspace = {
1457+
"folders": <any[]>[]
1458+
};
14711459

1472-
fs.writeFileSync(vscWorkspaceFile.path, JSON.stringify(vscWorkspace, undefined, 4));
1473-
}
1460+
const vscWorkspaceFile = File.fromArray([ewwRoot.path, `${ewwInfo.name}.code-workspace`]);
14741461

14751462
const toolchainType: ToolchainName = 'IAR_ARM';
14761463

@@ -1479,23 +1466,30 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
14791466
for (const path_ in ewwInfo.projects) {
14801467

14811468
const iarproj = ewwInfo.projects[path_];
1482-
const prjRoot = new File(NodePath.dirname(path_));
1483-
const createNewDir = NodePath.normalize(prjRoot.path) == NodePath.normalize(ewwRoot.path);
1469+
const iarPrjRoot = new File(NodePath.dirname(path_));
14841470

1471+
const needCreateNewDir = File.normalize(iarPrjRoot.path) == File.normalize(ewwRoot.path);
14851472
const basePrj = AbstractProject.NewProject().createBase({
14861473
name: iarproj.name,
14871474
projectName: iarproj.name,
14881475
type: 'ARM',
1489-
outDir: prjRoot
1490-
}, createNewDir);
1476+
outDir: iarPrjRoot
1477+
}, needCreateNewDir);
1478+
1479+
const prjRoot = basePrj.rootFolder;
1480+
1481+
vscWorkspace.folders.push({
1482+
name: iarproj.name,
1483+
path: ewwRoot.ToRelativePath(prjRoot.path) || prjRoot.path
1484+
});
14911485

14921486
if (!project0workspacefile)
14931487
project0workspacefile = basePrj.workspaceFile;
14941488

14951489
const eidePrjCfg = basePrj.prjConfig.config;
14961490
const eideFolder = File.fromArray([prjRoot.path, AbstractProject.EIDE_DIR]);
14971491

1498-
// set project env
1492+
// export project env
14991493
{
15001494
const envFile = File.fromArray([eideFolder.path, 'env.ini']);
15011495
const envCont = [
@@ -1504,9 +1498,13 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
15041498
`###########################################################`,
15051499
``,
15061500
];
1501+
1502+
iarproj.envs['PROJ_DIR'] = needCreateNewDir ? '..' : '.';
1503+
15071504
for (const key in iarproj.envs) {
15081505
envCont.push(`${key} = ${iarproj.envs[key]}`);
15091506
}
1507+
15101508
envFile.Write(envCont.join(os.EOL));
15111509
}
15121510

@@ -1702,11 +1700,14 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
17021700
basePrj.prjConfig.Save();
17031701
}
17041702

1703+
// store vscode workspace
1704+
fs.writeFileSync(vscWorkspaceFile.path, JSON.stringify(vscWorkspace, undefined, 4));
1705+
17051706
// switch project
17061707
const selection = await vscode.window.showInformationMessage(
17071708
view_str$operation$import_done, continue_text, cancel_text);
17081709
if (selection === continue_text) {
1709-
WorkspaceManager.getInstance().openWorkspace(projectnum > 1
1710+
WorkspaceManager.getInstance().openWorkspace(vscWorkspace.folders.length > 1
17101711
? vscWorkspaceFile
17111712
: project0workspacefile);
17121713
}
@@ -3494,7 +3495,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
34943495
rootDir = prj.GetRootDir();
34953496
templateName = prjConfig.name;
34963497
tmp_suffix = 'ept';
3497-
const prjOutFolder = NodePath.normalize(prj.GetConfiguration().config.outDir);
3498+
const prjOutFolder = File.normalize(prj.GetConfiguration().config.outDir);
34983499
defExcludeList.push(`${prjOutFolder}`, `${prjOutFolder}${File.sep}*`);
34993500
resIgnoreList = prj.readIgnoreList();
35003501
const prjUid = prjConfig.miscInfo.uid;
@@ -4167,7 +4168,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
41674168
}
41684169

41694170
cppcheckConf = cppcheckConf
4170-
.replace('${cppcheck_build_folder}', NodePath.normalize(prj.getOutputRoot()))
4171+
.replace('${cppcheck_build_folder}', File.normalize(prj.getOutputRoot()))
41714172
.replace('${platform}', cppcheck_plat)
41724173
.replace('${lib_list}', cfgList.map((str) => `<library>${str}</library>`).join(os.EOL + '\t\t'))
41734174
.replace('${include_list}', includeList.map((str) => `<dir name="${str}/"/>`).join(os.EOL + '\t\t'))
@@ -4396,7 +4397,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
43964397
case 'outDir':
43974398
{
43984399
const prjConfig = prj.GetConfiguration().config;
4399-
const oldFolderName = NodePath.normalize(prjConfig.outDir);
4400+
const oldFolderName = File.normalize(prjConfig.outDir);
44004401

44014402
const newName = await vscode.window.showInputBox({
44024403
value: oldFolderName,
@@ -4972,7 +4973,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
49724973
let file: File | undefined;
49734974

49744975
if (item.val.value instanceof File) { // if value is a file, use it
4975-
file = new File(NodePath.normalize(item.val.value.path));
4976+
file = new File(File.normalize(item.val.value.path));
49764977
}
49774978

49784979
if (file) {

src/EIDEProjectModules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ class OpenOCDUploadModel extends UploadConfigModel<OpenOCDFlashOptions> {
23962396

23972397
// find in build-in path
23982398
for (const path of this.configSearchList['build-in']) {
2399-
const cfgFolder = new File(NodePath.normalize(`${NodePath.dirname(openocdExe.dir)}/${path}/${configClass}`));
2399+
const cfgFolder = new File(File.normalize(`${NodePath.dirname(openocdExe.dir)}/${path}/${configClass}`));
24002400
if (cfgFolder.IsDir()) {
24012401
cfgFolder.GetAll([/\.cfg$/i], File.EMPTY_FILTER).forEach((file) => {
24022402
const rePath = (cfgFolder.ToRelativePath(file.path) || file.name);

src/EIDETypeDefine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ export class ProjectConfiguration<T extends BuilderConfigData>
441441

442442
private toAbsolutePath(path_: string): string {
443443
const path = path_.trim();
444-
if (File.isAbsolute(path)) { return NodePath.normalize(path); }
445-
return NodePath.normalize(File.ToLocalPath(this.getRootDir().path + File.sep + path));
444+
if (File.isAbsolute(path)) { return File.normalize(path); }
445+
return File.normalize(File.ToLocalPath(this.getRootDir().path + File.sep + path));
446446
}
447447

448448
private toRelativePath(path_: string): string {

src/IarProjectParser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ function tryGetIarChipInfo(iarToolRoot: File, rawChipNameStr: string): { [key: s
303303
export function formatEnvNameAndPathSep(str: string): string {
304304
return str.replace(/\\/g, '/')
305305
.replace(/\/$/, '')
306-
.replace(/\$PROJ_DIR\$\//g, '')
307306
.replace(/\$TOOLKIT_DIR\$/g, '${ToolchainRoot}')
308307
.replace(/\$(\w+)\$/g, '$${$1}');
309308
}

src/KeilXmlParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export abstract class KeilParser<T> {
182182
if (File.isAbsolute(path)) {
183183
return path.replace(/\//g, '\\');
184184
} else {
185-
return NodePath.normalize(this._file.dir + File.sep + path);
185+
return File.normalize(this._file.dir + File.sep + path);
186186
}
187187
}
188188

@@ -492,7 +492,7 @@ class C51Parser extends KeilParser<KeilC51Option> {
492492
target.TargetOption.TargetCommonOption.Device = devName;
493493
target.TargetOption.TargetCommonOption.Vendor = vendor;
494494

495-
const outFolder = NodePath.normalize(prjConfig.config.outDir);
495+
const outFolder = File.normalize(prjConfig.config.outDir);
496496
target.TargetOption.TargetCommonOption.OutputDirectory = `.\\${outFolder}\\Keil\\`;
497497
target.TargetOption.TargetCommonOption.ListingPath = `.\\${outFolder}\\Keil\\`;
498498
target.TargetOption.TargetCommonOption.OutputName = target.TargetName;
@@ -1077,7 +1077,7 @@ class ARMParser extends KeilParser<KeilARMOption> {
10771077
target.TargetOption.TargetCommonOption.Device = devName;
10781078
target.TargetOption.TargetCommonOption.Vendor = vendor;
10791079

1080-
const outFolder = NodePath.normalize(prjConfig.config.outDir);
1080+
const outFolder = File.normalize(prjConfig.config.outDir);
10811081
target.TargetOption.TargetCommonOption.OutputDirectory = `.\\${outFolder}\\Keil\\`;
10821082
target.TargetOption.TargetCommonOption.ListingPath = `.\\${outFolder}\\Keil\\`;
10831083
target.TargetOption.TargetCommonOption.OutputName = target.TargetName;

src/ResInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class ResInstaller {
194194
const instDir = File.fromArray([ResManager.GetInstance().getUtilToolsDir(), tool.resource_name]);
195195
if (instDir.IsDir()) {
196196
if (tool.require_name) {
197-
const p = NodePath.normalize(instDir.path + File.sep + tool.require_name);
197+
const p = File.normalize(instDir.path + File.sep + tool.require_name);
198198
return File.IsExist(p);
199199
} else {
200200
return true;

0 commit comments

Comments
 (0)