Skip to content

Commit 419b759

Browse files
committed
变更 unify_builder 位置,到插件安装目录
1 parent d5b3e3a commit 419b759

File tree

4 files changed

+64
-56
lines changed

4 files changed

+64
-56
lines changed

src/CodeBuilder.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export abstract class CodeBuilder {
323323

324324
// generate command line
325325
const commandLine = CmdLineHandler.getCommandLine(
326-
this.getBuilderExe().noSuffixName,
326+
ResManager.instance().getUnifyBuilderExe().noSuffixName,
327327
this.getCommands()
328328
);
329329

@@ -567,10 +567,6 @@ export abstract class CodeBuilder {
567567
return cmds;
568568
}
569569

570-
private getBuilderExe(): File {
571-
return ResManager.GetInstance().getBuilder();
572-
}
573-
574570
protected abstract getMcuMemorySize(): MemorySize | undefined;
575571

576572
protected abstract preHandleOptions(options: ICompileOptions): void;

src/EIDEProjectExplorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4314,7 +4314,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
43144314
paramsFile.Write(JSON.stringify(cmdList));
43154315

43164316
/* launch */
4317-
const exeName = ResManager.GetInstance().getBuilder().noSuffixName;
4317+
const exeName = ResManager.GetInstance().getUnifyBuilderExe().noSuffixName;
43184318
const commandLine = CmdLineHandler.getCommandLine(exeName, ['-r', paramsFile.path]);
43194319
runShellCommand('build workspace', commandLine);
43204320
}

src/ResManager.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import { File } from "../lib/node-utility/File";
2626
import { WorkspaceManager } from "./WorkspaceManager";
2727
import { GlobalEvent } from "./GlobalEvents";
28-
import { exeSuffix, GetLocalCodePage, osType } from "./Platform";
28+
import { exeSuffix, GetLocalCodePage, osType, getArchId } from "./Platform";
2929
import { ExceptionToMessage } from "./Message";
3030

3131
import * as ChildProcess from 'child_process';
@@ -429,30 +429,33 @@ export class ResManager extends events.EventEmitter {
429429

430430
/* ------------------ builder and runtime ----------------- */
431431

432-
getBuilderDir(): File {
432+
getLegacyBuilderDir(): File {
433433
return <File>this.GetDir('builder');
434434
}
435435

436436
getMsysBash(): File | undefined {
437437
if (os.platform() == 'win32') {
438-
return File.fromArray([this.getBuilderDir().path, 'msys', 'bin', `bash${exeSuffix()}`]);
438+
return File.fromArray([this.getLegacyBuilderDir().path, 'msys', 'bin', `bash${exeSuffix()}`]);
439439
}
440440
}
441441

442442
getMsysBinToolPath(toolname: string): string {
443443
if (os.platform() == 'win32') {
444-
return File.fromArray([this.getBuilderDir().path, 'msys', 'bin', `${toolname}${exeSuffix()}`]).path;
444+
return File.fromArray([this.getLegacyBuilderDir().path, 'msys', 'bin', `${toolname}${exeSuffix()}`]).path;
445445
} else {
446446
return `${toolname}${exeSuffix()}`;
447447
}
448448
}
449449

450-
getBuilder(): File {
451-
return File.fromArray([this.getBuilderDir().path, 'bin', `unify_builder${exeSuffix()}`]);
450+
getUnifyBuilderExe(): File {
451+
let dirname = 'unify_builder';
452+
if (osType() == 'darwin')
453+
dirname += File.sep + getArchId();
454+
return File.fromArray([this.getBuiltInToolsDir().path, dirname, `unify_builder${exeSuffix()}`]);
452455
}
453456

454457
getSerialPortExe(): File {
455-
return File.fromArray([this.getBuilderDir().path, 'bin', `serial_monitor${exeSuffix()}`]);
458+
return File.fromArray([this.getUnifyBuilderExe().dir, `serial_monitor${exeSuffix()}`]);
456459
}
457460

458461
getBuilderModelsDir(plat?: 'win32' | 'unix'): File {

src/extension.ts

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ async function newClangFormatFile() {
378378

379379
function checkBinFolder(binFolder: File): boolean {
380380
return binFolder.IsDir() &&
381-
File.fromArray([binFolder.path, File.ToLocalPath(`builder/bin/unify_builder${platform.exeSuffix()}`)]).IsFile();
381+
File.fromArray([binFolder.path, 'VERSION']).IsFile();
382382
}
383383

384384
async function checkAndInstallBinaries(forceInstall?: boolean): Promise<boolean> {
@@ -678,14 +678,57 @@ async function tryInstallBinaries(binFolder: File, binVersion: string): Promise<
678678
platform.DeleteDir(binFolder);
679679
}
680680

681-
// chmod executable's permission
682681
if (installedDone) {
683-
initBinariesExecutablePermission();
682+
onBinariesInstallDone();
684683
}
685684

686685
return installedDone;
687686
}
688687

688+
function onBinariesInstallDone() {
689+
690+
const resManager = ResManager.GetInstance();
691+
692+
// chmod +x for other executable files
693+
if (os.platform() != 'win32') {
694+
695+
const exeLi: string[] = [];
696+
697+
// get exe file list from folders
698+
for (const dir of [
699+
File.fromArray([resManager.GetBinDir().path, 'scripts']),
700+
File.fromArray([resManager.getLegacyBuilderDir().path, 'utils']),
701+
File.fromArray([resManager.getUnifyBuilderExe().dir])
702+
]) {
703+
dir.GetList(undefined, File.EXCLUDE_ALL_FILTER)
704+
.forEach((f) => {
705+
if (!f.suffix) { // nosuffix file is an exe file
706+
exeLi.push(f.path);
707+
}
708+
});
709+
}
710+
711+
for (const path of exeLi) {
712+
try {
713+
ChildProcess.execSync(`chmod +x "${path}"`);
714+
GlobalEvent.emit('globalLog', newMessage('Info', `chmod +x "${path}"`));
715+
} catch (error) {
716+
GlobalEvent.emit('globalLog', ExceptionToMessage(error, 'Error'));
717+
}
718+
}
719+
}
720+
721+
// delete legacy builder dir
722+
const legacyDir = File.fromArray([resManager.getLegacyBuilderDir().path, 'bin']);
723+
if (legacyDir.IsDir()) {
724+
platform.DeleteAllChildren(legacyDir);
725+
fs.writeFileSync(legacyDir.path + '/' + 'NOTICE.TXT',
726+
[`unify_builder has been moved to '${resManager.getUnifyBuilderExe().dir}, this folder is deprecated'`,
727+
`---`,
728+
`unify_builder 的位置已被转移到 '${resManager.getUnifyBuilderExe().dir}',该位置已被弃用`].join(os.EOL));
729+
}
730+
}
731+
689732
//////////////////////////////////////////////////
690733
// environment sutup
691734
//////////////////////////////////////////////////
@@ -696,13 +739,13 @@ function exportEnvToSysPath(context?: vscode.ExtensionContext) {
696739

697740
const settingManager = SettingManager.GetInstance();
698741
const resManager = ResManager.GetInstance();
699-
const builderFolder = resManager.getBuilderDir();
742+
const legacyBuilderDir = resManager.getLegacyBuilderDir();
700743

701744
// export some eide binaries path to system env path
702745
const systemEnvPaths: string[] = [
703-
File.normalize(`${builderFolder.path}/bin`), // builder bin folder
704-
File.normalize(`${builderFolder.path}/utils`), // utils tool folder
705-
File.normalize(`${builderFolder.dir}/scripts`),
746+
File.normalize(`${resManager.getUnifyBuilderExe().dir}`),
747+
File.normalize(`${legacyBuilderDir.path}/utils`), // utils tool folder
748+
File.normalize(`${legacyBuilderDir.dir}/scripts`),
706749
File.normalize(`${resManager.Get7zDir().path}`), // export built-in 7za tool
707750
File.normalize(`${resManager.getBuiltInToolsDir().path}/utils`) // builtin utils tool folder
708751
];
@@ -780,7 +823,7 @@ function exportEnvToSysPath(context?: vscode.ExtensionContext) {
780823
});
781824

782825
// search built-in tools and export path to system env
783-
builderFolder.GetList(File.EXCLUDE_ALL_FILTER).forEach((subDir) => {
826+
legacyBuilderDir.GetList(File.EXCLUDE_ALL_FILTER).forEach((subDir) => {
784827
const binFolder = File.normalize(`${subDir.path}/bin`);
785828
if (File.IsDir(binFolder)) {
786829
pathList.push({
@@ -965,40 +1008,6 @@ async function checkAndInstallRuntime() {
9651008
}
9661009
}
9671010

968-
function initBinariesExecutablePermission() {
969-
970-
const resManager = ResManager.GetInstance();
971-
972-
// chmod +x for other executable files
973-
if (os.platform() != 'win32') {
974-
975-
const exeLi: string[] = [];
976-
977-
// get exe file list from folders
978-
for (const dir of [
979-
File.fromArray([resManager.GetBinDir().path, 'scripts']),
980-
File.fromArray([resManager.getBuilderDir().path, 'utils']),
981-
File.fromArray([resManager.getBuilderDir().path, 'bin'])
982-
]) {
983-
dir.GetList(undefined, File.EXCLUDE_ALL_FILTER)
984-
.forEach((f) => {
985-
if (!f.suffix) { // nosuffix file is an exe file
986-
exeLi.push(f.path);
987-
}
988-
});
989-
}
990-
991-
for (const path of exeLi) {
992-
try {
993-
ChildProcess.execSync(`chmod +x "${path}"`);
994-
GlobalEvent.emit('globalLog', newMessage('Info', `chmod +x "${path}"`));
995-
} catch (error) {
996-
GlobalEvent.emit('globalLog', ExceptionToMessage(error, 'Error'));
997-
}
998-
}
999-
}
1000-
}
1001-
10021011
async function InitComponents(context: vscode.ExtensionContext): Promise<boolean | undefined> {
10031012

10041013
// init managers
@@ -1610,7 +1619,7 @@ class MapViewEditorProvider implements vscode.CustomTextEditorProvider {
16101619
.execSync(`memap -t ${memapTyp} -d ${vInfo.treeDepth} "${vInfo.mapPath}"`)
16111620
.toString().split(/\r\n|\n/);
16121621
} else {
1613-
const memapRoot = ResManager.GetInstance().getBuilderDir().path + File.sep + 'utils';
1622+
const memapRoot = ResManager.GetInstance().getLegacyBuilderDir().path + File.sep + 'utils';
16141623
const command = `python memap -t ${memapTyp} -d ${vInfo.treeDepth} "${vInfo.mapPath}"`;
16151624
lines = ChildProcess
16161625
.execSync(command, { cwd: memapRoot })

0 commit comments

Comments
 (0)