Infinite loop when installing Buck if not in VCS repository root
Created by: elldritch
When buck
is installed in a folder that's not either a Git or Mercurial repository root, the installer goes into an infinite loop.
To reproduce:
git clone --depth 1 https://github.com/facebook/buck.git
cd buck
mv .git .git-bak
ant
This will cause the build to hang at the gen-buck-info
step.
Root cause
The root cause here is a bug in how programs/gen_buck_info.py
attempts to detect the repository root. Here's the relevant excerpt: https://github.com/facebook/buck/blob/c5272997533a308face95d34e1e4a223691dd687/programs/gen_buck_info.py#L49-L63
If the current working directory is not a VCS repository root, the while
loop on line 54 attempts to traverse upwards in the filesystem until it either finds a VCS repository root (vcs_module is not None
) or reaches the filesystem root (os.path.dirname(path) == path
).
However, when trying to find the VCS repository, an inner loop also attempts to find the Buck repository root by searching for a .buckconfig
. This inner loop does NOT check that it stops at the filesystem root, and will loop infinitely if it does not find a .buckconfig
.
When running ant
in a directory that's not a VCS repository root, programs/gen_buck_info.py
will:
- Search the current working directory for a
.buckconfig
, and find the.buckconfig
(line 55). - Search the current working directory for a VCS repository root, and fail to find one (lines 57-60).
- Mutate the search path to the current path's parent (lines 61-63).
- Search the parent for a
.buckconfig
, and fail to find one (line 55). - Loop infinitely while searching parent folders for a
.buckconfig
(lines 55-56).
The fix
This code appears to be checking for a VCS in order to infer a Buck version from the VCS history. I'm not sure why it checks for a .buckconfig
- perhaps to try and ensure that the VCS repository is also the Buck repository?
I'm happy to submit a PR to fix this, but would like some guidance in the correct behaviour here. I think the right answer is to remove the .buckconfig
check in lines 55-56, because the existence of a .buckconfig
doesn't really tell you anything about whether the repository is the "correct" one to be getting a version from.