Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/EIDEProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,7 @@ $(OUT_DIR):

protected abstract create(option: CreateOptions): File;

abstract ExportToKeilProject(): File | undefined;
abstract ExportToKeilProject(saveFile?: File): File | undefined;

static NewProject(workspaceState: vscode.Memento): AbstractProject {
return new EIDEProject(workspaceState);
Expand Down Expand Up @@ -3813,7 +3813,7 @@ class EIDEProject extends AbstractProject {
return baseInfo.workspaceFile;
}

ExportToKeilProject(): File | undefined {
ExportToKeilProject(saveFile?: File): File | undefined {

let keilFile: File;

Expand All @@ -3826,8 +3826,8 @@ class EIDEProject extends AbstractProject {
const keilSuffix = prjConfig.type === 'C51' ? 'uvproj' : 'uvprojx';
const suffixFilter = [new RegExp('\\.' + keilSuffix + '$', 'i')];

// local keil file
const localKeilFile = File.fromArray([this.GetRootDir().path, `${prjConfig.name}.${keilSuffix}`]);
// use user-specified save path, or fall back to project root
const localKeilFile = saveFile ?? File.fromArray([this.GetRootDir().path, `${prjConfig.name}.${keilSuffix}`]);

// get from project root folder
if (localKeilFile.IsFile()) {
Expand Down Expand Up @@ -3860,7 +3860,7 @@ class EIDEProject extends AbstractProject {
halFiles = halFiles.concat(group.files);
} else {
fileGroups.push(<FileGroup>{
name: File.ToUnixPath(<string>rePath).toUpperCase(),
name: File.ToUnixPath(<string>rePath),
files: group.files,
disabled: group.disabled
});
Expand Down Expand Up @@ -3892,10 +3892,13 @@ class EIDEProject extends AbstractProject {
// rm empty file groups for MDK
fileGroups = fileGroups.filter(g => g.files.length > 0);

const outDir = saveFile ? new File(NodePath.dirname(saveFile.path)) : this.GetRootDir();
const outName = saveFile ? saveFile.noSuffixName : localKeilFile.noSuffixName;

// set keil xml
keilParser.SetKeilXml(this, fileGroups, cDevice);
keilParser.SetKeilXml(this, fileGroups, outDir, cDevice);

return keilParser.Save(this.GetRootDir(), localKeilFile.noSuffixName);
return keilParser.Save(outDir, outName);
}

//////////////////////////////// overrride ///////////////////////////////////
Expand Down
23 changes: 21 additions & 2 deletions src/EIDEProjectExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4203,7 +4203,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
}
}

ExportKeilXml(prjItem: ProjTreeItem) {
async ExportKeilXml(prjItem: ProjTreeItem) {
try {
const prj = this.getProjectByTreeItem(prjItem);
if (!prj)
Expand All @@ -4221,7 +4221,26 @@ export class ProjectExplorer implements CustomConfigurationProvider {
return;
}

const xmlFile = prj.ExportToKeilProject();
const prjConfig = prj.GetConfiguration().config;
const keilSuffix = prjConfig.type === 'C51' ? 'uvproj' : 'uvprojx';
const defaultUri = vscode.Uri.file(NodePath.join(prj.GetRootDir().path, `${prjConfig.name}.${keilSuffix}`));

const uri = await vscode.window.showSaveDialog({
defaultUri: defaultUri,
filters: { 'Keil Project': [keilSuffix] }
});
if (!uri) return;

// warn if the chosen save path is on a different drive from the project root;
// in that case, cross-drive paths cannot be made relative and will be written as absolute paths
const saveDrive = NodePath.parse(uri.fsPath).root.toLowerCase();
const prjDrive = NodePath.parse(prj.GetRootDir().path).root.toLowerCase();
if (saveDrive !== prjDrive) {
GlobalEvent.emit('msg', newMessage('Warning',
`导出路径 (${saveDrive}) 与项目根目录 (${prjDrive}) 不在同一驱动器,此行为可能导致移动或复制项目后 Keil 无法正确识别文件。`));
}

const xmlFile = prj.ExportToKeilProject(new File(uri.fsPath));

if (xmlFile) {
GlobalEvent.emit('msg', newMessage('Info', export_keil_xml_ok + prj.toRelativePath(xmlFile.path)));
Expand Down
35 changes: 19 additions & 16 deletions src/KeilXmlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export abstract class KeilParser<T> {

abstract ParseData(): KeilParserResult<T>[];

abstract SetKeilXml(prj: AbstractProject, fileGroups: FileGroup[], deviceInfo?: CurrentDevice): void;
abstract SetKeilXml(prj: AbstractProject, fileGroups: FileGroup[], keilOutputDir: File, deviceInfo?: CurrentDevice): void;
}

//----
Expand Down Expand Up @@ -504,7 +504,7 @@ class C51Parser extends KeilParser<KeilC51Option> {
}
}

SetKeilXml(prj: AbstractProject, fileGroups: FileGroup[], deviceInfo?: CurrentDevice): void {
SetKeilXml(prj: AbstractProject, fileGroups: FileGroup[], keilOutputDir: File, deviceInfo?: CurrentDevice): void {

const prjConfig: ProjectConfiguration<any> = prj.GetConfiguration();
const target = this.doc.Project.Targets.Target[0];
Expand Down Expand Up @@ -534,14 +534,15 @@ class C51Parser extends KeilParser<KeilC51Option> {
target.TargetOption.TargetCommonOption.Device = devName;
target.TargetOption.TargetCommonOption.Vendor = vendor;

const outFolder = File.normalize(prjConfig.config.outDir);
target.TargetOption.TargetCommonOption.OutputDirectory = `.\\${outFolder}\\Keil\\`;
target.TargetOption.TargetCommonOption.ListingPath = `.\\${outFolder}\\Keil\\`;
const outFolderAbs = prj.ToAbsolutePath(prjConfig.config.outDir);
const outFolder = File.ToLocalPath(keilOutputDir.ToRelativePath(outFolderAbs) || outFolderAbs);
target.TargetOption.TargetCommonOption.OutputDirectory = `${outFolder}\\Keil\\`;
target.TargetOption.TargetCommonOption.ListingPath = `${outFolder}\\Keil\\`;
target.TargetOption.TargetCommonOption.OutputName = target.TargetName;

target.TargetOption.Target51.C51.VariousControls.IncludePath = mergedDep.incList
.map(s => prj.resolveEnvVar(s))
.map(inc => File.ToLocalPath(prj.toRelativePath(inc)))
.map(inc => { const abs = File.isAbsolute(inc) ? inc : prj.ToAbsolutePath(inc); return File.ToLocalPath(keilOutputDir.ToRelativePath(abs) || abs); })
.join(';');

target.TargetOption.Target51.C51.VariousControls.Define = mergedDep.defineList.join(",");
Expand All @@ -563,7 +564,7 @@ class C51Parser extends KeilParser<KeilC51Option> {
const fileElement = {
FileName: _f.file.name,
FileType: this.getFileType(_f.file).toString(),
FilePath: prj.ToRelativePath(_f.file.path) || _f.file.path
FilePath: File.ToLocalPath(keilOutputDir.ToRelativePath(_f.file.path) || _f.file.path)
};

this.setFileDisableFlag(fileElement, _f.disabled);
Expand Down Expand Up @@ -1169,7 +1170,7 @@ class ARMParser extends KeilParser<KeilARMOption> {
return result;
}

private setOption(targetOptionObj: any, prj: AbstractProject) {
private setOption(targetOptionObj: any, prj: AbstractProject, keilOutputDir: File) {

const armAdsObj = targetOptionObj.TargetArmAds;
const prjConfig = <ProjectConfiguration<ArmBaseCompileData>>prj.GetConfiguration();
Expand Down Expand Up @@ -1213,7 +1214,7 @@ class ARMParser extends KeilParser<KeilARMOption> {
LDads.umfTarg = config.useCustomScatterFile ? '0' : '1';
if (config.scatterFilePath) {
const absPath = prj.ToAbsolutePath(config.scatterFilePath);
LDads.ScatterFile = this.ToRelativePath(absPath);
LDads.ScatterFile = File.ToLocalPath(keilOutputDir.ToRelativePath(absPath) || absPath);
} else {
LDads.ScatterFile = '';
}
Expand Down Expand Up @@ -1317,7 +1318,7 @@ class ARMParser extends KeilParser<KeilARMOption> {
}
}

SetKeilXml(prj: AbstractProject, fileGroups: FileGroup[], deviceInfo?: CurrentDevice): void {
SetKeilXml(prj: AbstractProject, fileGroups: FileGroup[], keilOutputDir: File, deviceInfo?: CurrentDevice): void {

const prjConfig: ProjectConfiguration<any> = prj.GetConfiguration();
const target = this.doc.Project.Targets.Target[0];
Expand Down Expand Up @@ -1366,17 +1367,19 @@ class ARMParser extends KeilParser<KeilARMOption> {
}

target.TargetName = prjConfig.config.name;
target.uAC6 = prj.getToolchain().name === 'AC6' ? '1' : '0';
target.TargetOption.TargetCommonOption.Device = devName;
target.TargetOption.TargetCommonOption.Vendor = vendor;

const outFolder = File.normalize(prjConfig.config.outDir);
target.TargetOption.TargetCommonOption.OutputDirectory = `.\\${outFolder}\\Keil\\`;
target.TargetOption.TargetCommonOption.ListingPath = `.\\${outFolder}\\Keil\\`;
const outFolderAbs = prj.ToAbsolutePath(prjConfig.config.outDir);
const outFolder = File.ToLocalPath(keilOutputDir.ToRelativePath(outFolderAbs) || outFolderAbs);
target.TargetOption.TargetCommonOption.OutputDirectory = `${outFolder}\\Keil\\`;
target.TargetOption.TargetCommonOption.ListingPath = `${outFolder}\\Keil\\`;
target.TargetOption.TargetCommonOption.OutputName = target.TargetName;

target.TargetOption.TargetArmAds.Cads.VariousControls.IncludePath = mergedDep.incList
.map(s => prj.resolveEnvVar(s))
.map(inc => File.ToLocalPath(prj.toRelativePath(inc)))
.map(inc => { const abs = File.isAbsolute(inc) ? inc : prj.ToAbsolutePath(inc); return File.ToLocalPath(keilOutputDir.ToRelativePath(abs) || abs); })
.join(';');

target.TargetOption.TargetArmAds.Cads.VariousControls.Define = mergedDep.defineList.join(","); // C/CPP
Expand All @@ -1387,7 +1390,7 @@ class ARMParser extends KeilParser<KeilARMOption> {
target.TargetOption.TargetArmAds.Aads.VariousControls.Define = defines.join(","); // ASM
}

this.setOption(target.TargetOption, prj);
this.setOption(target.TargetOption, prj, keilOutputDir);

const nGroups: any[] = [];

Expand All @@ -1404,7 +1407,7 @@ class ARMParser extends KeilParser<KeilARMOption> {
const fileElement = {
FileName: _f.file.name,
FileType: this.getFileType(_f.file).toString(),
FilePath: prj.ToRelativePath(_f.file.path) || _f.file.path
FilePath: File.ToLocalPath(keilOutputDir.ToRelativePath(_f.file.path) || _f.file.path)
};

this.setFileDisableFlag(fileElement, _f.disabled);
Expand Down