From 0ee3cf29c1f461b34d29038a9ea30f957eaa4cc1 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Mon, 9 Jan 2017 08:16:17 -0600 Subject: [PATCH 01/40] Bump up timeouts etc --- c-preload/compiler-wrapper | 2 +- etc/config/compiler-explorer.amazon.properties | 2 +- etc/config/compiler-explorer.defaults.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/c-preload/compiler-wrapper b/c-preload/compiler-wrapper index 8bf3cc7d9..d91e8921f 100755 --- a/c-preload/compiler-wrapper +++ b/c-preload/compiler-wrapper @@ -15,7 +15,7 @@ ALLOWED_FOR_READ=${ALLOWED_FOR_READ}:/usr/share/fonts:/etc/passwd # Last-gasp limits ulimit -m $((512 * 1024)) # RSS limit in K -ulimit -t 5 # CPU time in seconds +ulimit -t 10 # CPU time in seconds ulimit -v $((2 * 1024 * 1024)) # virtual RAM limit in K "$@" diff --git a/etc/config/compiler-explorer.amazon.properties b/etc/config/compiler-explorer.amazon.properties index eb763bca9..7abb56d0c 100644 --- a/etc/config/compiler-explorer.amazon.properties +++ b/etc/config/compiler-explorer.amazon.properties @@ -1,6 +1,6 @@ # Settings overridden for Amazon EC2 instances that power http://*.godbolt.org/ googleApiKey=AIzaSyAaz35KJv8DA0ABoime0fEIh32NmbyYbcQ -compileTimeoutMs=5000 +compileTimeoutMs=7500 compiler-wrapper=./c-preload/compiler-wrapper max-asm-size=8388608 staticMaxAgeSecs=30 diff --git a/etc/config/compiler-explorer.defaults.properties b/etc/config/compiler-explorer.defaults.properties index 0920065cb..3421abc22 100644 --- a/etc/config/compiler-explorer.defaults.properties +++ b/etc/config/compiler-explorer.defaults.properties @@ -1,6 +1,6 @@ # Default settings for GCC Explorer. port=10240 -compileTimeoutMs=3000 +compileTimeoutMs=10000 defaultSource=builtin cacheMb=50 language=C++ From 7ea75df3ee914ecdf9954b3a680e77eee4f94a68 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Mon, 9 Jan 2017 17:37:05 -0600 Subject: [PATCH 02/40] Make loading client-options.json asynchronous --- static/async-get.js | 36 ++++++++++++++++++++++++++++++++++++ static/options.js | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 static/async-get.js diff --git a/static/async-get.js b/static/async-get.js new file mode 100644 index 000000000..860dcc0ef --- /dev/null +++ b/static/async-get.js @@ -0,0 +1,36 @@ +// Copyright (c) 2012-2017, Matt Godbolt +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +define({ + load: function (name, req, onLoad, config) { + if (config.isBuild) return onLoad(null); // optimizer build + + req(['jquery'], function ($) { + $.ajax({type: "GET", url: name}).done(function (response) { + onLoad(response); + }); + }); + } +}); diff --git a/static/options.js b/static/options.js index 7028f97da..1e9b06b36 100644 --- a/static/options.js +++ b/static/options.js @@ -25,8 +25,8 @@ define(function (require) { "use strict"; - var $ = require('jquery'); - var options = $.ajax({type: "GET", url: 'client-options.json', async: false}).responseJSON; + var options = require('./async-get!client-options.json'); options.embedded = window.location.pathname === "/embed.html"; return options; }); + From 25f49f9a80447a0365d52881dbcffd8a8df58b6c Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Wed, 11 Jan 2017 15:53:12 -0600 Subject: [PATCH 03/40] Kill entire process tree of a child when the timeout is reached. Fixes #232 --- lib/base-compiler.js | 13 ++++++++++--- package.json | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 946c11083..28f182389 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -31,6 +31,7 @@ var child_process = require('child_process'), utils = require('./utils'), quote = require('shell-quote'), _ = require('underscore-node'), + treeKill = require('tree-kill'), logger = require('./logger').logger; function Compile(compiler, env) { @@ -265,12 +266,17 @@ Compile.prototype.exec = function (command, args, options) { env: env, detached: process.platform == 'linux' }); + var running = true; + function kill() { + if (running) treeKill(child.pid); + } var stderr = ""; var stdout = ""; var timeout; if (timeoutMs) timeout = setTimeout(function () { + logger.warn("Timeout for", command, args, "after", timeoutMs, "ms"); okToCache = false; - child.kill(); + kill(); stderr += "\nKilled - processing time exceeded"; }, timeoutMs); var truncated = false; @@ -279,7 +285,7 @@ Compile.prototype.exec = function (command, args, options) { if (stdout.length > maxOutput) { stdout += "\n[Truncated]"; truncated = true; - child.kill(); + kill(); return; } stdout += data; @@ -289,7 +295,7 @@ Compile.prototype.exec = function (command, args, options) { if (stderr.length > maxOutput) { stderr += "\n[Truncated]"; truncated = true; - child.kill(); + kill(); return; } stderr += data; @@ -297,6 +303,7 @@ Compile.prototype.exec = function (command, args, options) { child.on('exit', function (code) { logger.debug({type: 'exited', code: code}); if (timeout !== undefined) clearTimeout(timeout); + running = false; }); return new Promise(function (resolve, reject) { child.on('error', function (e) { diff --git a/package.json b/package.json index 0a987e9de..738bf1542 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "serve-favicon": "2.3.x", "serve-static": "1.10.x", "temp": "0.8.x", + "tree-kill": "1.1.x", "underscore-node": "*", "shell-quote": "1.6.x", "winston": "2.2.x" From f6ab7fe3737b8e7aebc63b239ba495d5640e285c Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Thu, 12 Jan 2017 02:35:29 +0400 Subject: [PATCH 04/40] base-compiler.js: acknowledge checkSource weakness --- lib/base-compiler.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 28f182389..e7caeacde 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -237,6 +237,10 @@ Compile.prototype.checkOptions = function (options) { return null; }; +// This check for arbitrary user-controlled preprocessor inclusions +// can be circumvented in more than one way. The goal here is to respond +// to simple attempts with a clear diagnostic; the service still needs to +// assume that malicious actors can make the compiler open arbitrary files. Compile.prototype.checkSource = function (source) { var re = /^\s*#\s*i(nclude|mport)(_next)?\s+["<"](\/|.*\.\.)/; var failed = []; From 65b5bf49c4d0a06f193f42c23e542bf28e62d0ab Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Thu, 12 Jan 2017 17:32:41 -0600 Subject: [PATCH 05/40] Correctly identify PROC and ENDP even when a comment is on the same line. Fixes #235 --- lib/asm-cl.js | 8 +- test/cases/cl-main-opt-out.asm | 90 ++++++++++++++++++ ...in-opt-out.directives.labels.comments.json | 94 +++++++++++++++++++ test/filter-tests.js | 2 + 4 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 test/cases/cl-main-opt-out.asm create mode 100644 test/cases/cl-main-opt-out.directives.labels.comments.json diff --git a/lib/asm-cl.js b/lib/asm-cl.js index 16abe1fcd..1a817d023 100644 --- a/lib/asm-cl.js +++ b/lib/asm-cl.js @@ -34,12 +34,12 @@ var gccExplorerDir = /\\compiler-explorer-compiler/; // has to match part of the // * optional leading whitespace // * middle part // * comment part -var parseRe = /^(\s*)([^;]*)(;.*)*$/; -var isProc = /.*PROC$/; -var isEndp = /.*ENDP$/; +var parseRe = /^(\s*)([^;]*)(;.*)?$/; +var isProc = /.*PROC\s*$/; +var isEndp = /.*ENDP\s*$/; var constDef = /^([a-zA-Z_$@][a-zA-Z_$@0-9.]*)\s*=.*$/; var labelFind = /[.a-zA-Z_@$][a-zA-Z_$@0-9.]*/g; -var labelDef = /^(.*):$/; +var labelDef = /^(.*):\s*$/; // Anything identifier-looking with a "@@" in the middle, and a comment at the end // is treated as a mangled name. The comment will be used to replace the identifier. var mangledIdentifier = /\?[^ ]+@@[^ |]+/; diff --git a/test/cases/cl-main-opt-out.asm b/test/cases/cl-main-opt-out.asm new file mode 100644 index 000000000..50df7d1ee --- /dev/null +++ b/test/cases/cl-main-opt-out.asm @@ -0,0 +1,90 @@ +; Listing generated by Microsoft (R) Optimizing Compiler Version 19.00.24224.0 + +include listing.inc + +INCLUDELIB LIBCMT +INCLUDELIB OLDNAMES + +PUBLIC main +PUBLIC ??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ ; make_array<1,3,5,2,3,5,6,4,8,9,2> +PUBLIC ??A?$array@H$0L@@std@@QEBAAEBH_K@Z ; std::array::operator[] +; Function compile flags: /Ogtpy +; File z:\home\mgodbolt\apps\windows\14.0.24224-pre\lib\native\include\array +; COMDAT ??A?$array@H$0L@@std@@QEBAAEBH_K@Z +_TEXT SEGMENT +this$ = 8 +_Pos$ = 16 +??A?$array@H$0L@@std@@QEBAAEBH_K@Z PROC ; std::array::operator[], COMDAT + +; 167 : #if _ITERATOR_DEBUG_LEVEL == 0 +; 168 : return (_Elems[_Pos]); + + 00000 48 8d 04 91 lea rax, QWORD PTR [rcx+rdx*4] + +; 169 : +; 170 : #else /* _ITERATOR_DEBUG_LEVEL == 0 */ +; 171 : return (_Size <= _Pos +; 172 : ? (_Bad_subscript(), _Elems[_Pos]) +; 173 : : _Elems[_Pos]); +; 174 : #endif /* _ITERATOR_DEBUG_LEVEL == 0 */ +; 175 : } + + 00004 c3 ret 0 +??A?$array@H$0L@@std@@QEBAAEBH_K@Z ENDP ; std::array::operator[] +_TEXT ENDS +; Function compile flags: /Ogtpy +; File z:\tmp\example.cpp +; COMDAT ??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ +_TEXT SEGMENT +$T1 = 8 +??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ PROC ; make_array<1,3,5,2,3,5,6,4,8,9,2>, COMDAT + +; 6 : return std::array{vars...}; + + 00000 c7 01 01 00 00 + 00 mov DWORD PTR [rcx], 1 + 00006 48 8b c1 mov rax, rcx + 00009 c7 41 04 03 00 + 00 00 mov DWORD PTR [rcx+4], 3 + 00010 c7 41 08 05 00 + 00 00 mov DWORD PTR [rcx+8], 5 + 00017 c7 41 0c 02 00 + 00 00 mov DWORD PTR [rcx+12], 2 + 0001e c7 41 10 03 00 + 00 00 mov DWORD PTR [rcx+16], 3 + 00025 c7 41 14 05 00 + 00 00 mov DWORD PTR [rcx+20], 5 + 0002c c7 41 18 06 00 + 00 00 mov DWORD PTR [rcx+24], 6 + 00033 c7 41 1c 04 00 + 00 00 mov DWORD PTR [rcx+28], 4 + 0003a c7 41 20 08 00 + 00 00 mov DWORD PTR [rcx+32], 8 + 00041 c7 41 24 09 00 + 00 00 mov DWORD PTR [rcx+36], 9 + 00048 c7 41 28 02 00 + 00 00 mov DWORD PTR [rcx+40], 2 + +; 7 : } + + 0004f c3 ret 0 +??$make_array@$00$02$04$01$02$04$05$03$07$08$01@@YA?AV?$array@H$0L@@std@@XZ ENDP ; make_array<1,3,5,2,3,5,6,4,8,9,2> +_TEXT ENDS +; Function compile flags: /Ogtpy +; File z:\tmp\example.cpp +; COMDAT main +_TEXT SEGMENT +main PROC ; COMDAT + +; 11 : constexpr auto a = make_array<1,3,5,2,3,5,6,4,8,9,2>(); +; 12 : +; 13 : return a[2]; + + 00000 b8 05 00 00 00 mov eax, 5 + +; 14 : } + + 00005 c3 ret 0 +main ENDP +_TEXT ENDS +END diff --git a/test/cases/cl-main-opt-out.directives.labels.comments.json b/test/cases/cl-main-opt-out.directives.labels.comments.json new file mode 100644 index 000000000..3005c6eac --- /dev/null +++ b/test/cases/cl-main-opt-out.directives.labels.comments.json @@ -0,0 +1,94 @@ +[ + { + "source": null, + "text": "std::array::operator[], COMDAT PROC" + }, + { + "source": null, + "text": " lea rax, QWORD PTR [rcx+rdx*4]" + }, + { + "source": null, + "text": " ret 0" + }, + { + "source": null, + "text": "std::array::operator[] ENDP" + }, + { + "source": null, + "text": "make_array<1,3,5,2,3,5,6,4,8,9,2>, COMDAT PROC" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx], 1" + }, + { + "source": null, + "text": " mov rax, rcx" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+4], 3" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+8], 5" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+12], 2" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+16], 3" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+20], 5" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+24], 6" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+28], 4" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+32], 8" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+36], 9" + }, + { + "source": null, + "text": " mov DWORD PTR [rcx+40], 2" + }, + { + "source": null, + "text": " ret 0" + }, + { + "source": null, + "text": "make_array<1,3,5,2,3,5,6,4,8,9,2> ENDP" + }, + { + "source": null, + "text": "main PROC; COMDAT" + }, + { + "source": null, + "text": " mov eax, 5" + }, + { + "source": null, + "text": " ret 0" + }, + { + "source": null, + "text": "main ENDP" + } +] \ No newline at end of file diff --git a/test/filter-tests.js b/test/filter-tests.js index efdd57e56..98baf65d2 100755 --- a/test/filter-tests.js +++ b/test/filter-tests.js @@ -98,6 +98,7 @@ function testFilter(filename, suffix, filters) { // bless("cases/cl-regex.asm", "cases/cl-regex.asm.dlcb.json", {directives: true, labels: true, commentOnly: true, binary:true}); // bless("cases/cl-maxarray.asm", "cases/cl-maxarray.asm.dlcb.json", {directives: true, labels: true, commentOnly: true, binary:true}); // bless("cases/cl64-sum.asm", "cases/cl64-sum.asm.dlcb.json", {directives: true, labels: true, commentOnly: true, binary:true}); +// bless("cases/cl-main-opt-out.asm", "cases/cl-main-opt-out.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true}); // bless("cases/avr-loop.asm", "cases/avr-loop.asm.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true}); // bless("cases/bug-192.asm", "cases/bug-192.asm.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true}); // bless("cases/arm-moose.asm", "cases/arm-moose.asm.directives.labels.comments.json", {directives: true, labels: true, commentOnly: true}); @@ -133,3 +134,4 @@ describe('Filter test cases', function () { }); }); }); + From 54ffd968641062b04358458a0547b34267d4c2e0 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Thu, 12 Jan 2017 17:41:39 -0600 Subject: [PATCH 06/40] Always resize instead of refresh. Fixes #229 --- static/compiler.js | 8 ++------ static/editor.js | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/static/compiler.js b/static/compiler.js index ad5e991c5..ce0292a13 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -113,7 +113,7 @@ define(function (require) { self.eventHub.emit('compilerClose', self.id); }, this); container.on('resize', this.resize, this); - container.on('shown', this.refresh, this); + container.on('shown', this.resize, this); container.on('open', function () { self.eventHub.emit('compilerOpen', self.id); self.updateFontScale(); @@ -154,10 +154,6 @@ define(function (require) { this.saveState(); } - Compiler.prototype.refresh = function () { - this.outputEditor.refresh(); - }; - // TODO: need to call resize if either .top-bar or .bottom-bar resizes, which needs some work. // Issue manifests if you make a window where one compiler is small enough that the buttons spill onto two lines: // reload the page and the bottom-bar is off the bottom until you scroll a tiny bit. @@ -165,7 +161,7 @@ define(function (require) { var topBarHeight = this.domRoot.find(".top-bar").outerHeight(true); var bottomBarHeight = this.domRoot.find(".bottom-bar").outerHeight(true); this.outputEditor.setSize(this.domRoot.width(), this.domRoot.height() - topBarHeight - bottomBarHeight); - this.refresh(); + this.outputEditor.refresh(); }; // Gets the filters that will actually be used (accounting for issues with binary diff --git a/static/editor.js b/static/editor.js index fea65fe33..8cc2e23b4 100644 --- a/static/editor.js +++ b/static/editor.js @@ -122,14 +122,10 @@ define(function (require) { this.debouncedEmitChange(); }, this)); - function refresh() { - self.editor.refresh(); - } - function resize() { var topBarHeight = self.domRoot.find(".top-bar").outerHeight(true); self.editor.setSize(self.domRoot.width(), self.domRoot.height() - topBarHeight); - refresh(); + self.editor.refresh(); } this.domRoot.find('.load-save').click(_.bind(function () { @@ -141,7 +137,7 @@ define(function (require) { }, this)); container.on('resize', resize); - container.on('shown', refresh); + container.on('shown', resize); container.on('open', function () { self.eventHub.emit('editorOpen', self.id); }); From fe4467756ff01d79f3e90b3986e80cf0dec6da96 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sat, 14 Jan 2017 21:52:08 -0600 Subject: [PATCH 07/40] Pop up an alert if URL parsing fails. FIxes #223 --- app.js | 1 - static/alert.js | 41 +++++++++++++++++++++++++++++++++++++++++ static/explorer.css | 6 ++++++ static/index.html | 19 +++++++++++++++++++ static/main.js | 14 +++++++++++++- static/url.js | 13 ++++++++----- 6 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 static/alert.js diff --git a/app.js b/app.js index 3404f6144..a70ce3001 100755 --- a/app.js +++ b/app.js @@ -455,7 +455,6 @@ function embeddedHandler(req, res, next) { res.end(); } - findCompilers() .then(function (compilers) { var prevCompilers; diff --git a/static/alert.js b/static/alert.js new file mode 100644 index 000000000..c18aadae1 --- /dev/null +++ b/static/alert.js @@ -0,0 +1,41 @@ +// Copyright (c) 2012-2017, Matt Godbolt +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +define(function (require) { + var $ = require('jquery'); + + function Alert() { + this.modal = $('#alert'); + this.title = this.modal.find('.modal-title'); + this.body = this.modal.find('.modal-body'); + } + + Alert.prototype.alert = function (title, body) { + this.title.html(title); + this.body.html(body); + this.modal.modal(); + }; + return Alert; +}); \ No newline at end of file diff --git a/static/explorer.css b/static/explorer.css index 0e76984f3..4f24a673f 100644 --- a/static/explorer.css +++ b/static/explorer.css @@ -213,4 +213,10 @@ pre.content { .compile-time { font-size: x-small; font-style: italic; +} + +.url-parse-info { + font-size: small; + margin-top: 1em; + font-style: italic; } \ No newline at end of file diff --git a/static/index.html b/static/index.html index 66372782b..2eb68f66e 100644 --- a/static/index.html +++ b/static/index.html @@ -243,5 +243,24 @@ int square(int num) { + + diff --git a/static/main.js b/static/main.js index f95c5a827..32be49c25 100644 --- a/static/main.js +++ b/static/main.js @@ -64,6 +64,7 @@ define(function (require) { var clipboard = require('clipboard'); var Hub = require('hub'); var Raven = require('raven-js'); + var Alert = require('alert'); function start() { analytics.initialise(); @@ -71,6 +72,7 @@ define(function (require) { var options = require('options'); $('.language-name').text(options.language); + var alert = new Alert(); var safeLang = options.language.toLowerCase().replace(/[^a-z_]+/g, ''); var defaultSrc = $('.template .lang.' + safeLang).text().trim(); @@ -87,7 +89,17 @@ define(function (require) { var config; if (!options.embedded) { - config = url.deserialiseState(window.location.hash.substr(1)); + var serializedState = window.location.hash.substr(1); + if (serializedState) { + try { + config = url.deserialiseState(serializedState); + } catch (exception) { + alert.alert("Unable to parse URL", + "
Compiler Explorer was unable to parse the URL hash. " + + "Please check it and try again.
" + + "
" + exception + "
"); + } + } if (config) { // replace anything in the default config with that from the hash config = _.extend(defaultConfig, config); diff --git a/static/url.js b/static/url.js index 1c0bdda59..967ea4021 100644 --- a/static/url.js +++ b/static/url.js @@ -34,7 +34,7 @@ define(function (require) { function convertOldState(state) { var sc = state.compilers[0]; - if (!sc) return false; + if (!sc) throw new Error("Unable to determine compiler from old state"); var content = []; var source; if (sc.sourcez) { @@ -68,7 +68,7 @@ define(function (require) { state = GoldenLayout.unminifyConfig(state); break; default: - return false; + throw new Error("Invalid version '" + state.version + "'"); } return state; } @@ -83,21 +83,24 @@ define(function (require) { function deserialiseState(stateText) { var state; + var exception; try { state = unrisonify(stateText); if (state && state.z) { state = unrisonify(lzstring.decompressFromBase64(state.z)); } - } catch (ignored) { + } catch (ex) { + exception = ex; } - if (!state) { try { state = $.parseJSON(decodeURIComponent(stateText)); - } catch (ignored) { + } catch (ex) { + if (!exception) exception = ex; } } + if (!state && exception) throw exception; return loadState(state); } From 23efc05167be188b5fea74c581cbeee12a384062 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sat, 14 Jan 2017 23:13:48 -0600 Subject: [PATCH 08/40] New RESTful API Partially addresses #179 and begins opening the door to #203. --- README.md | 56 +++++++++++++++++++++ app.js | 59 ++++++++++++---------- etc/config/c++.lud-mgodbolt01.properties | 4 +- lib/base-compiler.js | 12 +++++ lib/compile-handler.js | 62 ++++++++++++++++++++---- lib/utils.js | 9 +++- package.json | 1 - static/compiler.js | 2 +- 8 files changed, 166 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 79e9cb2d7..ebdce1e96 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,59 @@ Feel free to raise an issue on [github](https://github.com/mattgodbolt/compiler- Compiler Explorer is maintained by [Matt Godbolt](http://xania.org). Multiple compiler and difference view was implemented by [Gabriel Devillers](https://github.com/voxelf). + +### RESTful API + +There's a simple restful API that can be used to do compiles to asm and to list compilers. In general +all handlers live in `/api/*` endpoints, and will accept JSON or text in POSTs, and will return text responses +or JSON responses depending on the request's `Accept` header. + +At a later date there may be some form of rate-limiting: currently requests will be queued and dealt with +exactly like interactive requests on the main site. Authentication might be required at some point in the +future (for the main Compiler Explorer site anyway). + +The following endpoints are defined: + +#### `GET /api/compilers` - return a list of compilers + +Returns a list of compilers. In text form, there's a simple formatting of the ID of the compiler and its +description. In JSON, all the information is returned as an array of compilers, with the `id` key being the +primary identifier of each compiler. + +#### `POST /api//compiler` - perform a compilation + +To specify a compilation request as a JSON document, post it as the appropriate type and send an object of +the form: `{'source': 'source to compile', 'options': 'compiler flags', 'filters': {'filter': true}}`. The filters are an JSON object with true/false. If not supplied, defaults are used. If supplied, the filters are used +as-is. + +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 filters directly, else `addFilters=XX` to add a filter to defaults, or `removeFilters` to remove from defaults. Compiler parameters should be passed as `options=-O2` and default to empty. + +Filters include `binary`, `labels`, `intel`, `comments` and `directives` and correspond to the UI buttons on +the HTML version. + +The text request is designed for simplicity for command-line clients like `curl`: + +```bash +$ curl 'https://gcc.godbolt.org/api/compiler/g63/compile?options=-Wall' --data-binary 'int foo() { return 1; }' +# Compilation provided by Compiler Explorer at gcc.godbolt.org +foo(): + push rbp + mov rbp, rsp + mov eax, 1 + pop rbp + ret +``` + +If JSON is present in the request's `Accept` header, the compilation results are of the form: + +```json +{ + code: 0 if successful, else compiler return code, + stdout: [ { text: "Output", + (optional) tag: {line: source line, text: "parsed error for that line"} } ], + stderr: (as above), + asm: [ { text: "assembly text", source: source line number or null if none } ] +} +``` diff --git a/app.js b/app.js index a70ce3001..d0203cb50 100755 --- a/app.js +++ b/app.js @@ -138,8 +138,8 @@ fileSources.forEach(function (source) { }); var clientOptionsHandler = new ClientOptionsHandler(fileSources); -var apiHandler = new ApiHandler(); var compileHandler = new CompileHandler(gccProps, compilerProps); +var apiHandler = new ApiHandler(compileHandler); // auxiliary function used in clientOptionsHandler function compareOn(key) { @@ -386,27 +386,32 @@ function findCompilers() { }); } -// Instantiate a function that writes information on the compiler, -// in JSON format, for ease of external listing. -function ApiHandler() { - var reply = ""; +function ApiHandler(compileHandler) { + this.compilers = []; + this.compileHandler = compileHandler; this.setCompilers = function (compilers) { - reply = JSON.stringify(compilers); + this.compilers = compilers; }; - this.handler = function apiHandler(req, res, next) { - var bits = req.url.split("/"); - if (bits.length !== 2 || req.method !== "GET") return next(); - switch (bits[1]) { - default: - next(); - break; - - case "compilers": - res.set('Content-Type', 'application/json'); - res.end(reply); - break; + this.handler = express.Router(); + this.handler.get('/compilers', _.bind(function (req, res, next) { + if (req.accepts(['text', 'json']) == 'json') { + res.set('Content-Type', 'application/json'); + res.end(JSON.stringify(this.compilers)); + } else { + res.set('Content-Type', 'text/plain'); + var title = 'Compiler Name'; + var maxLength = _.max(_.pluck(_.pluck(this.compilers, 'id').concat([title]), 'length')); + res.write(padRight(title, maxLength) + ' | Description\n'); + res.end(_.map(this.compilers, function (compiler) { + return padRight(compiler.id, maxLength) + ' | ' + compiler.name + '\n'; + }).join("\n")); } - }; + }, this)); + this.handler.param('compiler', _.bind(function (req, res, next, compilerName) { + req.compiler = compilerName; + next(); + }, this)); + this.handler.post('/compiler/:compiler/compile', this.compileHandler.handler); } function shortUrlHandler(req, res, next) { @@ -484,7 +489,6 @@ findCompilers() var webServer = express(), sFavicon = require('serve-favicon'), - sStatic = require('serve-static'), bodyParser = require('body-parser'), morgan = require('morgan'), compression = require('compression'), @@ -501,24 +505,29 @@ findCompilers() .use(morgan('combined', {stream: logger.stream})) .use(compression()) .use(sFavicon(staticDir + '/favicon.ico')) - .use('/v', sStatic(staticDir + '/v', {maxAge: Infinity})) - .use(sStatic(staticDir, {maxAge: staticMaxAgeSecs * 1000})); + .use('/v', express.static(staticDir + '/v', {maxAge: Infinity, index: false})) + .use(express.static(staticDir, {maxAge: staticMaxAgeSecs * 1000})); if (archivedVersions) { // The archived versions directory is used to serve "old" versioned data during updates. It's expected // to contain all the SHA-hashed directories from previous versions of Compiler Explorer. logger.info(" serving archived versions from", archivedVersions); - webServer.use('/v', sStatic(archivedVersions, {maxAge: Infinity})); + webServer.use('/v', express.static(archivedVersions, {maxAge: Infinity, index: false})); } webServer .use(bodyParser.json({limit: gccProps('bodyParserLimit', '1mb')})) + .use(bodyParser.text({ + limit: gccProps('bodyParserLimit', '1mb'), type: function () { + return true; + } + })) .use(restreamer()) .get('/client-options.json', clientOptionsHandler.handler) .use('/source', getSource) .use('/api', apiHandler.handler) .use('/g', shortUrlHandler) .use('/e', embeddedHandler) - .post('/compile', compileHandler.handler) // used inside static/compiler.js - .post('/diff', diffHandler); // used inside static/compiler.js + .post('/compile', compileHandler.handler) + .post('/diff', diffHandler); logger.info("======================================="); webServer.on('error', function (err) { diff --git a/etc/config/c++.lud-mgodbolt01.properties b/etc/config/c++.lud-mgodbolt01.properties index 123020987..23a9a3a40 100644 --- a/etc/config/c++.lud-mgodbolt01.properties +++ b/etc/config/c++.lud-mgodbolt01.properties @@ -1,7 +1,7 @@ # Default settings for GCC Explorer. defaultCompiler=g52 -#compilers=g44:g45:g46:clang35:g51:g52:gdef:msp430g453:cl -compilers=&gcc:&clang:&windows +compilers=g44:g45:g46:clang35:g51:g52:gdef:msp430g453:cl +#compilers=&gcc:&clang:&windows group.gcc.compilers=gdef:g62 compiler.gdef.exe=/usr/bin/g++ compiler.gdef.name=Default G++ diff --git a/lib/base-compiler.js b/lib/base-compiler.js index e7caeacde..e9b4a5564 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -271,9 +271,11 @@ Compile.prototype.exec = function (command, args, options) { detached: process.platform == 'linux' }); var running = true; + function kill() { if (running) treeKill(child.pid); } + var stderr = ""; var stdout = ""; var timeout; @@ -387,4 +389,14 @@ Compile.prototype.getInfo = function () { return this.compiler; }; +Compile.prototype.getDefaultFilters = function () { + // TODO; propagate to UI? + return { + intel: true, + commentOnly: true, + directives: true, + labels: true + }; +}; + module.exports = Compile; diff --git a/lib/compile-handler.js b/lib/compile-handler.js index 2f874e9c8..0f6790748 100644 --- a/lib/compile-handler.js +++ b/lib/compile-handler.js @@ -85,9 +85,37 @@ function CompileHandler(gccProps, compilerProps) { var proxy = httpProxy.createProxyServer({}); this.handler = _.bind(function compile(req, res, next) { - var compiler = this.compilersById[req.body.compiler]; - if (!compiler) return next(); - + var source, options, filters, compiler; + if (req.is('json')) { + // JSON-style request + compiler = this.compilersById[req.compiler || req.body.compiler]; + if (!compiler) return next(); + source = req.body.source; + options = req.body.options; + filters = req.body.filters || compiler.getDefaultFilters(); + } else { + // API-style + compiler = this.compilersById[req.compiler]; + if (!compiler) return next(); + source = req.body; + options = req.query.options; + // By default we get the default filters. + filters = compiler.getDefaultFilters(); + // If specified exactly, we'll take that with ?filters=a,b,c + if (req.query.filters) { + filters = _.object(_.map(req.query.filters.split(","), function (filter) { + return [filter, true]; + })); + } + // Add a filter. ?addFilters=binary + _.each((req.query.addFilters || "").split(","), function (filter) { + filters[filter] = true; + }); + // Remove a filter. ?removeFilter=intel + _.each((req.query.removeFilters || "").split(","), function (filter) { + delete filters[filter]; + }); + } var remote = compiler.getRemote(); if (remote) { proxy.web(req, res, {target: remote}, function (e) { @@ -96,23 +124,39 @@ function CompileHandler(gccProps, compilerProps) { }); return; } - var source = req.body.source; - var options = req.body.options || ''; + if (source === undefined) { return next(new Error("Bad request")); } - options = _.chain(quote.parse(options) + options = _.chain(quote.parse(options || '') .map(function (x) { if (typeof(x) == "string") return x; return x.pattern; })) .filter(_.identity) .value(); - var filters = req.body.filters; + function textify(array) { + return _.pluck(array || [], 'text').join("\n"); + } + compiler.compile(source, options, filters).then( function (result) { - res.set('Content-Type', 'application/json'); - res.end(JSON.stringify(result)); + if (req.accepts(['text', 'json']) === 'json') { + res.set('Content-Type', 'application/json'); + res.end(JSON.stringify(result)); + } else { + res.set('Content-Type', 'text/plain'); + try { + res.write("# Compilation provided by Compiler Explorer at " + req.get('Host') + "\n"); + res.write(textify(result.asm)); + if (result.code !== 0) res.write("\n# Compiler exited with result code " + result.code); + if (!_.isEmpty(result.stdout)) res.write("\nStandard out:\n" + textify(result.stdout)); + if (!_.isEmpty(result.stderr)) res.write("\nStandard error:\n" + textify(result.stderr)); + } catch (ex) { + re.write("Error handling request: " + ex); + } + res.end('\n'); + } }, function (error) { logger.error("Error: " + error); diff --git a/lib/utils.js b/lib/utils.js index d590f5e73..8bc0ba59b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -66,4 +66,11 @@ function parseOutput(lines, inputFilename) { return result; } -exports.parseOutput = parseOutput; \ No newline at end of file +exports.parseOutput = parseOutput; + +function padRight(name, len) { + while (name.length < len) name = name + ' '; + return name; +} + +exports.padRight = padRight; \ No newline at end of file diff --git a/package.json b/package.json index 738bf1542..56a1e0f3b 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "promise-queue": "2.1.x", "nopt": "3.0.x", "serve-favicon": "2.3.x", - "serve-static": "1.10.x", "temp": "0.8.x", "tree-kill": "1.1.x", "underscore-node": "*", diff --git a/static/compiler.js b/static/compiler.js index ce0292a13..fdbfec673 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -214,7 +214,7 @@ define(function (require) { }, this), 500); $.ajax({ type: 'POST', - url: '/compile', + url: '/api/compiler/' + request.compiler + '/compile', dataType: 'json', contentType: 'application/json', data: jsonRequest, From 47195c29dc0c5297800d610666dd63393bd3d50c Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sat, 14 Jan 2017 23:39:19 -0600 Subject: [PATCH 09/40] Don't clean up temp diretories if there are pending compilations. Fixes #212. --- lib/compilation-env.js | 4 ++++ lib/compile-handler.js | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/compilation-env.js b/lib/compilation-env.js index c028e1dcc..29ca33114 100644 --- a/lib/compilation-env.js +++ b/lib/compilation-env.js @@ -100,6 +100,10 @@ CompilationEnvironment.prototype.enqueue = function (job) { return this.compileQueue.add(job); }; +CompilationEnvironment.prototype.isBusy = function () { + return this.compileQueue.getPendingLength() > 0 || this.compileQueue.getQueueLength() > 0; +}; + CompilationEnvironment.prototype.findBadOptions = function (options) { return _.filter(options, function (option) { return !option.match(this.okOptions) || option.match(this.badOptions); diff --git a/lib/compile-handler.js b/lib/compile-handler.js index 0f6790748..46844f559 100644 --- a/lib/compile-handler.js +++ b/lib/compile-handler.js @@ -33,26 +33,28 @@ var child_process = require('child_process'), temp.track(); -function periodicCleanup() { - temp.cleanup(function (err, stats) { - if (err) logger.error("Error cleaning directories: ", err); - if (stats) logger.debug("Directory cleanup stats:", stats); - }); -} - var oneTimeInit = false; -function initialise(gccProps, compilerProps) { +function initialise(gccProps, compilerEnv) { if (oneTimeInit) return; oneTimeInit = true; var tempDirCleanupSecs = gccProps("tempDirCleanupSecs", 600); logger.info("Cleaning temp dirs every " + tempDirCleanupSecs + " secs"); - setInterval(periodicCleanup, tempDirCleanupSecs * 1000); + setInterval(function () { + if (compilerEnv.isBusy()) { + logger.warn("Skipping temporary file clean up as compiler environment is busy"); + return; + } + temp.cleanup(function (err, stats) { + if (err) logger.error("Error cleaning directories: ", err); + if (stats) logger.debug("Directory cleanup stats:", stats); + }); + }, tempDirCleanupSecs * 1000); } function CompileHandler(gccProps, compilerProps) { - initialise(gccProps, compilerProps); this.compilersById = {}; this.compilerEnv = new CompilationEnvironment(gccProps, compilerProps); + initialise(gccProps, this.compilerEnv); this.factories = {}; this.create = function (compiler) { From a9e777b88dbf063fe7c689249592f7ee2c1a4ae7 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 15 Jan 2017 15:55:16 -0600 Subject: [PATCH 10/40] Fix remote compilers --- app.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index d0203cb50..0f75a49bb 100755 --- a/app.js +++ b/app.js @@ -271,7 +271,10 @@ function findCompilers() { var request = http.get({ hostname: host, port: port, - path: "/api/compilers" + path: "/api/compilers", + headers: { + 'Accept': 'application/json' + } }, function (res) { var str = ''; res.on('data', function (chunk) { @@ -401,9 +404,9 @@ function ApiHandler(compileHandler) { res.set('Content-Type', 'text/plain'); var title = 'Compiler Name'; var maxLength = _.max(_.pluck(_.pluck(this.compilers, 'id').concat([title]), 'length')); - res.write(padRight(title, maxLength) + ' | Description\n'); + res.write(utils.padRight(title, maxLength) + ' | Description\n'); res.end(_.map(this.compilers, function (compiler) { - return padRight(compiler.id, maxLength) + ' | ' + compiler.name + '\n'; + return utils.padRight(compiler.id, maxLength) + ' | ' + compiler.name + '\n'; }).join("\n")); } }, this)); From 801c58604a227b70e9c715c22c33c6218321a3b4 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 15 Jan 2017 16:14:36 -0600 Subject: [PATCH 11/40] README tweaks --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ebdce1e96..82a15eb0d 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ foo(): If JSON is present in the request's `Accept` header, the compilation results are of the form: -```json +``` { code: 0 if successful, else compiler return code, stdout: [ { text: "Output", From 6ecd63bef0285144ff2c887397ad62046a38b3ad Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 15 Jan 2017 16:29:01 -0600 Subject: [PATCH 12/40] Banner fixes --- etc/config/c++.amazon.properties | 2 ++ etc/config/c++.danger.properties | 1 + etc/config/d.amazon.properties | 1 + etc/config/go.amazon.properties | 1 + etc/config/rust.amazon.properties | 1 + lib/compile-handler.js | 3 ++- 6 files changed, 8 insertions(+), 1 deletion(-) diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 5d7ced6a2..5b398b6db 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -1,5 +1,7 @@ compilers=gcc1204@20480:&gcc86:&icc:&clang:&cl:&cross:&ellcc defaultCompiler=g63 +textBanner=Compilation provided by Compiler Explorer at https://gcc.godbolt.org/ + ############################### # GCC for x86 group.gcc86.compilers=g471:g472:g473:g474:g481:g482:g483:g484:g485:g490:g491:g492:g493:g494:g510:g520:g530:g540:g6:g62:g63:g7snapshot diff --git a/etc/config/c++.danger.properties b/etc/config/c++.danger.properties index 5013c12b0..40c858e0d 100644 --- a/etc/config/c++.danger.properties +++ b/etc/config/c++.danger.properties @@ -1,5 +1,6 @@ # Matt's home development computer defaultCompiler=g54 +textBanner=Testing the text banner compilers=g54:g47:g48:avr #compilers=localhost@20480 compiler.g54.exe=/usr/bin/g++ diff --git a/etc/config/d.amazon.properties b/etc/config/d.amazon.properties index 486e44718..07fd37988 100644 --- a/etc/config/d.amazon.properties +++ b/etc/config/d.amazon.properties @@ -1,4 +1,5 @@ compilers=gdc48:gdc49:gdc52:&ldc +textBanner=Compilation provided by Compiler Explorer at https://d.godbolt.org/ defaultCompiler=gdc52 # This is only due to limitations on the d.godbolt.org image for now. supportsBinary=false diff --git a/etc/config/go.amazon.properties b/etc/config/go.amazon.properties index 68c2d7ca6..0d7534841 100644 --- a/etc/config/go.amazon.properties +++ b/etc/config/go.amazon.properties @@ -1,4 +1,5 @@ defaultCompiler=gccgo491 +textBanner=Compilation provided by Compiler Explorer at https://go.godbolt.org/ compilers=gccgo491:6g141 compileFilename=file.go compiler.gccgo491.exe=/usr/bin/gccgo diff --git a/etc/config/rust.amazon.properties b/etc/config/rust.amazon.properties index 7de85c1d6..3c74a1dd9 100644 --- a/etc/config/rust.amazon.properties +++ b/etc/config/rust.amazon.properties @@ -1,4 +1,5 @@ compilers=&rust +textBanner=Compilation provided by Compiler Explorer at https://rust.godbolt.org/ defaultCompiler=r1140 group.rust.compilers=r1140:r1130:r1120:r1110:r1100:r190:r180:r170:r160:r150:r140:r130:r120:r110:r100:nightly:beta group.rust.compilerType=rust diff --git a/lib/compile-handler.js b/lib/compile-handler.js index 46844f559..70f8e712d 100644 --- a/lib/compile-handler.js +++ b/lib/compile-handler.js @@ -85,6 +85,7 @@ function CompileHandler(gccProps, compilerProps) { }); }; var proxy = httpProxy.createProxyServer({}); + var textBanner = compilerProps('textBanner'); this.handler = _.bind(function compile(req, res, next) { var source, options, filters, compiler; @@ -149,7 +150,7 @@ function CompileHandler(gccProps, compilerProps) { } else { res.set('Content-Type', 'text/plain'); try { - res.write("# Compilation provided by Compiler Explorer at " + req.get('Host') + "\n"); + if (!_.isEmpty(textBanner)) res.write('# ' + textBanner + "\n"); res.write(textify(result.asm)); if (result.code !== 0) res.write("\n# Compiler exited with result code " + result.code); if (!_.isEmpty(result.stdout)) res.write("\nStandard out:\n" + textify(result.stdout)); From 76381e350249e182b8e1dd5fe8f854cbbb4cb520 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Mon, 16 Jan 2017 16:59:49 -0600 Subject: [PATCH 13/40] Road map --- README.md | 4 ++- Roadmap.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 Roadmap.md diff --git a/README.md b/README.md index 82a15eb0d..4ce57dfad 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Try out one of the demo sites: [C++][cpp], [Rust][rust], [D][d] or [Go][go]. [d]: https://d.godbolt.org/ "Compiler Explorer for D" [go]: https://go.godbolt.org/ "Compiler Explorer for Go" -### Developing +### Developing or running a local instance Compiler Explorer is written in node.js. @@ -33,6 +33,8 @@ The config system leaves a lot to be desired, I'm working on porting [CCS](https Feel free to raise an issue on [github](https://github.com/mattgodbolt/compiler-explorer/issues) or [email me directly](mailto:matt@godbolt.org) for more help. +There's now a [Road map](Roadmap.md) that gives a little insight into future plans for Compiler Explorer. + ### Credits Compiler Explorer is maintained by [Matt Godbolt](http://xania.org). Multiple compiler and difference view was diff --git a/Roadmap.md b/Roadmap.md new file mode 100644 index 000000000..bafe01e88 --- /dev/null +++ b/Roadmap.md @@ -0,0 +1,80 @@ +# Compiler Explorer Road Map + +CE was started in 2012 to serve my needs at [my company](http:/drw.com) in terms of showing how +C++ constructs translated to assembly code. It started out as a `tmux` session with `vi` running in one +pane and `watch gcc -S foo.cc -o -` running in the other. Since those days it's now a public website +serving the C++, Rust, Go and D communities and performs around 20,000 compilations per day. + +This document is an attempt to capture thoughts on the future direction of Compiler Explorer. + +## Areas to improve + +### Mobile client support + +CE's UI doesn't work well with mobile clients. The editor doesn't work well on many mobile clients, and the +layout doesn't lend itself well to small screens. + +Ideas for improving mobile support include automatically folding up all the panes into a single tab upon +detection of a mobile client. This would require a bunch of fixes in the +underlying [UI library](http://golden-layout.com) as this doesn't properly work with mobile and tabs. + +Perhaps a read-only simplified view would work better: the main reason one brings up the CE website is to +look at tweeted links rather than author content. + +### UI improvements + +The UI has a number of things that need improving: + +* Multiple editor windows +* Saving and restoring from browser-local storage +* Handling the loss of data if one has a work-in-progress CE window open and then clicks another CE link. + +### Diff view + +A frequently requested feature is to be able to diff output. A large patch was provided by @Voxelf which +helped spur on the development of the new UI, but the diff view he created has yet to be merged. There's +a possibility that moving to the [Monaco](https://microsoft.github.io/monaco-editor/) editor will not only +give a better editing experience, but also bring pretty much free diff windows out of the box. + +### Execution support + +Another big ticket item is to allow executing of the user's code. This is fraught with security issues, and +brings up a number of UI and API considerations. Compiling code every time to execute with different params +seems wasteful, so caching seems good; but in a multi-instance setup a shared cache woudl be needed. Perhaps +a backend system that caches the executables (and makes them downloadable; at least for some compilers where +license allows), and stores the binaries in ephemeral, shared storage. This same backend system could also +be used to store code, and could be part of a whole new way of sending and sharing code (if made permanent +storage). + +### Support more compilers + +Most of the open tickets are to do with adding new compilers, or fixing issues with existing compilers. +Continuing to add more compilers and make it easier for others to submit PRs to add new compilers is +very important. + +## Tensions + +There's an inherent tension between the standalone, run-it-yourself version of CE and the scalable, AWS-backed +CE instance. Care must be taken to keep the standalone version usable, not least as the majority of CE's +development is done on a laptop during a commute (with little or no internet access). + +## Priorities + +Above all, the priority is to keep the main CE site up, stable and dependable. After that, features are +added honestly in the order that is most useful and interesting to the primary developer (Matt Godbolt). + +## Non-goals + +CE will remain ad-free, open-source and non-commercial. There's no plans at all to add "freemium" content. + +## 2017 goals + +With all this in mind, the tentative goals for 2017 are: + +* Move to the Monaco editor + * Implement diff view +* Come up with a decent secure solution for code execution +* Design an API that can handle remote code execution and download needs +* Implement remote execution UIs + +These goals will be refined as time ticks on. From 7eb0d035c4a05f59cf2afb91bbb91666e4a56a0b Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Tue, 17 Jan 2017 17:50:03 -0600 Subject: [PATCH 14/40] URI encode the compiler when requesting Fixes #238 --- etc/config/c++.lud-mgodbolt01.properties | 2 +- static/compiler.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/config/c++.lud-mgodbolt01.properties b/etc/config/c++.lud-mgodbolt01.properties index 23a9a3a40..0cecf418a 100644 --- a/etc/config/c++.lud-mgodbolt01.properties +++ b/etc/config/c++.lud-mgodbolt01.properties @@ -1,6 +1,6 @@ # Default settings for GCC Explorer. defaultCompiler=g52 -compilers=g44:g45:g46:clang35:g51:g52:gdef:msp430g453:cl +compilers=/usr/bin/g++:g44:g45:g46:clang35:g51:g52:gdef:msp430g453:cl #compilers=&gcc:&clang:&windows group.gcc.compilers=gdef:g62 compiler.gdef.exe=/usr/bin/g++ diff --git a/static/compiler.js b/static/compiler.js index fdbfec673..d0fe6f51c 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -214,7 +214,7 @@ define(function (require) { }, this), 500); $.ajax({ type: 'POST', - url: '/api/compiler/' + request.compiler + '/compile', + url: '/api/compiler/' + encodeURIComponent(request.compiler) + '/compile', dataType: 'json', contentType: 'application/json', data: jsonRequest, From eb679d56c7afeb2d34c090aedd84ca17eff54493 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Wed, 18 Jan 2017 08:47:07 -0600 Subject: [PATCH 15/40] Fix extraneous new line --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 0f75a49bb..676677fbd 100755 --- a/app.js +++ b/app.js @@ -406,7 +406,7 @@ function ApiHandler(compileHandler) { var maxLength = _.max(_.pluck(_.pluck(this.compilers, 'id').concat([title]), 'length')); res.write(utils.padRight(title, maxLength) + ' | Description\n'); res.end(_.map(this.compilers, function (compiler) { - return utils.padRight(compiler.id, maxLength) + ' | ' + compiler.name + '\n'; + return utils.padRight(compiler.id, maxLength) + ' | ' + compiler.name; }).join("\n")); } }, this)); From 2b1be4ed717b1c67f573201f13fee7cb8c16c3dc Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Wed, 18 Jan 2017 08:47:40 -0600 Subject: [PATCH 16/40] Fix proxying of requests. Fixes #239 --- lib/compile-handler.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compile-handler.js b/lib/compile-handler.js index 70f8e712d..774eb5b55 100644 --- a/lib/compile-handler.js +++ b/lib/compile-handler.js @@ -121,6 +121,7 @@ function CompileHandler(gccProps, compilerProps) { } var remote = compiler.getRemote(); if (remote) { + req.url = req.originalUrl; // Undo any routing that was done to get here (i.e. /api/* path has been removed) proxy.web(req, res, {target: remote}, function (e) { logger.error("Proxy error: ", e); next(e); From 0d04f0b437a26c40342f98cd057192a988bb5b29 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 22 Jan 2017 09:11:03 -0600 Subject: [PATCH 17/40] Catch stream errors. Maybe addresses #228 --- .idea/libraries/Cargo__rustfilt_.xml | 22 ++++++------ lib/base-compiler.js | 53 ++++++++++++++-------------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.idea/libraries/Cargo__rustfilt_.xml b/.idea/libraries/Cargo__rustfilt_.xml index 053fc6144..517e9f476 100644 --- a/.idea/libraries/Cargo__rustfilt_.xml +++ b/.idea/libraries/Cargo__rustfilt_.xml @@ -1,19 +1,19 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/lib/base-compiler.js b/lib/base-compiler.js index e9b4a5564..8aa33360e 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -276,36 +276,37 @@ Compile.prototype.exec = function (command, args, options) { if (running) treeKill(child.pid); } - var stderr = ""; - var stdout = ""; + var streams = { + stderr: "", + stdout: "", + truncated: false + }; var timeout; if (timeoutMs) timeout = setTimeout(function () { logger.warn("Timeout for", command, args, "after", timeoutMs, "ms"); okToCache = false; kill(); - stderr += "\nKilled - processing time exceeded"; + streams.stderr += "\nKilled - processing time exceeded"; }, timeoutMs); - var truncated = false; - child.stdout.on('data', function (data) { - if (truncated) return; - if (stdout.length > maxOutput) { - stdout += "\n[Truncated]"; - truncated = true; - kill(); - return; - } - stdout += data; - }); - child.stderr.on('data', function (data) { - if (truncated) return; - if (stderr.length > maxOutput) { - stderr += "\n[Truncated]"; - truncated = true; - kill(); - return; - } - stderr += data; - }); + + function setupStream(stream, name) { + stream.on('data', function (data) { + if (streams.truncated) return; + if (streams[name].length > maxOutput) { + streams[name] += "\n[Truncated]"; + streams.truncated = true; + kill(); + return; + } + streams[name] += data; + }); + stream.on('error', function (err) { + logger.error('Error with stream:', err); + }); + } + + setupStream(child.stdout, 'stdout'); + setupStream(child.stderr, 'stderr'); child.on('exit', function (code) { logger.debug({type: 'exited', code: code}); if (timeout !== undefined) clearTimeout(timeout); @@ -320,8 +321,8 @@ Compile.prototype.exec = function (command, args, options) { if (timeout !== undefined) clearTimeout(timeout); var result = { code: code, - stdout: stdout, - stderr: stderr, + stdout: streams.stdout, + stderr: streams.stderr, okToCache: okToCache }; logger.debug({type: "executed", command: command, args: args, result: result}); From a77c356c3064cac06b34fd72317c79bca489e531 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 22 Jan 2017 09:13:27 -0600 Subject: [PATCH 18/40] Don't pass gcc-toolchain to older clangs. Fixes #242 --- etc/config/c++.amazon1204.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/config/c++.amazon1204.properties b/etc/config/c++.amazon1204.properties index e361ed8b1..8f499e9ff 100644 --- a/etc/config/c++.amazon1204.properties +++ b/etc/config/c++.amazon1204.properties @@ -23,7 +23,6 @@ compiler.icc1301.supportsBinary=false # Clang for x86 group.clang.compilers=clang30:clang32:clang33:clang341 group.clang.intelAsm=-mllvm --x86-asm-syntax=intel -group.clang.options=--gcc-toolchain=/opt/compiler-explorer/gcc-6.2.0 compiler.clang30.exe=/usr/bin/clang++ compiler.clang30.alias=/usr/bin/clang++ compiler.clang30.name=x86-64 clang 3.0 @@ -36,6 +35,7 @@ compiler.clang33.name=x86-64 clang 3.3 compiler.clang341.exe=/opt/compiler-explorer/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ compiler.clang341.alias=/opt/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ compiler.clang341.name=x86-64 clang 3.4.1 +compiler.clang341.clang.options=--gcc-toolchain=/opt/compiler-explorer/gcc-6.2.0 ############################### # GCC for ARM From 9aa45f77ec9b98dd7062c3a4cd6ad91040a3af43 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 22 Jan 2017 09:19:21 -0600 Subject: [PATCH 19/40] Explicitly remove options for clang... --- etc/config/c++.amazon1204.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/config/c++.amazon1204.properties b/etc/config/c++.amazon1204.properties index 8f499e9ff..ad9d81ef1 100644 --- a/etc/config/c++.amazon1204.properties +++ b/etc/config/c++.amazon1204.properties @@ -23,6 +23,7 @@ compiler.icc1301.supportsBinary=false # Clang for x86 group.clang.compilers=clang30:clang32:clang33:clang341 group.clang.intelAsm=-mllvm --x86-asm-syntax=intel +group.clang.options= compiler.clang30.exe=/usr/bin/clang++ compiler.clang30.alias=/usr/bin/clang++ compiler.clang30.name=x86-64 clang 3.0 From 6f1039ec98184aaf480327b6f97c0593b6352c66 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 22 Jan 2017 16:46:05 -0600 Subject: [PATCH 20/40] Move more compilers over from gcc1204 instance to normal gcc instance --- etc/config/c++.amazon.properties | 34 ++++++++++++++++++++++++---- etc/config/c++.amazon1204.properties | 32 ++------------------------ etc/config/c++.danger.properties | 2 +- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 5b398b6db..67bdb1194 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -4,7 +4,10 @@ textBanner=Compilation provided by Compiler Explorer at https://gcc.godbolt.org/ ############################### # GCC for x86 -group.gcc86.compilers=g471:g472:g473:g474:g481:g482:g483:g484:g485:g490:g491:g492:g493:g494:g510:g520:g530:g540:g6:g62:g63:g7snapshot +group.gcc86.compilers=g464:g471:g472:g473:g474:g481:g482:g483:g484:g485:g490:g491:g492:g493:g494:g510:g520:g530:g540:g6:g62:g63:g7snapshot +compiler.g464.exe=/opt/compiler-explorer/gcc-4.6.4/bin/g++ +compiler.g464.alias=/usr/bin/g++-4.6 +compiler.g464.name=x86-64 gcc 4.6.4 compiler.g471.exe=/opt/compiler-explorer/gcc-4.7.1/bin/g++ compiler.g471.name=x86-64 gcc 4.7.1 compiler.g472.exe=/opt/compiler-explorer/gcc-4.7.2/bin/g++ @@ -52,10 +55,28 @@ compiler.g7snapshot.exe= /opt/compiler-explorer/gcc-7-snapshot/bin/g++ compiler.g7snapshot.name=x86-64 gcc 7 (snapshot) # Clang for x86 -group.clang.compilers=clang350:clang351:clang37x:clang36x:clang371:clang380:clang381:clang390:clang391:clang_trunk +group.clang.compilers=clang30:clang31:clang32:clang33:clang341:clang350:clang351:clang37x:clang36x:clang371:clang380:clang381:clang390:clang391:clang_trunk group.clang.intelAsm=-masm=intel group.clang.options=--gcc-toolchain=/opt/compiler-explorer/gcc-6.2.0 -compiler.clang350.exe=/usr/bin/clang++-3.5 +compiler.clang30.exe=/opt/compiler-explorer/clang+llvm-3.0-x86_64-linux-Ubuntu-11_10/bin/clang++ +compiler.clang30.alias=/usr/bin/clang++ +compiler.clang30.name=x86-64 clang 3.0 +compiler.clang30.options= +compiler.clang31.exe=/opt/compiler-explorer/clang+llvm-3.1-x86_64-linux-ubuntu_12.04/bin/clang++ +compiler.clang31.name=x86-64 clang 3.1 +compiler.clang31.options= +compiler.clang32.exe=/opt/compiler-explorer/clang-3.2/bin/clang++ +compiler.clang32.alias=/opt/clang-3.2/bin/clang++ +compiler.clang32.name=x86-64 clang 3.2 +compiler.clang32.options= +compiler.clang33.exe=/opt/compiler-explorer/clang-3.3/bin/clang++ +compiler.clang33.alias=/opt/clang-3.3/bin/clang++ +compiler.clang33.name=x86-64 clang 3.3 +compiler.clang33.options= +compiler.clang341.exe=/opt/compiler-explorer/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ +compiler.clang341.alias=/opt/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ +compiler.clang341.name=x86-64 clang 3.4.1 +compiler.clang350.exe=/opt/compiler-explorer/clang+llvm-3.5.0-x86_64-linux-gnu/bin/clang++ compiler.clang350.name=x86-64 clang 3.5 compiler.clang351.exe=/opt/compiler-explorer/clang+llvm-3.5.1-x86_64-linux-gnu/bin/clang++ compiler.clang351.name=x86-64 clang 3.5.1 @@ -79,9 +100,14 @@ compiler.clang_trunk.exe=/opt/compiler-explorer/clang-trunk/bin/clang++ compiler.clang_trunk.name=x86-64 clang (trunk) # icc for x86 -group.icc.compilers=icc16:icc17 +group.icc.compilers=icc1301:icc16:icc17 group.icc.intelAsm=-masm=intel group.icc.needsMulti=false +compiler.icc1301.exe=/opt/compiler-explorer/intel/bin/icc +compiler.icc1301.alias=/opt/intel/bin/icc +compiler.icc1301.name=x86-64 icc 13.0.1 +# intel 13.01 binary disabled: it just segfaults (no idea why) +compiler.icc1301.supportsBinary=false compiler.icc16.exe=/opt/compiler-explorer/intel/xe_2016_update3/bin/icc compiler.icc16.name=x86-64 icc 16 compiler.icc17.exe=/opt/compiler-explorer/intel/2017/bin/icc diff --git a/etc/config/c++.amazon1204.properties b/etc/config/c++.amazon1204.properties index ad9d81ef1..b737aaddb 100644 --- a/etc/config/c++.amazon1204.properties +++ b/etc/config/c++.amazon1204.properties @@ -1,42 +1,14 @@ -compilers=&gcc86:&clang:avrg453:&gccarm:icc1301:msp430g453 +compilers=&gcc86:avrg453:&gccarm:msp430g453 defaultCompiler=g447 ############################### # GCC for x86 -group.gcc86.compilers=g447:g453:g464 +group.gcc86.compilers=g447:g453 compiler.g447.exe=/usr/bin/g++-4.4 compiler.g447.alias=/usr/bin/g++-4.4 compiler.g447.name=x86-64 gcc 4.4.7 compiler.g453.exe=/usr/bin/g++-4.5 compiler.g453.alias=/usr/bin/g++-4.5 compiler.g453.name=x86-64 gcc 4.5.3 -compiler.g464.exe=/usr/bin/g++-4.6 -compiler.g464.alias=/usr/bin/g++-4.6 -compiler.g464.name=x86-64 gcc 4.6.4 -# Intel for x86 -compiler.icc1301.exe=/opt/compiler-explorer/intel/bin/icc -compiler.icc1301.alias=/opt/intel/bin/icc -compiler.icc1301.name=x86-64 icc 13.0.1 -compiler.icc1301.intelAsm=-masm=intel -compiler.icc1301.needsMulti=false -# intel binary disabled for now TODO why does it segfault? preload? -compiler.icc1301.supportsBinary=false -# Clang for x86 -group.clang.compilers=clang30:clang32:clang33:clang341 -group.clang.intelAsm=-mllvm --x86-asm-syntax=intel -group.clang.options= -compiler.clang30.exe=/usr/bin/clang++ -compiler.clang30.alias=/usr/bin/clang++ -compiler.clang30.name=x86-64 clang 3.0 -compiler.clang32.exe=/opt/compiler-explorer/clang-3.2/bin/clang++ -compiler.clang32.alias=/opt/clang-3.2/bin/clang++ -compiler.clang32.name=x86-64 clang 3.2 -compiler.clang33.exe=/opt/compiler-explorer/clang-3.3/bin/clang++ -compiler.clang33.alias=/opt/clang-3.3/bin/clang++ -compiler.clang33.name=x86-64 clang 3.3 -compiler.clang341.exe=/opt/compiler-explorer/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ -compiler.clang341.alias=/opt/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ -compiler.clang341.name=x86-64 clang 3.4.1 -compiler.clang341.clang.options=--gcc-toolchain=/opt/compiler-explorer/gcc-6.2.0 ############################### # GCC for ARM diff --git a/etc/config/c++.danger.properties b/etc/config/c++.danger.properties index 40c858e0d..008eae286 100644 --- a/etc/config/c++.danger.properties +++ b/etc/config/c++.danger.properties @@ -1,7 +1,7 @@ # Matt's home development computer defaultCompiler=g54 textBanner=Testing the text banner -compilers=g54:g47:g48:avr +#compilers=g54:g47:g48:avr #compilers=localhost@20480 compiler.g54.exe=/usr/bin/g++ compiler.g54.name=g++ 5.4 From afb33cb4c707a64f3f466c073565fb388bd7a329 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 22 Jan 2017 17:02:29 -0600 Subject: [PATCH 21/40] Add Patreon link (gulp!) --- static/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/static/index.html b/static/index.html index 2eb68f66e..e8a83c221 100644 --- a/static/index.html +++ b/static/index.html @@ -17,6 +17,7 @@