summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-04-15 12:55:09 -0500
committerDaniil Baturin <daniil@vyos.io>2024-04-15 18:11:43 +0000
commit867567e0ee4d40a870fffa03aaed4458a08db453 (patch)
tree1fb2b58bc7756864c0e27187c885b2f6a6e94e0e /scripts
parent29288652eaa245ccf7fe591f76460ef228d7dd4d (diff)
downloadvyos-build-867567e0ee4d40a870fffa03aaed4458a08db453.tar.gz
vyos-build-867567e0ee4d40a870fffa03aaed4458a08db453.zip
build: T3664: initialize git vyos-1x submodule before imports
Signed-off-by: Daniil Baturin <daniil@vyos.io>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/image-build/build-vyos-image59
1 files changed, 30 insertions, 29 deletions
diff --git a/scripts/image-build/build-vyos-image b/scripts/image-build/build-vyos-image
index 68b1f743..61431c16 100755
--- a/scripts/image-build/build-vyos-image
+++ b/scripts/image-build/build-vyos-image
@@ -31,14 +31,6 @@ import argparse
import datetime
import functools
-# Add the vyos-1x submodule directory to the Python path
-# so that we can import modules from it.
-VYOS1X_DIR = os.path.join(os.getcwd(), 'vyos-1x/python')
-if not os.path.exists(VYOS1X_DIR):
- print("E: vyos-1x subdirectory does not exist, did you initialize submodules?")
-else:
- sys.path.append(VYOS1X_DIR)
-
# Import third-party modules
try:
import tomli
@@ -49,6 +41,36 @@ except ModuleNotFoundError as e:
print(f"E: Cannot load required library {e}")
print("E: Please make sure the following Python3 modules are installed: tomli jinja2 git psutil")
+# Initialize Git object from our repository
+try:
+ repo = git.Repo('.', search_parent_directories=True)
+ repo.git.submodule('update', '--init')
+
+ # Retrieve the Git commit ID of the repository, 14 charaters will be sufficient
+ build_git = repo.head.object.hexsha[:14]
+ # If somone played around with the source tree and the build is "dirty", mark it
+ if repo.is_dirty():
+ build_git += "-dirty"
+
+ # Retrieve git branch name or current tag
+ # Building a tagged release might leave us checking out a git tag that is not the tip of a named branch (detached HEAD)
+ # Check if the current HEAD is associated with a tag and use its name instead of an unavailable branch name.
+ git_branch = next((tag.name for tag in repo.tags if tag.commit == repo.head.commit), None)
+ if git_branch is None:
+ git_branch = repo.active_branch.name
+except Exception as e:
+ print(f'W: Could not retrieve information from git: {repr(e)}')
+ build_git = ""
+ git_branch = ""
+
+# Add the vyos-1x submodule directory to the Python path
+# so that we can import modules from it.
+VYOS1X_DIR = os.path.join(os.getcwd(), 'vyos-1x/python')
+if not os.path.exists(VYOS1X_DIR):
+ print("E: vyos-1x subdirectory does not exist, did you initialize submodules?")
+else:
+ sys.path.append(VYOS1X_DIR)
+
# Import local modules from scripts/image-build
# They rely on modules from vyos-1x
import utils
@@ -340,27 +362,6 @@ if __name__ == "__main__":
# Assign a (hopefully) unique identifier to the build (UUID)
build_uuid = str(uuid.uuid4())
- # Initialize Git object from our repository
- try:
- repo = git.Repo('.', search_parent_directories=True)
-
- # Retrieve the Git commit ID of the repository, 14 charaters will be sufficient
- build_git = repo.head.object.hexsha[:14]
- # If somone played around with the source tree and the build is "dirty", mark it
- if repo.is_dirty():
- build_git += "-dirty"
-
- # Retrieve git branch name or current tag
- # Building a tagged release might leave us checking out a git tag that is not the tip of a named branch (detached HEAD)
- # Check if the current HEAD is associated with a tag and use its name instead of an unavailable branch name.
- git_branch = next((tag.name for tag in repo.tags if tag.commit == repo.head.commit), None)
- if git_branch is None:
- git_branch = repo.active_branch.name
- except Exception as e:
- print(f'W: Could not retrieve information from git: {repr(e)}')
- build_git = ""
- git_branch = ""
-
# Create the build version string
if build_config['build_type'] == 'development':
try: