summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-04-22 15:43:03 +0000
committerChristian Breunig <christian@breunig.cc>2024-05-05 15:12:50 +0200
commit43155713c100f5679ddfe1e4196d950b5ec185ef (patch)
tree80d45cf69fc30cc986e4fe82aab610829ecbbb6d
parent80e03e604a00536c8f15611a180bc0dd18dfe4c7 (diff)
downloadvyos-build-43155713c100f5679ddfe1e4196d950b5ec185ef.tar.gz
vyos-build-43155713c100f5679ddfe1e4196d950b5ec185ef.zip
build: T3664: adjust the vyos-1x submodule path in scripts
(cherry picked from commit ec42af75e0ab468e062add3852c80254d153c021)
-rw-r--r--Makefile2
-rwxr-xr-xscripts/image-build/build-vyos-image67
2 files changed, 39 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index e0a22888..62587ced 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ all:
@echo "The most common target is 'iso'"
%:
- VYOS_TEMPLATE_DIR=`pwd`/vyos-1x/data/templates/ ./build-vyos-image $*
+ VYOS_TEMPLATE_DIR=`pwd`/packages/vyos-1x/data/templates/ ./build-vyos-image $*
.PHONY: checkiso
.ONESHELL:
diff --git a/scripts/image-build/build-vyos-image b/scripts/image-build/build-vyos-image
index 68b1f743..f9544054 100755
--- a/scripts/image-build/build-vyos-image
+++ b/scripts/image-build/build-vyos-image
@@ -30,14 +30,7 @@ import platform
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 string
# Import third-party modules
try:
@@ -49,6 +42,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(), 'packages/vyos-1x/python')
+if not os.path.exists(VYOS1X_DIR):
+ print("E: vyos-1x subdirectory does not exist, did git submodules fail to initialize?")
+else:
+ sys.path.append(VYOS1X_DIR)
+
# Import local modules from scripts/image-build
# They rely on modules from vyos-1x
import utils
@@ -253,6 +276,13 @@ if __name__ == "__main__":
print("Use --build-type=release option if you want to set version number")
sys.exit(1)
+ # Validate characters in version name
+ if 'version' in args and args['version'] != None:
+ allowed = string.ascii_letters + string.digits + '.' + '-' + '+'
+ if not set(args['version']) <= set(allowed):
+ print(f'Version contained illegal character(s), allowed: {allowed}')
+ sys.exit(1)
+
## Inject some useful hardcoded options
args['build_dir'] = defaults.BUILD_DIR
args['pbuilder_config'] = os.path.join(defaults.BUILD_DIR, defaults.PBUILDER_CONFIG)
@@ -340,27 +370,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: