Skip to content

Commit be23cd9

Browse files
Move documentation build into bootstrap
1 parent aa3ca32 commit be23cd9

File tree

2 files changed

+58
-46
lines changed

2 files changed

+58
-46
lines changed

src/bootstrap/test.rs

+41-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! our CI.
55
66
use std::env;
7-
use std::ffi::OsString;
7+
use std::ffi::{OsStr, OsString};
88
use std::fmt;
99
use std::fs;
1010
use std::iter;
@@ -639,14 +639,50 @@ impl Step for RustdocJSNotStd {
639639

640640
fn run(self, builder: &Builder) {
641641
if let Some(ref nodejs) = builder.config.nodejs {
642-
let mut command = Command::new(nodejs);
643-
command.args(&["src/tools/rustdoc-js/tester.js",
644-
&*self.host,
645-
builder.top_stage.to_string().as_str()]);
646642
builder.ensure(crate::doc::Std {
647643
target: self.target,
648644
stage: builder.top_stage,
649645
});
646+
647+
let mut tests_to_run = Vec::new();
648+
let out = Path::new("build").join(&*self.host)
649+
.join(&format!("stage{}",
650+
builder.top_stage.to_string().as_str()))
651+
.join("tests")
652+
.join("rustdoc-js");
653+
654+
if let Ok(it) = fs::read_dir("src/test/rustdoc-js/") {
655+
for entry in it {
656+
if let Ok(entry) = entry {
657+
let path = entry.path();
658+
if path.extension() != Some(&OsStr::new("rs")) || !path.is_file() {
659+
continue
660+
}
661+
let path_clone = path.clone();
662+
let file_stem = path_clone.file_stem().expect("cannot get file stem");
663+
let out = out.join(file_stem);
664+
let mut cmd = builder.rustdoc_cmd(self.host);
665+
cmd.arg("-o");
666+
cmd.arg(out);
667+
cmd.arg(path);
668+
if if builder.config.verbose_tests {
669+
try_run(builder, &mut cmd)
670+
} else {
671+
try_run_quiet(builder, &mut cmd)
672+
} {
673+
tests_to_run.push(file_stem.to_os_string());
674+
}
675+
}
676+
}
677+
}
678+
assert!(!tests_to_run.is_empty(), "no rustdoc-js test generated...");
679+
680+
tests_to_run.insert(0, "src/tools/rustdoc-js/tester.js".into());
681+
tests_to_run.insert(1, out.into());
682+
683+
let mut command = Command::new(nodejs);
684+
command.args(&tests_to_run);
685+
650686
builder.run(&mut command);
651687
} else {
652688
builder.info(

src/tools/rustdoc-js/tester.js

+17-41
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,6 @@ function lookForEntry(entry, data) {
220220
return null;
221221
}
222222

223-
function build_docs(out_dir, rustdoc_path, file_to_document) {
224-
var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]);
225-
var s = '';
226-
if (c.error || c.stderr.length > 0) {
227-
if (c.stderr.length > 0) {
228-
s += '==> STDERR: ' + c.stderr + '\n';
229-
}
230-
s += '==> ERROR: ' + c.error;
231-
}
232-
return s;
233-
}
234-
235223
function load_files(out_folder, crate) {
236224
var mainJs = readFile(out_folder + "/main.js");
237225
var ALIASES = readFile(out_folder + "/aliases.js");
@@ -266,44 +254,32 @@ function load_files(out_folder, crate) {
266254
}
267255

268256
function main(argv) {
269-
if (argv.length !== 4) {
270-
console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]");
257+
if (argv.length < 4) {
258+
console.error("USAGE: node tester.js OUT_FOLDER [TESTS]");
271259
return 1;
272260
}
273-
const toolchain = argv[2];
274-
const stage = argv[3];
275-
const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc';
261+
if (argv[2].substr(-1) !== "/") {
262+
argv[2] += "/";
263+
}
264+
const out_folder = argv[2];
276265

277266
var errors = 0;
278267

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

287-
if (!fs.existsSync(rust_file)) {
288-
console.error("FAILED");
289-
console.error("==> Missing '" + test_name + ".rs' file...");
271+
process.stdout.write('Checking "' + test_name + '" ... ');
272+
if (!fs.existsSync(TEST_FOLDER + test_name + ".js")) {
290273
errors += 1;
291-
return;
292-
}
293-
294-
var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js/" +
295-
test_name;
296-
297-
var ret = build_docs(out_folder, rustdoc_path, rust_file);
298-
if (ret.length > 0) {
299274
console.error("FAILED");
300-
console.error(ret);
301-
errors += 1;
302-
return;
275+
console.error("==> Missing '" + test_name + ".js' file...");
276+
continue;
303277
}
304278

305-
var [loaded, index] = load_files(out_folder, test_name);
306-
var loadedFile = loadContent(readFile(TEST_FOLDER + file) +
279+
const test_out_folder = out_folder + test_name;
280+
281+
var [loaded, index] = load_files(test_out_folder, test_name);
282+
var loadedFile = loadContent(readFile(TEST_FOLDER + test_name + ".js") +
307283
'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
308284
const expected = loadedFile.EXPECTED;
309285
const query = loadedFile.QUERY;
@@ -351,7 +327,7 @@ function main(argv) {
351327
} else {
352328
console.log("OK");
353329
}
354-
});
330+
}
355331
return errors;
356332
}
357333

0 commit comments

Comments
 (0)