From 340d63a01ccd6ceccab0be54099d0ea271b0afa2 Mon Sep 17 00:00:00 2001 From: Partouf Date: Fri, 12 Jul 2019 14:34:38 +0200 Subject: [PATCH 1/9] splitter change for win32 --- lib/options-handler.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/options-handler.js b/lib/options-handler.js index 5a6d28d1f..6395afa82 100644 --- a/lib/options-handler.js +++ b/lib/options-handler.js @@ -168,7 +168,9 @@ class ClientOptionsHandler { this.compilerProps(lang, libVersionName + '.version'); const includes = this.compilerProps(lang, libVersionName + '.path'); libraries[lang][lib].versions[version].path = []; - if (includes) { + if (includes && (process.platform === "win32")) { + libraries[lang][lib].versions[version].path = includes.split(';'); + } else if (includes) { libraries[lang][lib].versions[version].path = includes.split(':'); } else { logger.warn(`Library ${lib} ${version} (${lang}) has no include paths`); From d5694bbea7ad12cfd400c93923c3fa8263c288a2 Mon Sep 17 00:00:00 2001 From: Partouf Date: Fri, 12 Jul 2019 14:40:06 +0200 Subject: [PATCH 2/9] test fix win32 --- test/options-handler.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/options-handler.js b/test/options-handler.js index 3910b6d62..6307567e1 100644 --- a/test/options-handler.js +++ b/test/options-handler.js @@ -51,6 +51,10 @@ const libProps = { 'libs.fakelib.versions.noPaths.path': '' }; +if (process.platform === "win32") { + libProps['libs.fakelib.versions.twoPaths.path'] = '/dev/null;/dev/urandom'; +} + const compilerProps = new properties.CompilerProps(languages, properties.fakeProps(libProps)); const optionsHandler = new OptionsHandler([], compilerProps, {}); From 6e9c5c8dbc96cc04e79272edadbce5df60647909 Mon Sep 17 00:00:00 2001 From: Partouf Date: Fri, 12 Jul 2019 14:40:45 +0200 Subject: [PATCH 3/9] add libraries option to compile api --- lib/base-compiler.js | 39 +++++++++++++++++++++++++++++++-------- lib/handlers/compile.js | 8 +++++--- static/libs-widget.js | 6 +++--- static/panes/compiler.js | 11 +++++++---- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 082dfd3f6..3a122529d 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -203,7 +203,27 @@ class BaseCompiler { return options; } - prepareArguments(userOptions, filters, backendOptions, inputFilename, outputFilename) { + getIncludeArguments(libraries) { + const includeFlag = this.compiler.includeFlag || "-I"; + + return _.map(libraries, (selectedLib) => { + const foundLib = _.find(this.compiler.libs, (o, libId) => { + return (libId === selectedLib.id); + }); + + if (!foundLib) return false; + + const foundVersion = _.find(foundLib.versions, (o, versionId) => { + return (versionId === selectedLib.version); + }); + + if (!foundVersion) return false; + + return includeFlag + foundVersion.path; + }); + } + + prepareArguments(userOptions, filters, backendOptions, inputFilename, outputFilename, libraries) { let options = this.optionsForFilter(filters, outputFilename, userOptions); backendOptions = backendOptions || {}; @@ -215,8 +235,9 @@ class BaseCompiler { options = options.concat(this.compiler.optArg); } + const libIncludes = this.getIncludeArguments(libraries); userOptions = this.filterUserOptions(userOptions); - return options.concat(userOptions || []).concat([this.filename(inputFilename)]); + return libIncludes.concat(options).concat(userOptions || []).concat([this.filename(inputFilename)]); } @@ -339,7 +360,8 @@ class BaseCompiler { buildFilters.execute = true; const compilerArguments = _.compact( - this.prepareArguments(key.options, buildFilters, key.backendOptions, inputFilename, outputFilename) + this.prepareArguments(key.options, buildFilters, key.backendOptions, + inputFilename, outputFilename, key.libraries) ); const result = await this.buildExecutable(key.compiler.exe, compilerArguments, inputFilename, @@ -409,11 +431,11 @@ class BaseCompiler { return result; } - getCacheKey(source, options, backendOptions, filters, tools) { - return {compiler: this.compiler, source, options, backendOptions, filters, tools}; + getCacheKey(source, options, backendOptions, filters, tools, libraries) { + return {compiler: this.compiler, source, options, backendOptions, filters, tools, libraries}; } - compile(source, options, backendOptions, filters, bypassCache, tools, executionParameters) { + compile(source, options, backendOptions, filters, bypassCache, tools, executionParameters, libraries) { const optionsError = this.checkOptions(options); if (optionsError) return Promise.reject(optionsError); const sourceError = this.checkSource(source); @@ -428,7 +450,7 @@ class BaseCompiler { stdin: executionParameters.stdin || "" }; delete options.executeParameters; - const key = this.getCacheKey(source, options, backendOptions, filters, tools); + const key = this.getCacheKey(source, options, backendOptions, filters, tools, libraries); const doExecute = filters.execute; filters = Object.assign({}, filters); @@ -470,7 +492,8 @@ class BaseCompiler { const outputFilename = this.getOutputFilename(dirPath, this.outputFilebase); options = _.compact( - this.prepareArguments(options, filters, backendOptions, inputFilename, outputFilename) + this.prepareArguments(options, filters, backendOptions, + inputFilename, outputFilename, libraries) ); const toolsPromise = this.runToolsOfType( diff --git a/lib/handlers/compile.js b/lib/handlers/compile.js index 94a747d5d..09d36c97f 100644 --- a/lib/handlers/compile.js +++ b/lib/handlers/compile.js @@ -181,6 +181,7 @@ class CompileHandler { parseRequest(req, compiler) { let source, options, backendOptions, filters, bypassCache = false, tools, executionParameters = {}; + let libraries = []; // IF YOU MODIFY ANYTHING HERE PLEASE UPDATE THE DOCUMENTATION! if (req.is('json')) { // JSON-style request @@ -195,6 +196,7 @@ class CompileHandler { backendOptions = requestOptions.compilerOptions; filters = requestOptions.filters || compiler.getDefaultFilters(); tools = requestOptions.tools; + libraries = requestOptions.libraries || []; } else { // API-style source = req.body; @@ -221,7 +223,7 @@ class CompileHandler { tools.forEach((tool) => { tool.args = this.splitArguments(tool.args); }); - return {source, options, backendOptions, filters, bypassCache, tools, executionParameters}; + return {source, options, backendOptions, filters, bypassCache, tools, executionParameters, libraries}; } splitArguments(options) { @@ -258,7 +260,7 @@ class CompileHandler { return next(); } const {source, options, backendOptions, filters, - bypassCache, tools, executionParameters} = this.parseRequest(req, compiler); + bypassCache, tools, executionParameters, libraries} = this.parseRequest(req, compiler); const remote = compiler.getRemote(); if (remote) { // Undo any routing that was done to get here (i.e. /api/* path has been removed) @@ -279,7 +281,7 @@ class CompileHandler { return _.pluck(array || [], 'text').join("\n"); } - compiler.compile(source, options, backendOptions, filters, bypassCache, tools, executionParameters) + compiler.compile(source, options, backendOptions, filters, bypassCache, tools, executionParameters, libraries) .then(result => { if (req.accepts(['text', 'json']) === 'json') { res.set('Content-Type', 'application/json'); diff --git a/static/libs-widget.js b/static/libs-widget.js index 59978104d..e86020091 100644 --- a/static/libs-widget.js +++ b/static/libs-widget.js @@ -186,11 +186,11 @@ LibsWidget.prototype.listUsedLibs = function () { LibsWidget.prototype.getLibsInUse = function () { var libs = []; - _.each(this.availableLibs[this.currentLangId], function (library) { + _.each(this.availableLibs[this.currentLangId], function (library, libId) { _.each(library.versions, function (version, ver) { if (library.versions[ver].used) { - // We trust the invariant of only 1 used version at any given time per lib - libs.push(library.versions[ver]); + var libVer = Object.assign({libId: libId, versionId: ver}, library.versions[ver]); + libs.push(libVer); } }); }); diff --git a/static/panes/compiler.js b/static/panes/compiler.js index 668f0bf88..0a3b461b2 100644 --- a/static/panes/compiler.js +++ b/static/panes/compiler.js @@ -484,14 +484,17 @@ Compiler.prototype.compile = function (bypassCache, newTools) { produceIr: this.irViewOpen }, filters: this.getEffectiveFilters(), - tools: this.getActiveTools(newTools) + tools: this.getActiveTools(newTools), + libraries: [] }; - var includeFlag = this.compiler ? this.compiler.includeFlag : '-I'; + _.each(this.libsWidget.getLibsInUse(), function (item) { - _.each(item.path, function (path) { - options.userArguments += ' ' + includeFlag + path; + options.libraries.push({ + id: item.libId, + version: item.versionId }); }); + this.compilerService.expand(this.source).then(_.bind(function (expanded) { var request = { source: expanded || '', From d4e9f37e72fb50fdba21e6d79d40a5240b09399a Mon Sep 17 00:00:00 2001 From: Partouf Date: Fri, 12 Jul 2019 14:50:44 +0200 Subject: [PATCH 4/9] libraries in conformance view --- static/panes/conformance-view.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/static/panes/conformance-view.js b/static/panes/conformance-view.js index b531d87bf..c2cc0f227 100644 --- a/static/panes/conformance-view.js +++ b/static/panes/conformance-view.js @@ -306,16 +306,18 @@ Conformance.prototype.compileChild = function (child) { options: { userArguments: child.find(".options").val() || "", filters: {}, - compilerOptions: {produceAst: false, produceOptInfo: false} + compilerOptions: {produceAst: false, produceOptInfo: false}, + libraries: [] } }; - var compiler = this.compilerService.findCompiler(this.langId, picker.val()); - var includeFlag = compiler ? compiler.includeFlag : '-I'; + _.each(this.libsWidget.getLibsInUse(), function (item) { - _.each(item.path, function (path) { - request.options.userArguments += ' ' + includeFlag + path; + request.options.libraries.push({ + id: item.libId, + version: item.versionId }); }); + // This error function ensures that the user will know we had a problem (As we don't save asm) this.compilerService.submit(request) .then(_.bind(function (x) { From 125f4d360fd676d5e84eac12b06a632d2a18332b Mon Sep 17 00:00:00 2001 From: Partouf Date: Fri, 12 Jul 2019 14:52:27 +0200 Subject: [PATCH 5/9] libraries in executor --- static/panes/executor.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/static/panes/executor.js b/static/panes/executor.js index d0ad189c4..e0e2660a8 100644 --- a/static/panes/executor.js +++ b/static/panes/executor.js @@ -231,14 +231,17 @@ Executor.prototype.compile = function (bypassCache) { executorRequest: true }, filters: {execute: true}, - tools: [] + tools: [], + libraries: [] }; - var includeFlag = this.compiler ? this.compiler.includeFlag : '-I'; + _.each(this.libsWidget.getLibsInUse(), function (item) { - _.each(item.path, function (path) { - options.userArguments += ' ' + includeFlag + path; + options.libraries.push({ + id: item.libId, + version: item.versionId }); }); + this.compilerService.expand(this.source).then(_.bind(function (expanded) { var request = { source: expanded || '', From e70aa4f3b3d4af770300c23087bef0d442ddc28d Mon Sep 17 00:00:00 2001 From: Partouf Date: Fri, 12 Jul 2019 15:10:08 +0200 Subject: [PATCH 6/9] extend documentation --- docs/API.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/API.md b/docs/API.md index cd56135bf..6c456a494 100644 --- a/docs/API.md +++ b/docs/API.md @@ -36,7 +36,9 @@ Returns a list of compilers for the provided language id. In text form, Returns a list of libraries and library versions available for the provided language id. This request only returns data in JSON. -You can use the given include paths to supply in the userArguments for compilation. +You can use the given include paths to supply in the userArguments for compilation. *(deprecated)* + +You will need the library id's and the version id's to supply to **compile** if you want to include libraries during compilation. ### `GET /api/shortlinkinfo/` - return information about a given link @@ -56,7 +58,8 @@ To specify a compilation request as a JSON document, post it as the appropriate "filters": { "filter": true }, - "tools": [] + "tools": [], + "libraries": [] } } ``` @@ -83,6 +86,9 @@ With the tools array you can ask CE to execute certain tools available for For example: ```"tools": [{"id":"clangtidytrunk","args":"-checks=*"}]``` to execute clang-tidy with all checks enabled. +Libraries can be included by supplying the library id and versions in an array, for example: + ```[{"id": "range-v3", "version": "trunk"}, {"id": "fmt", "version": "400"}]``` + The text request is designed for simplicity for command-line clients like `curl` ```bash From 026eee84bf8d33ca13ec53c129b5675c1dda2070 Mon Sep 17 00:00:00 2001 From: Partouf Date: Fri, 12 Jul 2019 15:28:37 +0200 Subject: [PATCH 7/9] bugfix multiple paths in libraryversion --- lib/base-compiler.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 3a122529d..eb4297807 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -206,7 +206,7 @@ class BaseCompiler { getIncludeArguments(libraries) { const includeFlag = this.compiler.includeFlag || "-I"; - return _.map(libraries, (selectedLib) => { + return _.flatten(_.map(libraries, (selectedLib) => { const foundLib = _.find(this.compiler.libs, (o, libId) => { return (libId === selectedLib.id); }); @@ -219,8 +219,8 @@ class BaseCompiler { if (!foundVersion) return false; - return includeFlag + foundVersion.path; - }); + return _.map(foundVersion.path, (path) => includeFlag + path); + })); } prepareArguments(userOptions, filters, backendOptions, inputFilename, outputFilename, libraries) { From de7b26d695d49d630e419538f326890d631c967a Mon Sep 17 00:00:00 2001 From: Patrick Quist Date: Sat, 13 Jul 2019 18:43:02 +0200 Subject: [PATCH 8/9] Attempt to cleanup API documentation --- docs/API.md | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/docs/API.md b/docs/API.md index 6c456a494..805cbe4cf 100644 --- a/docs/API.md +++ b/docs/API.md @@ -56,13 +56,26 @@ To specify a compilation request as a JSON document, post it as the appropriate "userArguments": "Compiler flags", "compilerOptions": {}, "filters": { - "filter": true + "binary": false, + "commentOnly": true, + "demangle": true, + "directives": true, + "execute": false, + "intel": true, + "labels": true, + "libraryCode": false, + "trim": false }, - "tools": [], - "libraries": [] + "tools": [ + {"id":"clangtidytrunk", "args":"-checks=*"} + ], + "libraries": [ + {"id": "range-v3", "version": "trunk"}, + {"id": "fmt", "version": "400"} + ] } } -``` +``` The filters are a JSON object with `true`/`false` values. If not supplied, defaults are used. If supplied, the filters are used as-is. @@ -71,6 +84,23 @@ The filters are a JSON object with `true`/`false` values. If not supplied, To force a cache bypass, set `bypassCache` in the root of the request to `true`. +Filters include `binary`, `labels`, `intel`, `directives` and + `demangle`, which correspond to the UI buttons on the HTML version. + +With the tools array you can ask CE to execute certain tools available for + the current compiler, and also supply arguments for this tool. + +Libraries can be marked to have their directories available when including + their header files. The can be listed by supplying the library ids and versions in an array. + The id's to supply can be found with the `/api/libraries/` + + +# Non-REST API's + +### `POST /api/compiler//compile` - perform a compilation + +This is same endpoint as for compilation using JSON. + A text compilation request has the source as the body of the post, and uses query parameters to pass the options and filters. Filters are supplied as a comma-separated string. Use the query parameter `filters=XX` to set the @@ -78,17 +108,6 @@ A text compilation request has the source as the body of the post, and uses or `removeFilters` to remove from defaults. Compiler parameters should be passed as `options=-O2` and default to empty. -Filters include `binary`, `labels`, `intel`, `comments`, `directives` and - `demangle`, which correspond to the UI buttons on the HTML version. - -With the tools array you can ask CE to execute certain tools available for - the current compiler, and also supply arguments for this tool. - For example: ```"tools": [{"id":"clangtidytrunk","args":"-checks=*"}]``` - to execute clang-tidy with all checks enabled. - -Libraries can be included by supplying the library id and versions in an array, for example: - ```[{"id": "range-v3", "version": "trunk"}, {"id": "fmt", "version": "400"}]``` - The text request is designed for simplicity for command-line clients like `curl` ```bash @@ -145,8 +164,6 @@ If JSON is present in the request's `Accept` header, the compilation results } ``` -# Not-so-RESTful API's - ### `POST /shortener` - saves given state *forever* to a shortlink and returns the unique id for the link The body of this post should be in the format of a [ClientState](https://github.com/mattgodbolt/compiler-explorer/blob/master/lib/clientstate.js) From e25dd140f317a2fc8fed86c773801c584028e6f6 Mon Sep 17 00:00:00 2001 From: Partouf Date: Tue, 16 Jul 2019 22:10:31 +0200 Subject: [PATCH 9/9] fix as suggested --- lib/base-compiler.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index eb4297807..9cf1f369e 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -236,11 +236,12 @@ class BaseCompiler { } const libIncludes = this.getIncludeArguments(libraries); - userOptions = this.filterUserOptions(userOptions); - return libIncludes.concat(options).concat(userOptions || []).concat([this.filename(inputFilename)]); + + userOptions = this.filterUserOptions(userOptions) || []; + return options.concat(libIncludes, userOptions, [this.filename(inputFilename)]); } - + filterUserOptions(userOptions) { return userOptions; }