Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Display version #188

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@ __pycache__
irc.yaml
root-*
shorten_key.py

bin/activate*
bin/bottle.py
bin/cherryd
bin/easy_install*
bin/pip*
bin/pygmentize
bin/python*
cherrypy/
lib/
local/

out
3 changes: 3 additions & 0 deletions bin/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -o errexit

bindir=${0%/*}
. $bindir/getopt.sh

TERM=xterm rustc - -o ./out "$@"
printf '\377' # 255 in octal
exec cat out
8 changes: 5 additions & 3 deletions bin/evaluate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

set -o errexit

bindir=${0%/*}
. $bindir/getopt.sh

TERM=xterm rustc - -o ./out "$@"
printf '\377' # 255 in octal
if [ "${*#*--test}" != "$*" ] && [ "${*#*--color=always}" != "$*" ]; then
if [ $coloredtest = 1 ]; then
# For /evaluate.json, we have {test: true, color: true}. Let's make the
# output coloured too. This would be better in web.py, but we don't
# have an easy way to allot parameters for ./out.
# output coloured too.
TERM=xterm exec ./out --color=always
else
exec ./out
Expand Down
22 changes: 22 additions & 0 deletions bin/getopt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/false
# This file should be source-d rather than exec-ed

coloredtest=0
while : ; do
case "$1" in
--evaluatesh=*|--compilesh=*)
case "$1" in
--evaluatesh=debug|--compilesh=debug)
export RUST_BACKTRACE=1
debugme=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and the backtrace thing would be #119, so it should probably be solved in a different way (such as a check box on the website - but that can wait for another PR, too)

;;
--evaluatesh=coloredtest)
coloredtest=1
;;
esac
shift
;;
*)
break
esac
done
35 changes: 27 additions & 8 deletions playpen.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
#!/usr/bin/env python3

import subprocess
import re, os.path

def execute(version, command, arguments, data=None):
with subprocess.Popen(("playpen",
"root-" + version,
g_wrapper_cmd_cache = {}

def execute(channel, command, arguments, data=None, skip_playpen=False, debug_me=False):
cache_key = (channel, command)
wrapper_cmd = g_wrapper_cmd_cache.get(cache_key, None)
if wrapper_cmd is None:
if skip_playpen:
wrapper_cmd = ()
if os.path.exists(command):
with open(command) as fp:
if re.match(r'#!.*sh', fp.readline()):
wrapper_cmd = ("sh", ) # compile.sh has non-standard #!/usr/bin/dash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you rather change the shebang instead? Not sure if that's a good idea either, but it seems better than checking in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the Debian standard #!/bin/dash is really compatible with the playpen jail on the production server.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to wikipedia, Debian's /bin/sh is Dash, so you're running that anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is (I'm on Debian.)

Arch is a weird distro. The tar binary package of Dash contains /usr/bin/dash but its install/uninstall hook script tweaks /etc/shells as if it's at /bin/dash. If there's really no /bin/*sh under an Arch chroot, I have to live with the above clumsiness.

The quickest solution is changing the shebang to #!/usr/bin/env sh but I think it is marginally more secure to keep using the current absolute shebang path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arch symlinks /bin to /usr/bin and /sbin to /usr/sbin, so that might be what you're seeing. You should be able to use /bin/sh, since its included in bash's package.

else:
wrapper_cmd = ("playpen",
"root-" + channel,
"--mount-proc",
"--user=rust",
"--timeout=5",
"--syscalls-file=whitelist",
"--devices=/dev/urandom:r,/dev/null:rw",
"--memory-limit=128",
"--",
command) + arguments,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) as p:
"--")
g_wrapper_cmd_cache[cache_key] = wrapper_cmd

full_cmd = wrapper_cmd + (command, ) + arguments
if debug_me:
print("running {}".format(full_cmd), file=sys.stderr, flush=True)

with subprocess.Popen(full_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) as p:
if data is None:
out = p.communicate()[0]
else:
Expand Down
11 changes: 11 additions & 0 deletions static/web.css
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ button.primary:hover, button.primary:focus, button.primary:active {
margin-top: 1.25em;
}

#rustc-version {
position: absolute;
bottom: 1em;
right: 1em;
}

#rustc-version-text {
margin: 0px;
}

#configure-editor span {
background: url("data:image/svg+xml,%3C?xml version='1.0' standalone='no'?%3E%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' version='1.1'%3E%3Cpath fill='%23a42' stroke='%23931' stroke-width='1' d='M 7,0.5 6.5,1 6.5,3 6,3.5 5.5,3.5 4,2 3,2 2,3 2,4 3.5,5.5 3.5,6 3,6.5 1,6.5 0.5,7 l 0,2 0.5,0.5 2,0 0.5,0.5 0,0.5 -1.5,1.5 0,1 1,1 1,0 1.5,-1.5 0.5,0 0.5,0.5 0,2 0.5,0.5 2,0 0.5,-0.5 0,-2 0.5,-0.5 0.5,0 1.5,1.5 1,0 1,-1 0,-1 -1.5,-1.5 0,-0.5 0.5,-0.5 2,0 L 15.5,9 15.5,7 15,6.5 13,6.5 12.5,6 12.5,5.5 14,4 14,3 13,2 12,2 10.5,3.5 10,3.5 9.5,3 9.5,1 9,0.5 Z m 1,5 c 1.5,0 2.5,1 2.5,2.5 0,1.5 -1,2.5 -2.5,2.5 C 6.5,10.5 5.5,9.5 5.5,8 5.5,6.5 6.5,5.5 8,5.5 Z'/%3E%3C/svg%3E");
background-size: 100% 100%;
Expand Down Expand Up @@ -464,6 +474,7 @@ button[disabled]:last-child::before {
}

main {
position: relative;
flex: 1;
display: flex;
flex-flow: column;
Expand Down
7 changes: 4 additions & 3 deletions static/web.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
· Beta: the next version; stable features only.
· Nightly: cutting edge; unstable features allowed.">Channel</div
><div
><input type=radio name=version id=version-stable value=stable checked><label for=version-stable title="Use the stable channel">Stable</label
><input type=radio name=version id=version-beta value=beta><label for=version-beta title="Use the beta channel">Beta</label
><input type=radio name=version id=version-nightly value=nightly><label for=version-nightly title="Use the nightly channel">Nightly</label
><input type=radio name=version id=version-stable value=stable checked><label id=label-stable for=version-stable title="Use the stable channel">Stable</label
><input type=radio name=version id=version-beta value=beta><label id=label-beta for=version-beta title="Use the beta channel">Beta</label
><input type=radio name=version id=version-nightly value=nightly><label id=label-nightly for=version-nightly title="Use the nightly channel">Nightly</label
></div
></div
><wbr><div class=right-c-e
Expand All @@ -81,6 +81,7 @@
println!("Hello, world!");
}</div>
<div id=result data-empty><div></div><button type=button id=clear-result title="Close this pane">×</button></div>
<div id=rustc-version><p id=rustc-version-text></p></div>
</main>
</body>
</html>
42 changes: 40 additions & 2 deletions static/web.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(function () {
"use strict";

window.g_versionDict = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon (fails Travis)


// For convenience of development
var PREFIX = location.href.indexOf("/web.html") != -1 ? "https://play.rust-lang.org/" : "/";

Expand Down Expand Up @@ -205,7 +207,9 @@
req.open(method, url, true);
req.onreadystatechange = function() {
if (req.readyState == XMLHttpRequest.DONE) {
if (req.status == expect) {
var ok = Array.isArray(expect) ? expect.includes(req.status) :
req.status == expect;
if (ok) {
if (on_success) {
on_success(req.responseText);
}
Expand Down Expand Up @@ -558,6 +562,40 @@
session = editor.getSession();
themelist = ace.require("ace/ext/themelist");

var rustVerDisplay = document.getElementById('rustc-version-text');
if (rustVerDisplay) {
httpRequest("GET", "/version.json", null, [200, 304],
function(response) {
window.g_versionDict = JSON.parse(response);
for (var channel in window.g_versionDict) {
if ( ! window.g_versionDict.hasOwnProperty(channel)) continue;
var rustver = window.g_versionDict[channel].rustc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another missing semicolon


var label = document.getElementById('label-' + channel);
if (label) {
var t = label.title;
if (t) {
label.title = t + ": " + rustver;
}
}

var button = document.getElementById('version-' + channel);
if (button) {
button.onclick = (function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Don't make functions within a loop" apparently also fails Travis

var rv = rustver;
return function() {
rustVerDisplay.textContent = rv;
};
})();
if (button.checked)
button.onclick();
}
}
}, function(status, response) {
rustVerDisplay.textContent = "Could not fetch rustc version";
});
}

editor.focus();

build_themes(themelist);
Expand Down Expand Up @@ -665,7 +703,7 @@
};

mirButton.onclick = function() {
document.getElementById("version-nightly").checked = true;
document.getElementById("version-nightly").onclick();
compile("mir", result, session.getValue(), getRadioValue("version"),
getRadioValue("optimize"), mirButton);
};
Expand Down
Loading