Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the error that Zig build system does not fail when a test fails #15078

Closed
wants to merge 6 commits into from

Conversation

chrboesch
Copy link
Contributor

Fixes for: #15009 and #15059

@chrboesch
Copy link
Contributor Author

Double with: #15064

@chrboesch chrboesch closed this Mar 25, 2023
@chrboesch chrboesch deleted the init-exe branch March 25, 2023 21:04
@@ -63,5 +63,5 @@ pub fn build(b: *std.Build) void {
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
test_step.dependOn(&exe_tests.run().step);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think exe_tests.run() is marked as deprecated.

/// Deprecated: use `std.Build.addRunArtifact`

I haven't tested the following, but I think it would be better to have something like

    // Creates a step for unit testing.
    const exe_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    const exe_tests_run = b.addRunArtifact(exe_tests);

    // Similar to creating the run step earlier, this exposes a `test` step to
    // the `zig build --help` menu, providing a way for the user to request
    // running the unit tests.
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&exe_tests_run.step);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right and it works. Should I create a new pull request?

Copy link
Contributor

@travisstaloch travisstaloch Mar 26, 2023

Choose a reason for hiding this comment

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

no reason to create a new one. just amend this commit and force push.

@chrboesch chrboesch restored the init-exe branch March 26, 2023 00:07
@chrboesch chrboesch reopened this Mar 26, 2023
@travisstaloch
Copy link
Contributor

it would be better imo to do this all in one commit. and did you forgot to update the other file too?

@chrboesch
Copy link
Contributor Author

I changed it online because my branch did not longer work :-(

@travisstaloch
Copy link
Contributor

travisstaloch commented Mar 26, 2023

oops nvm. i didn't notice you changed both. LGTM (minus the extra commits)

@perillo
Copy link
Contributor

perillo commented Mar 26, 2023

I changed it online because my branch did not longer work :-(

If you are using an old version of the Zig compiler, you can just build the stage3 compiler, following https://github.com/ziglang/zig/wiki/Contributing#editing-source-code.

@chrboesch
Copy link
Contributor Author

@Vexu Is it possible to merge this so you can use init-exe/init-lib again?

@Vexu
Copy link
Member

Vexu commented Mar 29, 2023

Not with failed checks, I don't know how to help you with that since I can't find a failure in those 5k lines of success.

@kcbanner
Copy link
Contributor

2023-03-26T09:55:08.2511600Z Install the project...
2023-03-26T09:55:08.2617140Z -- Install configuration: "Release"
2023-03-26T10:18:27.6791210Z ++ pwd
2023-03-26T10:18:27.6795520Z + stage3/bin/zig build test docs --zig-lib-dir /Users/runner/work/zig/zig/build/../lib -Denable-macos-sdk -Dstatic-llvm -Dskip-non-native --search-prefix /Users/runner/zig+llvm+lld+clang-x86_64-macos-none-0.11.0-dev.1416+8484df5bd
2023-03-26T10:48:13.6580930Z zig build test: error: run test: error: unexpected errno: 22
2023-03-26T10:48:13.6589520Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/debug.zig:561:19: 0x10d819f48 in writeCurrentStackTrace__anon_12364 (build)
2023-03-26T10:48:13.6615640Z     while (it.next()) |return_address| {
2023-03-26T10:48:13.6774580Z                   ^
2023-03-26T10:48:13.6882090Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/debug.zig:157:80: 0x10d7f01e0 in dumpCurrentStackTrace (build)
2023-03-26T10:48:13.6983360Z         writeCurrentStackTrace(stderr, debug_info, detectTTYConfig(io.getStdErr()), start_addr) catch |err| {
2023-03-26T10:48:13.7084510Z                                                                                ^
2023-03-26T10:48:13.7187300Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/os.zig:5559:40: 0x10d7c09d9 in unexpectedErrno (build)
2023-03-26T10:48:13.7289250Z         std.debug.dumpCurrentStackTrace(null);
2023-03-26T10:48:13.7390370Z                                        ^
2023-03-26T10:48:13.7491610Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/os.zig:2996:49: 0x10d8dacac in fchdir (build)
2023-03-26T10:48:13.7592860Z             else => |err| return unexpectedErrno(err),
2023-03-26T10:48:13.7690880Z                                                 ^
2023-03-26T10:48:13.7794820Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/child_process.zig:587:30: 0x10d8aca2f in spawnPosix (build)
2023-03-26T10:48:13.7896060Z                 os.fchdir(cwd.fd) catch |err| forkChildErrReport(err_pipe[1], err);
2023-03-26T10:48:13.8046670Z                              ^
2023-03-26T10:48:13.8147960Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/child_process.zig:203:35: 0x10d87167c in spawn (build)
2023-03-26T10:48:13.8250130Z             return self.spawnPosix();
2023-03-26T10:48:13.8354330Z                                   ^
2023-03-26T10:48:13.8473070Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Build/RunStep.zig:893:20: 0x10d8854b3 in spawnChildAndCollect (build)
2023-03-26T10:48:13.8574460Z     try child.spawn();
2023-03-26T10:48:13.8677050Z                    ^
2023-03-26T10:48:13.8779460Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Build/RunStep.zig:560:40: 0x10d886119 in runCommand (build)
2023-03-26T10:48:13.8881040Z     const result = spawnChildAndCollect(self, argv, has_side_effects, prog_node) catch |err| term: {
2023-03-26T10:48:13.8983100Z                                        ^
2023-03-26T10:48:13.9084460Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Build/RunStep.zig:488:35: 0x10d8533f0 in make (build)
2023-03-26T10:48:13.9094350Z     try runCommand(self, argv_list.items, has_side_effects, &digest, prog_node);
2023-03-26T10:48:13.9195430Z                                   ^
2023-03-26T10:48:13.9298660Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Build/Step.zig:161:13: 0x10d7c1d3f in make (build)
2023-03-26T10:48:13.9460430Z     s.makeFn(s, prog_node) catch |err| switch (err) {
2023-03-26T10:48:13.9568110Z             ^
2023-03-26T10:48:13.9670510Z /Users/runner/work/zig/zig/build/stage3/lib/zig/build_runner.zig:810:31: 0x10d7c115c in workerMakeOneStep (build)
2023-03-26T10:48:13.9787660Z     const make_result = s.make(&sub_prog_node);
2023-03-26T10:48:13.9888940Z                               ^
2023-03-26T10:48:13.9990890Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Thread/Pool.zig:94:39: 0x10d7994b2 in runFn (build)
2023-03-26T10:48:14.0092350Z             @call(.auto, func, closure.arguments);
2023-03-26T10:48:14.0193770Z                                       ^
2023-03-26T10:48:14.0295040Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Thread/Pool.zig:133:28: 0x10d7bffa0 in worker (build)
2023-03-26T10:48:14.0396170Z             runFn(&run_node.data);
2023-03-26T10:48:14.0497310Z                            ^
2023-03-26T10:48:14.0598620Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Thread.zig:406:13: 0x10d806a4a in callFn__anon_11911 (build)
2023-03-26T10:48:14.0699800Z             @call(.auto, f, args);
2023-03-26T10:48:14.0801010Z             ^
2023-03-26T10:48:14.0902290Z /Users/runner/work/zig/zig/build/stage3/lib/zig/std/Thread.zig:679:30: 0x10d7c097c in entryFn (build)
2023-03-26T10:48:14.1003590Z                 return callFn(f, args_ptr.*);
2023-03-26T10:48:14.1105040Z                              ^
2023-03-26T10:48:14.1206540Z ???:?:?: 0x7fff205778fb in ??? (???)
2023-03-26T10:48:14.1307640Z ???:?:?: 0x7fff20573442 in ??? (???)
2023-03-26T10:48:14.1408740Z ???:?:?: 0x0 in ??? (???)
2023-03-26T10:48:14.1510370Z run test: error: unable to spawn /Users/runner/work/zig/zig/build/zig-local-cache/o/9b4de791705a9ce09114a285ec283527/test: Unexpected
2023-03-26T10:48:14.1612050Z Build Summary: 1/3 steps succeeded; 1 failed (disable with -fno-summary)
2023-03-26T10:48:14.1713200Z test transitive failure
2023-03-26T10:48:14.1814440Z +- run test failure
2023-03-26T10:48:14.1915790Z    +- zig test Debug native success 2s MaxRSS:141M
2023-03-26T10:48:14.2017820Z error: the following build command failed with exit code 1:
2023-03-26T10:48:14.2119770Z /Users/runner/work/zig/zig/build/zig-local-cache/o/0e6780f1199b89faab8dabcdd06f6e3f/build /Users/runner/work/zig/zig/build/stage3/bin/zig /Users/runner/work/zig/zig/build/zig-local-cache/tmp/5c5ad08cfc1284c2 /Users/runner/work/zig/zig/build/zig-local-cache /Users/runner/work/zig/zig/build/zig-global-cache test
2023-03-26T10:48:14.2220950Z 

@chrboesch
Copy link
Contributor Author

As you can see, only the missing lines are added to the two templates init-exe/build.zig and ini-lib/build.zig. Why this leads to a compile check error is beyond me, since these are exclusively templates that are written 1:1 when zig ini-exe or zig init-lib are called.

@chrboesch
Copy link
Contributor Author

But I can start the test again, see if anything changes.

@perillo
Copy link
Contributor

perillo commented Mar 29, 2023

Not with failed checks, I don't know how to help you with that since I can't find a failure in those 5k lines of success.

See #15104 for a simple test that reproduces the problem.

By the way, this and #15064 solve the same issue.

@chrboesch
Copy link
Contributor Author

See #15104 for a simple test that reproduces the problem.

I checked this, but does not reproduces the problem. When I run zig build test in the temp dir it works. But I'm currently looking for this error. It's a problem with the directory when it call from a spawn child.

By the way, this and #15064 solve the same issue.

No, because this solution is allready deprecated: /// Deprecated: use std.Build.addRunArtifact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants