-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Use goto to exit in build.cmd so that error code propagates out of cmd #990
Conversation
What's the difference between an |
I don't think there's a difference, I guess Santi is basically trying to create a unified choke point for error handling. |
There is a difference if you're within a subroutine or a call. So basically doing goto and then exiting, goto is telling the script to exit the subroutine and then execute |
This Lines 987 to 991 in ccc8c7f
(Based on looking it up--didn't know batch files had this concept.) |
Right. That's the only subroutine call. The weird thing is that if we exit outside of any of these ifs: https://github.com/dotnet/runtime/blob/master/src/coreclr/build.cmd#L528 The exit code is propagated. However if we exit within the if ( ) blocks, then it is not propagated and the calling process (either Powershell or MSBuild) would get an exit code 0. That's why I decided to do a goto, to be in the root of the script, and that indeed fixes the issue. I've tried everything else, I will try and read the script one more time very careful to see why that can be, however, if any of you have any other better ideas I would really appreciate it. |
exit /b 1 | ||
|
||
:ExitWithCode | ||
exit /b !__exitCode! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe document the weird subroutine behavior here, so someone doesn't try to remove it in the future thinking it's just someone trying to do "single return". (And if someone hits a similar issue, maybe they'll see this and get their fix without as much headache.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the expectation of this method that a zero exit code is acceptable? Basically is this explicitly an error routine or a general purpose exit routine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a general purpose exit routine is acceptable. That's why there's also ExitWithError which exits with 1.
@BruceForstall @jkoritzinsky @trylek it seems like the format windows job was already broken but since the exit code wasn't flowing from
|
@safern Are you saying that "goto" from within a call, then calling "exit" will exit the entire script? I don't believe that's how it works. I thought that any |
The formatting job probably needs work to make it work in the new repo. If there's not an issue, we should add one. In particular, it looks like src\jit-format\jit-format.cs in the https://github.com/dotnet/jitutils repo might need work to handle the new
where @erozenfeld Can you look into getting the formatting job to work? |
Sure, I'll fix it tomorrow. |
Thanks @erozenfeld could you cc me on whatever it is needed and let me know whenever it is fixed so I can merge this PR? |
REM ========================================================================================= | ||
REM === These two routines are intended for the exit code to propagate to the parent process | ||
REM === Like MSBuild or Powershell. If we directly exit /b 1 from within a if statement in | ||
REM === any of the routines, the exit code is not propagated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another great item / design principal that we could include in scripting design guideline documents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a doc for those guidelines yet? If not, do we have an issue?
That was already fixed in dotnet/jitutils#227 We had this CMAKE error
for at least 3 years, e.g., see the output here: dotnet/jitutils#64 We get this error when we run It's benign, compile_commands.json file is generated and clang-tidy uses it to run. I'm trying to figure out a way to work around this error. cmake documentation is not very helpful. Will keep digging. |
@janvorli might have ideas... |
Adding
at the end of makes the error disappear. |
Thanks @erozenfeld. I'll include that as part of my PR. |
I added: ceefc5f to fix it. |
If there is a failure in some nested steps of coreclr/build.cmd the exit code was not being propagated due to nested calls and if blocks, instead, go to the end of the script and exit. Because the exit code wasn't propagated, when running
build.cmd
from the root,coreclr.proj
is called and that shells out viaExec
intocoreclr/build.cmd
, and MSBuild was getting a 0 exit code, so the build wouldn't fail if there was a failure. I.e: thesdk.txt
failure which was manifesting latter on the build up when the installer tried to crossgen libraries assemblies.cc: @dotnet/runtime-infrastructure