build-system: sub-package implementation

This commit is contained in:
2024-05-02 17:10:25 +02:00
parent 05dafb461c
commit 9149fd698d
+154 -24
View File
@@ -188,11 +188,13 @@ declare -- opt_debug='no'
declare -- opt_yaml='yes'
declare -- opt_variant=''
declare -- opt_clean_install='no'
declare -- opt_parent_prefix=''
declare -- BUILD_SCRIPT=''
declare -- yaml_config_file=''
declare -a legacy_config_files=()
declare -- module_name=''
declare -- module_type='module'
declare -- echo=':'
parse_args() {
@@ -327,6 +329,16 @@ parse_args() {
shift
fi
;;
--parent-prefix | --parent-prefix=* )
if [[ $1 == *=* ]]; then
opt_parent_prefix=( "${1#--*=}" )
else
opt_parent_prefix=( "$2" )
shift
fi
module_type='sub_package'
pbuild.set_prefix "${opt_parent_prefix}"
;;
-- | '' )
:
;;
@@ -335,9 +347,8 @@ parse_args() {
;;
* )
local -- arg="$1"
local -- tmpvar=$(std::get_abspath "${arg}")
if [[ -r ${tmpvar} ]]; then
BUILD_SCRIPT="${tmpvar}"
if [[ -r ${arg} ]]; then
BUILD_SCRIPT="$(std::get_abspath "${arg}")"
BUILDBLOCK_DIR=$(dirname "${BUILD_SCRIPT}")
elif [[ "${arg}" == */* ]]; then
module_name="${arg%/*}"
@@ -362,7 +373,7 @@ parse_args() {
opt_system="${opt_system:-$(std::get_os_release)}"
# set config file
if [[ ${opt_yaml,,} != 'yes' ]]; then
if [[ ${opt_yaml,,} == 'no' ]]; then
# look for legacy config files
if [[ -n ${opt_config_file} ]]; then
legacy_config_files=( "${opt_config_file}" )
@@ -550,6 +561,16 @@ build_modules_yaml(){
shift 2
local -a with_modules=( $* )
if [[ "${opt_check_mode}" == 'yes' ]]; then
local -- yamllint
if ! which yamllint > /dev/null 2>&1; then
eval $( "${MODULECMD}" bash load yamllint/1.28.0 )
fi
which yamllint > /dev/null 2>&1 || \
std::die 3 "yamllint not found"
yamllint "${yaml_config_file}"
fi
local -- file_fmt=$(get_yaml_file_fmt "${yaml_config_file}")
local -- yaml_mod_config=''
@@ -567,17 +588,45 @@ build_modules_yaml(){
esac
}
# these variables must be export for envsubst(1)
declare -x P=''
declare -x V=''
declare -x V_PKG=''
declare -x V_MAJOR='' # first number in version string
declare -x V_MINOR='' # second number in version string (or empty)
declare -x V_PATCHLVL='' # third number in version string (or empty)
declare -x V_RELEASE='' # module release (or empty)
#......................................................................
#
# Initialise environment modules.
#
# Arguments:
# none
#
init_module_environment(){
eval $( "${MODULECMD}" bash use unstable )
eval $( "${MODULECMD}" bash use deprecated )
eval $( "${MODULECMD}" bash purge )
declare -A SHASUMS=()
declare -a MODULE_DOCFILES=()
# :FIXME: this is a hack!!!
# shouldn't this be set in the build-script?
if [[ -e "${PMODULES_HOME%%/Tools*}/Libraries" ]]; then
eval $( "${MODULECMD}" bash use Libraries )
fi
if [[ -e "${PMODULES_HOME%%/Tools*}/System" ]]; then
eval $( "${MODULECMD}" bash use System )
fi
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset CPP_INCLUDE_PATH
unset LIBRARY_PATH
unset LD_LIBRARY_PATH
unset DYLD_LIBRARY_PATH
unset CFLAGS
unset CPPFLAGS
unset CXXFLAGS
unset LIBS
unset LDFLAGS
unset CC
unset CXX
unset FC
unset F77
unset F90
}
parse_version() {
local v="$1"
@@ -623,11 +672,24 @@ parse_version() {
fi
VERSIONS+=( ${V_MAJOR} )
}
# these variables must be export for envsubst(1)
declare -x P=''
declare -x V=''
declare -x V_PKG=''
declare -x V_MAJOR='' # first number in version string
declare -x V_MINOR='' # second number in version string (or empty)
declare -x V_PATCHLVL='' # third number in version string (or empty)
declare -x V_RELEASE='' # module release (or empty)
declare -A SHASUMS=()
declare -a MODULE_DOCFILES=()
declare -A Yaml_valid_keys_for_module=(
['defaults']=1 # !!map
['shasums']=1 # !!map
['versions']=1 # !!int
['defaults']=1
['shasums']=1
['type']=1
['versions']=1
)
declare -A Yaml_default_config=(
@@ -649,6 +711,7 @@ declare -A Yaml_default_config=(
["script"]='build' # !!str
["suffix"]='' # !!str
["systems"]='' # !!seq of strings
["sub_packages"]='' # !!map
["urls"]='' # !!map
["variant"]='' # !!str
)
@@ -724,8 +787,8 @@ build_modules_yaml_v1(){
local -- yaml_input="$1"
local -n cfg="$2" # ref. to return configuration
local -n dfl="$3" # ref. to defaults
local -- key
local -- value
local -- key=''
local -- value=''
for key in "${!dfl[@]}"; do
cfg[${key}]="${dfl[${key}]}"
@@ -739,7 +802,6 @@ build_modules_yaml_v1(){
keys=( $( ${yq} -e ".|keys().[]" <<<"${yaml_input}" 2>/dev/null )) || \
std::die 3 "Oops: retrieving keys from:\n${yaml_input}"
debug "config keys: ${keys[@]}"
local -- type;
for key in "${keys[@]}"; do
[[ -v dfl[${key,,}] ]] || \
std::die 3 "%s -- %s\n%s" \
@@ -802,7 +864,7 @@ build_modules_yaml_v1(){
;;
esac
;;
urls )
urls | sub_packages )
get_value "${yaml_input}" value "${key}" '!!seq'
cfg[${key,,}]="${value}"
;;
@@ -1151,7 +1213,6 @@ build_modules_yaml_v1(){
l=$( ${yq} -Ne e '.|length' <<<"${yaml}" 2>/dev/null) || \
std::die 3 "error parsing YAML configuration"
local -i i=0
local -- fname=''
local -- url_yaml=''
for ((i=0; i<l; i++)); do
url_yaml=$(${yq} -Ne e ".[$i]" <<<"${yaml}" 2>/dev/null) || \
@@ -1159,6 +1220,8 @@ build_modules_yaml_v1(){
local url=''
local fname=''
local strip_dirs=''
local key=''
local value=''
while read key value; do
key=${key:0:-1}
case "${key}" in
@@ -1199,6 +1262,57 @@ build_modules_yaml_v1(){
pbuild.add_patch_files "${args[@]}"
}
build_sub_packages(){
local -- yaml="$1"
local -i l=0
l=$( ${yq} -Ne e '.|length' <<<"${yaml}" 2>/dev/null) || \
std::die 3 "error parsing YAML configuration"
local -i i=0
local -- fname=''
local -- pkgs_yaml=''
for ((i=0; i<l; i++)); do
pkgs_yaml=$(${yq} -Ne e ".[$i]" <<<"${yaml}" 2>/dev/null) || \
std::die 3 "error parsing YAML configuration"
local -- pkg_name=''
local -- pkg_version=''
local -a pkg_build_args=()
local -a keys=()
keys=( $( ${yq} -e ".|keys().[]" <<<"${pkgs_yaml}" 2>/dev/null )) || \
std::die 3 "Oops: retrieving keys from:\n${yaml_input}"
local -- key=''
for key in "${keys[@]}"; do
case ${key,,} in
'name' )
get_value "${pkgs_yaml}" pkg_name "${key}" '!!str'
;;
'version' )
get_value "${pkgs_yaml}" pkg_version "${key}" '!!str'
;;
'build_args' )
local -- value=''
get_seq "${pkgs_yaml}" value "${key}"
readarray -t pkg_build_args <<< "${value}"
;;
* )
std::die 3 "%s -- %s\n%s" \
"Invalid key in configuration" \
"${key}" "${yaml_input}"
;;
esac
done
[[ "${opt_verbose}" == 'yes' ]] && \
pkg_build_args+=( '--verbose' )
[[ "${opt_debug}" == 'yes' ]] && \
pkg_build_args+=( '--debug' )
[[ "${opt_force_rebuild}" == 'yes' ]] && \
pkg_build_args+=( '-f' )
pkg_build_args+=( "--parent-prefix=${PREFIX}" )
"$BUILDBLOCK_DIR/build-${pkg_name}" \
"${pkg_name}/${pkg_version}" \
"${pkg_build_args[@]}"
done
}
build_modules_variant(){
local -- module_name="$1"
local -- module_version="$2"
@@ -1287,6 +1401,7 @@ build_modules_yaml_v1(){
"${module_version}" \
module_config \
"${runtime_deps[@]}" "${build_requires[@]}"
build_sub_packages "${module_config['sub_packages']}"
}
expand_version_key(){
@@ -1332,8 +1447,23 @@ build_modules_yaml_v1(){
SHASUMS[${key//:}]="${value}"
done <<<"${yaml_input}"
fi
if [[ -v used_keys['type'] ]]; then
local -- value=''
get_value "${yaml_mod_config}" value 'type' '!!str'
case "${value,,}" in
'module' )
[[ "${module_type}" == 'sub_package' ]] && \
std::die 3 "Module type is 'module' but was called as 'sub_package'!"
;;
'sub_package' )
[[ "${module_type}" == 'module' ]] && \
std::die 3 "Module type is 'sub_package' but was called as 'module'!"
;;
* )
std::die 3 "Invalid module type -- '${value}'!"
;;
esac
fi
get_matching_version_keys version_keys "${version}" <<<"${yaml_mod_config}"
for version_key in "${version_keys[@]}"; do
local yaml_vk_config=$(get_yaml_vk_config "${version_key}" <<<"${yaml_mod_config}")