Skip to content

Commit

Permalink
Move documentation build into bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 25, 2019
1 parent aa3ca32 commit be23cd9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 46 deletions.
46 changes: 41 additions & 5 deletions src/bootstrap/test.rs
Expand Up @@ -4,7 +4,7 @@
//! our CI.

use std::env;
use std::ffi::OsString;
use std::ffi::{OsStr, OsString};
use std::fmt;
use std::fs;
use std::iter;
Expand Down Expand Up @@ -639,14 +639,50 @@ impl Step for RustdocJSNotStd {

fn run(self, builder: &Builder) {
if let Some(ref nodejs) = builder.config.nodejs {
let mut command = Command::new(nodejs);
command.args(&["src/tools/rustdoc-js/tester.js",
&*self.host,
builder.top_stage.to_string().as_str()]);
builder.ensure(crate::doc::Std {
target: self.target,
stage: builder.top_stage,
});

let mut tests_to_run = Vec::new();
let out = Path::new("build").join(&*self.host)
.join(&format!("stage{}",
builder.top_stage.to_string().as_str()))
.join("tests")
.join("rustdoc-js");

if let Ok(it) = fs::read_dir("src/test/rustdoc-js/") {
for entry in it {
if let Ok(entry) = entry {
let path = entry.path();
if path.extension() != Some(&OsStr::new("rs")) || !path.is_file() {
continue
}
let path_clone = path.clone();
let file_stem = path_clone.file_stem().expect("cannot get file stem");
let out = out.join(file_stem);
let mut cmd = builder.rustdoc_cmd(self.host);
cmd.arg("-o");
cmd.arg(out);
cmd.arg(path);
if if builder.config.verbose_tests {
try_run(builder, &mut cmd)
} else {
try_run_quiet(builder, &mut cmd)
} {
tests_to_run.push(file_stem.to_os_string());
}
}
}
}
assert!(!tests_to_run.is_empty(), "no rustdoc-js test generated...");

tests_to_run.insert(0, "src/tools/rustdoc-js/tester.js".into());
tests_to_run.insert(1, out.into());

let mut command = Command::new(nodejs);
command.args(&tests_to_run);

builder.run(&mut command);
} else {
builder.info(
Expand Down
58 changes: 17 additions & 41 deletions src/tools/rustdoc-js/tester.js
Expand Up @@ -220,18 +220,6 @@ function lookForEntry(entry, data) {
return null;
}

function build_docs(out_dir, rustdoc_path, file_to_document) {
var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]);
var s = '';
if (c.error || c.stderr.length > 0) {
if (c.stderr.length > 0) {
s += '==> STDERR: ' + c.stderr + '\n';
}
s += '==> ERROR: ' + c.error;
}
return s;
}

function load_files(out_folder, crate) {
var mainJs = readFile(out_folder + "/main.js");
var ALIASES = readFile(out_folder + "/aliases.js");
Expand Down Expand Up @@ -266,44 +254,32 @@ function load_files(out_folder, crate) {
}

function main(argv) {
if (argv.length !== 4) {
console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]");
if (argv.length < 4) {
console.error("USAGE: node tester.js OUT_FOLDER [TESTS]");
return 1;
}
const toolchain = argv[2];
const stage = argv[3];
const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc';
if (argv[2].substr(-1) !== "/") {
argv[2] += "/";
}
const out_folder = argv[2];

var errors = 0;

fs.readdirSync(TEST_FOLDER).forEach(function(file) {
if (!file.endsWith('.js')) {
return;
}
var test_name = file.substring(0, file.length - 3);
process.stdout.write('Checking "' + test_name + '" ... ');
var rust_file = TEST_FOLDER + test_name + '.rs';
for (var j = 3; j < argv.length; ++j) {
const test_name = argv[j];

if (!fs.existsSync(rust_file)) {
console.error("FAILED");
console.error("==> Missing '" + test_name + ".rs' file...");
process.stdout.write('Checking "' + test_name + '" ... ');
if (!fs.existsSync(TEST_FOLDER + test_name + ".js")) {
errors += 1;
return;
}

var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js/" +
test_name;

var ret = build_docs(out_folder, rustdoc_path, rust_file);
if (ret.length > 0) {
console.error("FAILED");
console.error(ret);
errors += 1;
return;
console.error("==> Missing '" + test_name + ".js' file...");
continue;
}

var [loaded, index] = load_files(out_folder, test_name);
var loadedFile = loadContent(readFile(TEST_FOLDER + file) +
const test_out_folder = out_folder + test_name;

var [loaded, index] = load_files(test_out_folder, test_name);
var loadedFile = loadContent(readFile(TEST_FOLDER + test_name + ".js") +
'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
const expected = loadedFile.EXPECTED;
const query = loadedFile.QUERY;
Expand Down Expand Up @@ -351,7 +327,7 @@ function main(argv) {
} else {
console.log("OK");
}
});
}
return errors;
}

Expand Down

0 comments on commit be23cd9

Please sign in to comment.