From 24ae176d91bcce733c1b4ee24dd58af4ec091c36 Mon Sep 17 00:00:00 2001 From: Loko Kung Date: Tue, 5 Apr 2022 20:11:43 +0000 Subject: [PATCH] Fix commit build rule to use empty hash (and not throw error) if git is not available. Bug: dawn:549 Change-Id: I75ab6eb0273ddcb2dc571d5c91d35422793fdffc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/85745 Reviewed-by: Austin Eng Commit-Queue: Loko Kung --- generator/dawn_version_generator.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/generator/dawn_version_generator.py b/generator/dawn_version_generator.py index 462cb31e1f..1907e88da4 100644 --- a/generator/dawn_version_generator.py +++ b/generator/dawn_version_generator.py @@ -28,11 +28,17 @@ def get_gitHash(dawnDir): cwd=dawnDir) if result.returncode == 0: return result.stdout.decode('utf-8').strip() + # No hash was available (possibly) because the directory was not a git checkout. Dawn should + # explicitly handle its absenece and disable features relying on the hash, i.e. caching. return '' def get_gitHead(dawnDir): - return [os.path.join(dawnDir, '.git', 'HEAD')] + return os.path.join(dawnDir, '.git', 'HEAD') + + +def gitExists(dawnDir): + return os.path.exists(get_gitHead(dawnDir)) def unpackGitRef(packed, resolved): @@ -89,8 +95,10 @@ class DawnVersionGenerator(Generator): help='The Dawn root directory path to use') def get_dependencies(self, args): - dawn_dir = os.path.abspath(args.dawn_dir) - return get_gitHead(dawn_dir) + get_gitResolvedHead(dawn_dir) + dawnDir = os.path.abspath(args.dawn_dir) + if gitExists(dawnDir): + return [get_gitHead(dawnDir)] + get_gitResolvedHead(dawnDir) + return [] def get_file_renders(self, args): params = compute_params(args)