mirror of
https://github.com/vyos/vyos-build.git
synced 2025-10-01 20:28:40 +02:00
build: T3664: initialize git vyos-1x submodule before imports
Signed-off-by: Daniil Baturin <daniil@vyos.io>
This commit is contained in:
parent
29288652ea
commit
867567e0ee
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user