Skip to content

Commit

Permalink
Merge pull request #20322 from ziglang/ci-tidy
Browse files Browse the repository at this point in the history
add -Denable-tidy flag and use it in the CI
  • Loading branch information
andrewrk authored Jun 17, 2024
2 parents fda2458 + 1e9e293 commit 4558996
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
22 changes: 22 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ pub fn build(b: *std.Build) !void {
const skip_install_langref = b.option(bool, "no-langref", "skip copying of langref to the installation prefix") orelse skip_install_lib_files;
const std_docs = b.option(bool, "std-docs", "include standard library autodocs") orelse false;
const no_bin = b.option(bool, "no-bin", "skip emitting compiler binary") orelse false;
const enable_tidy = b.option(bool, "enable-tidy", "Check langref output HTML validity") orelse false;

const langref_file = generateLangRef(b);
const install_langref = b.addInstallFileWithDir(langref_file, .prefix, "doc/langref.html");
const check_langref = tidyCheck(b, langref_file);
if (enable_tidy) install_langref.step.dependOn(check_langref);
// Checking autodocs is disabled because tidy gives a false positive:
// line 304 column 9 - Warning: moved <style> tag to <head>! fix-style-tags: no to avoid.
// I noticed that `--show-warnings no` still incorrectly causes exit code 1.
// I was unable to find an alternative to tidy.
//const check_autodocs = tidyCheck(b, b.path("lib/docs/index.html"));
if (enable_tidy) {
test_step.dependOn(check_langref);
//test_step.dependOn(check_autodocs);
}
if (!skip_install_langref) {
b.getInstallStep().dependOn(&install_langref.step);
}
Expand All @@ -50,6 +62,7 @@ pub fn build(b: *std.Build) !void {
.install_dir = .prefix,
.install_subdir = "doc/std",
});
//if (enable_tidy) install_std_docs.step.dependOn(check_autodocs);
if (std_docs) {
b.getInstallStep().dependOn(&install_std_docs.step);
}
Expand Down Expand Up @@ -1308,3 +1321,12 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
docgen_cmd.addFileArg(b.path("doc/langref.html.in"));
return docgen_cmd.addOutputFileArg("langref.html");
}

fn tidyCheck(b: *std.Build, html_file: std.Build.LazyPath) *std.Build.Step {
const run_tidy = b.addSystemCommand(&.{
"tidy", "--drop-empty-elements", "no", "-qe",
});
run_tidy.addFileArg(html_file);
run_tidy.expectExitCode(0);
return &run_tidy.step;
}
7 changes: 2 additions & 5 deletions ci/aarch64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ stage3-debug/bin/zig build test docs \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"

# Look for HTML errors.
# TODO: move this to a build.zig flag (-Denable-tidy)
tidy --drop-empty-elements no -qe "../zig-out/doc/langref.html"
--zig-lib-dir "$PWD/../lib" \
-Denable-tidy

# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-debug/bin/zig build update-zig1
Expand Down
7 changes: 2 additions & 5 deletions ci/aarch64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ stage3-release/bin/zig build test docs \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"

# Look for HTML errors.
# TODO: move this to a build.zig flag (-Denable-tidy)
tidy --drop-empty-elements no -qe "../zig-out/doc/langref.html"
--zig-lib-dir "$PWD/../lib" \
-Denable-tidy

# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-release/bin/zig build update-zig1
Expand Down
7 changes: 2 additions & 5 deletions ci/x86_64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ stage3-debug/bin/zig build test docs \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"

# Look for HTML errors.
# TODO: move this to a build.zig flag (-Denable-tidy)
tidy --drop-empty-elements no -qe "../zig-out/doc/langref.html"
--zig-lib-dir "$PWD/../lib" \
-Denable-tidy

# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-debug/bin/zig build update-zig1
Expand Down
7 changes: 2 additions & 5 deletions ci/x86_64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ stage3-release/bin/zig build test docs \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"

# Look for HTML errors.
# TODO: move this to a build.zig flag (-Denable-tidy)
tidy --drop-empty-elements no -qe "../zig-out/doc/langref.html"
--zig-lib-dir "$PWD/../lib" \
-Denable-tidy

# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
Expand Down

0 comments on commit 4558996

Please sign in to comment.