Skip to content

Commit

Permalink
Warn about uncommitted files in final summary
Browse files Browse the repository at this point in the history
Too many times rebuilds have gone unnoticed because the per package
warning gets lost in the debug output. This tries to improve the issue
by adding a summary at the end with the list of directories containing
untracked files.
  • Loading branch information
ktf committed Oct 9, 2023
1 parent 066bb09 commit aefbe97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions alibuild_helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def hash_local_changes(directory):
If there are untracked files, this function returns a unique hash to force a
rebuild, and logs a warning, as we cannot detect changes to those files.
"""
untrackedFilesDirectories = []
class UntrackedChangesError(Exception):
"""Signal that we cannot detect code changes due to untracked files."""
h = Hasher()
Expand All @@ -291,6 +292,7 @@ def hash_output(msg, args):
debug("Command %s returned %d", cmd, err)
dieOnError(err, "Unable to detect source code changes.")
except UntrackedChangesError:
untrackedFilesDirectories = [directory]
warning("You have untracked changes in %s, so aliBuild cannot detect "
"whether it needs to rebuild the package. Therefore, the package "
"is being rebuilt unconditionally. Please use 'git add' and/or "
Expand All @@ -299,7 +301,7 @@ def hash_output(msg, args):
# and let CMake figure out what needs to be rebuilt. Force a rebuild by
# changing the hash to something basically random.
h(str(time.time()))
return h.hexdigest()
return (h.hexdigest(), untrackedFilesDirectories)


def better_tarball(spec, old, new):
Expand Down Expand Up @@ -473,6 +475,10 @@ def doBuild(args, parser):

# Clone/update repos
update_git_repos(args, specs, buildOrder, develPkgs)
# This is the list of packages which have untracked files in their
# source directory, and which are rebuilt every time. We will warn
# about them at the end of the build.
untrackedFilesDirectories = []

# Resolve the tag to the actual commit ref
for p in buildOrder:
Expand Down Expand Up @@ -509,7 +515,9 @@ def doBuild(args, parser):
# Devel package: we get the commit hash from the checked source, not from remote.
out = git(("rev-parse", "HEAD"), directory=spec["source"])
spec["commit_hash"] = out.strip()
spec["devel_hash"] = spec["commit_hash"] + hash_local_changes(spec["source"])
local_hash, untracked = hash_local_changes(spec["source"])
untrackedFilesDirectories.extend(untracked)
spec["devel_hash"] = spec["commit_hash"] + local_hash
out = git(("rev-parse", "--abbrev-ref", "HEAD"), directory=spec["source"])
if out == "HEAD":
out = git(("rev-parse", "HEAD"), directory=spec["source"])[:10]
Expand Down Expand Up @@ -1153,5 +1161,8 @@ def doBuild(args, parser):
for x in develPkgs:
banner("Build directory for devel package %s:\n%s/BUILD/%s-latest%s/%s",
x, abspath(args.workDir), x, "-"+args.develPrefix if "develPrefix" in args else "", x)
for x in untrackedFilesDirectories:
banner("Untracked files in the following directories resulted in a rebuild of "

Check warning on line 1165 in alibuild_helpers/build.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/build.py#L1165

Added line #L1165 was not covered by tests
"the associated package and its dependencies:\n%s\n\nPlease commit or remove them to avoid useless rebuilds.", "\n".join(untrackedFilesDirectories))
debug("Everything done")
return 0
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ allowlist_externals =
sh
git
test
touch
deps =
py27: mock
coverage
Expand Down Expand Up @@ -101,6 +102,10 @@ commands =
# Test for devel packages
coverage run --source={toxinidir} -a {toxinidir}/aliBuild init zlib
coverage run --source={toxinidir} -a {toxinidir}/aliBuild --aggressive-cleanup --docker -a slc7_x86-64 --always-prefer-system -d build zlib
# Test that we complain if we have a devel package with an untracked file
coverage run --source={toxinidir} -a {toxinidir}/aliBuild init ZeroMQ
touch ZeroMQ/foo
coverage run --source={toxinidir} -a {toxinidir}/aliBuild --aggressive-cleanup --docker -a slc7_x86-64 --always-prefer-system -d build ZeroMQ

[coverage:run]
branch = True
Expand Down

0 comments on commit aefbe97

Please sign in to comment.