Skip to content

Commit cd09672

Browse files
committed
new file option: 'Always In Build'
1 parent b2c04f3 commit cd09672

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

src/CodeBuilder.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface BuilderParams {
9292
sha?: { [options_name: string]: string };
9393
env?: { [name: string]: any };
9494
sysPaths?: string[];
95+
alwaysInBuildSources?: string[];
9596
}
9697

9798
export interface CompilerCommandsDatabaseItem {
@@ -130,11 +131,13 @@ export abstract class CodeBuilder {
130131

131132
protected genSourceInfo(): {
132133
sources: string[],
133-
params?: { [name: string]: string; }
134+
params?: { [name: string]: string; },
135+
alwaysBuildSourceFiles?: string[]
134136
} {
135137

136138
const srcParams: { [name: string]: string; } = {};
137139
const srcList: { path: string, virtualPath?: string; }[] = this.project.getAllSources();
140+
const alwaysBuildSourceFiles: string[] = [];
138141

139142
// append user options for files
140143
try {
@@ -175,6 +178,14 @@ export abstract class CodeBuilder {
175178
const parttenInfo = options?.files;
176179
matcher(parttenInfo, 'path');
177180
}
181+
182+
if (Array.isArray(options.alwaysBuildSourceFiles)) {
183+
options.alwaysBuildSourceFiles.forEach((srcPath) => {
184+
if (srcList.findIndex((inf) => this.project.comparePath(inf.path, srcPath)) != -1) {
185+
alwaysBuildSourceFiles.push(srcPath);
186+
}
187+
});
188+
}
178189
}
179190

180191
} catch (err) {
@@ -184,7 +195,8 @@ export abstract class CodeBuilder {
184195

185196
return {
186197
sources: srcList.map((inf) => inf.path),
187-
params: srcParams
198+
params: srcParams,
199+
alwaysBuildSourceFiles
188200
}
189201
}
190202

@@ -384,6 +396,7 @@ export abstract class CodeBuilder {
384396
libDirs: this.getLibDirs().map(p => this.project.toRelativePath(p)),
385397
defines: this.getProjectCMacroList(),
386398
sourceList: sourceInfo.sources.sort(),
399+
alwaysInBuildSources: sourceInfo.alwaysBuildSourceFiles,
387400
sourceParams: sourceInfo.params,
388401
options: JSON.parse(JSON.stringify(compileOptions)),
389402
env: this.project.getProjectVariables(),

src/EIDEProject.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ export interface BaseProjectInfo {
782782
export interface SourceExtraCompilerOptionsCfg {
783783
files?: { [key: string]: string };
784784
virtualPathFiles?: { [key: string]: string };
785+
alwaysBuildSourceFiles?: string[];
785786
}
786787

787788
export interface SourceFileOptions {
@@ -916,6 +917,19 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
916917
return this.replacePathEnv(p);
917918
}
918919

920+
public comparePath(path1: string, path2: string): boolean {
921+
const abs1 = this.toAbsolutePath(path1);
922+
const abs2 = this.toAbsolutePath(path2);
923+
// windows 上盘符可能不区分大小写,因此需比较相对路径
924+
if (platform.osType() == 'win32') {
925+
const repath1 = this.toRelativePath(abs1);
926+
const repath2 = this.toRelativePath(abs2);
927+
return repath1 === repath2;
928+
} else {
929+
return abs1 === abs2;
930+
}
931+
}
932+
919933
public registerBuiltinVar(key: string, func: () => string) {
920934
this.builtinEnvVars[key] = func;
921935
}
@@ -2297,6 +2311,13 @@ $(OUT_DIR):
22972311
}
22982312
}
22992313

2314+
if (cfg.alwaysBuildSourceFiles) {
2315+
const idx = cfg.alwaysBuildSourceFiles.findIndex(p => this.comparePath(p, fspath));
2316+
if (idx !== -1) {
2317+
return true;
2318+
}
2319+
}
2320+
23002321
return false;
23012322
}
23022323

src/EIDEProjectExplorer.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5399,6 +5399,20 @@ export class ProjectExplorer implements CustomConfigurationProvider {
53995399
},
54005400
};
54015401

5402+
let isAlwaysInBuild = false;
5403+
if (extraArgs.alwaysBuildSourceFiles)
5404+
isAlwaysInBuild = extraArgs.alwaysBuildSourceFiles
5405+
.findIndex(p => project.comparePath(p, <string>fspath)) !== -1;
5406+
ui_cfg.items['always_in_build'] = {
5407+
type: 'bool',
5408+
attrs: {},
5409+
name: 'Always In Build',
5410+
data: <SimpleUIConfigData_boolean>{
5411+
value: isAlwaysInBuild,
5412+
default: isAlwaysInBuild,
5413+
}
5414+
};
5415+
54025416
try {
54035417
const db = project.getSourceCompileDatabase(fspath);
54045418
if (db) {
@@ -5431,21 +5445,35 @@ export class ProjectExplorer implements CustomConfigurationProvider {
54315445
}
54325446

54335447
let category: string = 'files';
5434-
let argsConf: any = extraArgs;
5448+
let fileOptions: any = extraArgs;
54355449

54365450
if (virtpath) {
54375451
category = 'virtualPathFiles';
54385452
}
54395453

5440-
if (!argsConf[category])
5441-
argsConf[category] = {};
5454+
if (!fileOptions[category])
5455+
fileOptions[category] = {};
54425456

54435457
if (nArgs) {
5444-
argsConf[category][pattern] = nArgs;
5458+
fileOptions[category][pattern] = nArgs;
5459+
} else {
5460+
if (fileOptions[category][pattern] != undefined)
5461+
delete fileOptions[category][pattern];
5462+
}
5463+
5464+
// option: always in build
5465+
const isAlwaysInBuild = (<SimpleUIConfigData_boolean>new_cfg.items['always_in_build'].data).value;
5466+
let alwaysBuildSourceFiles: string[] = fileOptions.alwaysBuildSourceFiles || [];
5467+
if (isAlwaysInBuild) {
5468+
alwaysBuildSourceFiles.push(<string>fspath);
54455469
} else {
5446-
if (argsConf[category][pattern] != undefined)
5447-
delete argsConf[category][pattern];
5470+
const idx = alwaysBuildSourceFiles.findIndex(p => project.comparePath(p, <string>fspath));
5471+
if (idx !== -1) {
5472+
alwaysBuildSourceFiles.splice(idx, 1);
5473+
}
54485474
}
5475+
alwaysBuildSourceFiles = ArrayDelRepetition(alwaysBuildSourceFiles);
5476+
fileOptions.alwaysBuildSourceFiles = alwaysBuildSourceFiles.length > 0 ? alwaysBuildSourceFiles : undefined;
54495477

54505478
project.setSourceExtraArgsCfg(extraArgs);
54515479
project.onSourceCompilerOptionsChanged();

0 commit comments

Comments
 (0)