summaryrefslogtreecommitdiff
path: root/scripts/build-config
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/build-config')
-rwxr-xr-xscripts/build-config87
1 files changed, 81 insertions, 6 deletions
diff --git a/scripts/build-config b/scripts/build-config
index 7d1aa66b..27a6c7ba 100755
--- a/scripts/build-config
+++ b/scripts/build-config
@@ -1,4 +1,27 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
+#
+# Copyright (C) 2018, VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# File: build-config
+# Purpose:
+# This script serves the same purpose as ./configure in traditional
+# autoconf setups.
+# It takes build configuration options from command line, checks them,
+# builds a config dictionary, augments it with some default and/or
+# computed values and saves it to build/build-config.json
+# for other build scripts to read.
import argparse
import re
@@ -19,28 +42,80 @@ def field_to_option(s):
def get_default_build_by():
return "{user}@{host}".format(user= getpass.getuser(), host=platform.node())
+def get_validator(optdict, name):
+ try:
+ return optdict[name][2]
+ except KeyError:
+ return None
+
+# Options dict format:
+# '$option_name_without_leading_dashes': { ('$help_string', $default_value_generator_thunk, $value_checker_thunk) }
options = {
- 'architecture': ('Image target architecture (amd64 or i586)', lambda: 'amd64', lambda x: x in ['amd64', 'i586']),
- 'build-by': ('Builder identifier (e.g. jrandomhacker@example.net)', get_default_build_by, None)
+ 'architecture': ('Image target architecture (amd64 or i586 or armhf)', lambda: 'amd64', lambda x: x in ['amd64', 'i586', 'armhf']),
+ 'build-by': ('Builder identifier (e.g. jrandomhacker@example.net)', get_default_build_by, None),
+ 'debian-mirror': ('Debian repository mirror for ISO build', lambda: defaults.DEBIAN_MIRROR, None),
+ 'debian-security-mirror': ('Debian security updated mirror', lambda: defaults.DEBIAN_SECURITY_MIRROR, None),
+ 'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', lambda: defaults.DEBIAN_MIRROR, None),
+ 'vyos-mirror': ('VyOS package mirror', lambda: defaults.VYOS_MIRROR, None),
+ 'build-type': ('Build type, release or development', lambda: 'development', lambda x: x in ['release', 'development']),
+ 'version': ('Version number (release builds only)', None, None)
}
# Create the option parser
parser = argparse.ArgumentParser()
for k, v in options.items():
- parser.add_argument('--' + k, type=str, help=v[0], default=v[1]())
+ help_string, default_value_thunk = v[0], v[1]
+ if default_value_thunk is None:
+ parser.add_argument('--' + k, type=str, help=help_string)
+ else:
+ parser.add_argument('--' + k, type=str, help=help_string, default=default_value_thunk())
+
+# The debug option is a bit special since it's different type
+parser.add_argument('--debug', help="Enable debug output", action='store_true')
args = vars(parser.parse_args())
# Validate options
for k, v in args.items():
key = field_to_option(k)
- func = options[key][2]
+ func = get_validator(options, k)
if func is not None:
if not func(v):
print("{v} is not a valid value for --{o} option".format(o=key, v=v))
sys.exit(1)
+# Some fixup for mirror settings.
+# The idea is: if --debian-mirror is specified but --pbuilder-debian-mirror is not,
+# use the --debian-mirror value for both lb and pbuilder bootstrap
+if (args['debian_mirror'] != defaults.DEBIAN_MIRROR) and \
+ (args['pbuilder_debian_mirror'] == defaults.DEBIAN_MIRROR):
+ args['pbuilder_debian_mirror'] = args['debian_mirror']
+
+# Version can only be set for release builds,
+# for dev builds it hardly makes any sense
+if args['build_type'] == 'development':
+ if args['version'] is not None:
+ print("Version can only be set for release builds")
+ print("Use --build-type=release option if you want to set version number")
+ sys.exit(1)
+
+# Populate some defaults that are not configurable,
+# but that are handy to have in the options hash
+args['distribution'] = defaults.DEBIAN_DISTRIBUTION
+args['build_dir'] = os.path.join(os.getcwd(), defaults.BUILD_DIR)
+args['pbuilder_config'] = defaults.PBUILDER_CONFIG
+args['vyos_branch'] = defaults.VYOS_BRANCH
+
+# Check the build environment and dependencies
+env_check_retval = os.system("scripts/check-build-env")
+if env_check_retval > 0:
+ print("Build environment check failed, fix the issues and retry")
+
+
# Save to file
+os.makedirs(defaults.BUILD_DIR, exist_ok=True)
+print("Saving the build config to {0}".format(defaults.BUILD_CONFIG))
with open(defaults.BUILD_CONFIG, 'w') as f:
- json.dump(args, f)
+ json.dump(args, f, indent=4, sort_keys=True)
+ print("\n", file=f)