From a1c02b793e264f2b655ae706831221508ba8c52c Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Sun, 6 Feb 2022 13:52:19 -0700 Subject: [PATCH] gen-license.py: Fall back to submodule HEAD file for version info --- scripts/gen-license.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/gen-license.py b/scripts/gen-license.py index 2550410bdf..705f8f96a1 100755 --- a/scripts/gen-license.py +++ b/scripts/gen-license.py @@ -145,10 +145,19 @@ class Submodule: @property def head(self): - head = subprocess.run(['git', 'rev-parse', 'HEAD'], - cwd=self.path, capture_output=True, - check=True) - return head.stdout.decode('utf-8').strip() + try: + return subprocess.run(['git', 'rev-parse', 'HEAD'], + cwd=self.path, capture_output=True, + check=True).stdout.decode('utf-8').strip() + except subprocess.CalledProcessError: + pass + + commit_file_path = os.path.join(self.path, 'HEAD') + if os.path.exists(commit_file_path): + return open(commit_file_path).read().strip() + + raise Exception('Failed to determine submodule revision') + return '' LIBS = [