Skip to content

Commit d88bfcb

Browse files
committed
Add baseOptions to compiler props
Added as a way to help with compiler-explorer#1899
1 parent ed71f67 commit d88bfcb

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

Diff for: lib/compiler-finder.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,26 @@ class CompilerFinder {
156156
}
157157

158158
const ceToolsPath = props("ceToolsPath", "./");
159+
159160
const supportsBinary = !!props("supportsBinary", true);
160161
const supportsExecute = supportsBinary && !!props("supportsExecute", true);
161162
const supportsLibraryCodeFilter = !!props("supportsLibraryCodeFilter", true);
163+
162164
const group = props("group", "");
165+
163166
const demanglerProp = props("demangler", "");
164167
const demangler = demanglerProp ? path.normalize(demanglerProp.replace("${ceToolsPath}", ceToolsPath)) : "";
168+
165169
const isSemVer = props("isSemVer", false);
166170
const baseName = props("baseName", null);
167171
const semverVer = props("semver", "");
172+
168173
const name = props("name", compilerName);
174+
175+
const baseOptions = props("baseOptions", "");
176+
const options = props("options", "");
177+
let actualOptions = _.compact([baseOptions, options]).join(' ');
178+
169179
const envVars = (() => {
170180
const envVarsString = props("envVars", "");
171181
if (envVarsString === "") {
@@ -185,7 +195,7 @@ class CompilerFinder {
185195
exe: exe,
186196
name: isSemVer && baseName ? `${baseName} ${semverVer}` : name,
187197
alias: _.filter(props("alias", "").split(":"), (a) => a !== ""),
188-
options: props("options"),
198+
options: actualOptions,
189199
versionFlag: props("versionFlag"),
190200
versionRe: props("versionRe"),
191201
compilerType: props("compilerType", ""),

Diff for: test/compiler-finder-tests.js

+62-4
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,81 @@ const props = {
4040
compilers: "goodCompiler:&badCompiler"
4141
};
4242

43+
const noOptionsAtAll = {
44+
compilers: "goodCompiler"
45+
};
46+
47+
const noBaseOptions = {
48+
compilers: "goodCompiler",
49+
options: "bar"
50+
};
51+
52+
const onlyBaseOptions = {
53+
compilers: "goodCompiler",
54+
baseOptions: "foo"
55+
};
56+
57+
const bothOptions = {
58+
compilers: "goodCompiler",
59+
baseOptions: "foo",
60+
options: "bar"
61+
};
62+
4363
describe('Compiler-finder', function () {
4464
let compilerProps;
4565

66+
let noOptionsAtAllProps;
67+
let noBaseOptionsProps;
68+
let onlyBaseOptionsProps;
69+
let bothOptionsProps;
70+
71+
let optionsHandler;
72+
4673
before(() => {
4774
compilerProps = new properties.CompilerProps(languages, properties.fakeProps(props));
48-
});
4975

50-
it('should not hang for undefined groups (Bug #860)', () => {
51-
const optionsHandler = {
76+
noOptionsAtAllProps = new properties.CompilerProps(languages, properties.fakeProps(noOptionsAtAll));
77+
noBaseOptionsProps = new properties.CompilerProps(languages, properties.fakeProps(noBaseOptions));
78+
onlyBaseOptionsProps = new properties.CompilerProps(languages, properties.fakeProps(onlyBaseOptions));
79+
bothOptionsProps = new properties.CompilerProps(languages, properties.fakeProps(bothOptions));
80+
81+
optionsHandler = {
5282
get: () => {
5383
return {
5484
libs: {},
5585
tools: {}
5686
};
5787
}
5888
};
89+
});
90+
91+
it('should not hang for undefined groups (Bug #860)', () => {
92+
5993
const finder = new CompilerFinder({}, compilerProps, properties.fakeProps({}), {}, optionsHandler);
6094
return finder.getCompilers().should.eventually.have.lengthOf(2);
61-
})
95+
});
96+
97+
it('should behave properly if no options are provided at all', async () => {
98+
const finder = new CompilerFinder({}, noOptionsAtAllProps, properties.fakeProps({}), {}, optionsHandler);
99+
const compilers = await finder.getCompilers();
100+
compilers[0].options.should.equal('');
101+
});
102+
103+
it('should behave properly if no base options are provided', async () => {
104+
const finder = new CompilerFinder({}, noBaseOptionsProps, properties.fakeProps({}), {}, optionsHandler);
105+
const compilers = await finder.getCompilers();
106+
compilers[0].options.should.equal('bar');
107+
});
108+
109+
it('should behave properly if only base options are provided', async () => {
110+
const finder = new CompilerFinder({}, onlyBaseOptionsProps, properties.fakeProps({}), {}, optionsHandler);
111+
const compilers = await finder.getCompilers();
112+
compilers[0].options.should.equal('foo');
113+
});
114+
115+
it('should behave properly if both options are provided', async () => {
116+
const finder = new CompilerFinder({}, bothOptionsProps, properties.fakeProps({}), {}, optionsHandler);
117+
const compilers = await finder.getCompilers();
118+
compilers[0].options.should.equal('foo bar');
119+
});
62120
});

0 commit comments

Comments
 (0)