2020-12-28 02:48

Build fails with weird errors if git is not on path

From -karas on February 13, 2018 15:31

Running the build.cmd script (on Windows) from VS development environment without having git on path fails the build in a really weird way which is hard to figure out. If this happens the error reported is:

E:\coreclr\bin\obj\_version.h(19): error RC2001: newline in constant [E:\coreclr\bin\obj\Windows_NT.x86.Debug\src\tools

Looking into this the _version.h has a line like this:

#define VER_PRODUCTVERSION_STR      "4.6.26211.0 : vitkaras-VITKARASD : 'git' is not recognized as an internal or external command,
operable program or batch file."

If the build really needs git (which in this case it could put some string instead into the version), then it should fail up front with a clear error message. Currently it fails during compilation and keeps on trying to compile and so on.

Copied from original issue: dotnet/coreclr#16356


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39799825 weixin_39799825 4月前

    From on February 13, 2018 20:53

    maybe this was the issue you were hitting..

    点赞 评论 复制链接分享
  • weixin_39799825 weixin_39799825 4月前

    I would prefer to see if we can remove the git dependency by using gitattributes. For example, the commit hash can be gotten with ident. I think the branch name could be gotten as well with a bit more work, but I haven't worked through it completely.

    点赞 评论 复制链接分享
  • weixin_40005887 weixin_40005887 4月前

    I see these used in the build, but there are others in the .targets files.

    git rev-parse --abbrev-ref HEAD 
    git rev-parse HEAD 
    git show -s --format=%cd --date=short HEAD

    On my Windows box it just says

      'git' is not recognized as an internal or external command,
      operable program or batch file.

    but then carries on regardless.

    Is there much value in eliminating a git dependency? It could regress periodically.

    点赞 评论 复制链接分享
  • weixin_39799825 weixin_39799825 4月前

    What I'm proposing is in some sense not removing the Git dependency. It's just unifying it with the other dependency we already have--synch'ing the source tree with the remote. Git supports adding information like above to "meta-files" in the tree via variable substitution or other means. Then, at build time, rather than having to invoke Git, the info we need looks like it was checked in because it is generated at the same time Git last updated the tree.

    The advantage is conceptually similar to the advantage of being able to restore everything necessary for the build and then drop the network dependency from that point forward. I acknowledge that dropping the Git dependency is less valuable given the pervasiveness of Git, but you could for example imagine someone expecting to use VS's Git client only without installing the official Git CLI.

    I don't object to fixing this just by warning or erroring if the command fails, but I think there's a cleaner solution. I don't think it's more likely to regress if implemented properly.

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 4月前

    In repo root, if you try cat .git/FETCH_HEAD, most likely it will list the current branch and hash etc.

    点赞 评论 复制链接分享
  • weixin_39717110 weixin_39717110 4月前

    This will probably be fixed by https://github.com/dotnet/buildtools/issues/1980 "Add graceful error handling to Git branch fetch" which I'm planning to do soon to remove a workaround in the dotnet/source-build repo. The plan is basically to start caring about the exit code, so it should catch this case.

    点赞 评论 复制链接分享
  • weixin_39717110 weixin_39717110 4月前

    This was fixed in https://github.com/dotnet/buildtools/pull/1977. (Thanks !) CoreCLR and CoreFX master got buildtools updates in the last few days, so they should have it.

    I ran a clean CoreCLR build on linux with git renamed to git_. It logged git: command not found', and created version files that just didn't try to include the branch.

    点赞 评论 复制链接分享