]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
build/config-submenu.sh: Replace scripts/uk_build_configure.sh
authorSimon Kuenzer <simon@unikraft.io>
Thu, 27 Jul 2023 20:38:41 +0000 (22:38 +0200)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 10:21:30 +0000 (10:21 +0000)
This commit introduces a replacement for `build/config-submenu.sh`. The
main reason for the rewrite was the incompatibilities on Darwin. The new
script mainly uses `bash`-internal functions to avoid incompatibilities
with third-party commands called by the script.

Checkpatch-Ignore: LONG_LINE_STRING
Checkpatch-Ignore: LONG_LINE
Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Alexander Jung <alex@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1034

Config.uk
Makefile
support/build/config-submenu.sh [new file with mode: 0755]
support/scripts/uk_build_configure.sh [deleted file]

index 4807f1721858fea769e67a44849eb5f1e7ce401e..3cedd3a5aa3d2e38f2abbf3edba435709aec401f 100644 (file)
--- a/Config.uk
+++ b/Config.uk
@@ -34,13 +34,17 @@ menu "Architecture Selection"
 endmenu
 
 menu "Platform Configuration"
-       source "$(shell,$(UK_BASE)/support/scripts/uk_build_configure.sh -p '$(KCONFIG_PLAT_DIR)' -o '$(KCONFIG_PLAT_IN)')"
+       source "$(shell,$(UK_BASE)/support/build/config-submenu.sh -q -o '$(KCONFIG_PLAT_IN)' -r '$(KCONFIG_PLAT_BASE)' -l '$(KCONFIG_PLAT_BASE)' -c '$(KCONFIG_EPLAT_DIRS)')"
 endmenu
 
 menu "Library Configuration"
-       source "$(shell,$(UK_BASE)/support/scripts/uk_build_configure.sh -e '$(KCONFIG_LIB_DIR)' -o '$(KCONFIG_LIB_IN)')"
+       source "$(shell,$(UK_BASE)/support/build/config-submenu.sh -q -o '$(KCONFIG_LIB_IN)' -r '$(KCONFIG_LIB_BASE)' -l '$(KCONFIG_LIB_BASE)' -c '$(KCONFIG_ELIB_DIRS)')"
 endmenu
 
+if !NO_APP
+       source "$(shell,$(UK_BASE)/support/build/config-submenu.sh -q -o '$(KCONFIG_APP_IN)' -t "Application Options" -l '$(KCONFIG_EAPP_DIR)')"
+endif
+
 menu "Build Options"
 choice
        prompt "Optimization level"
@@ -212,12 +216,6 @@ config LLVM_TARGET_ARCH
 #        system.
 endmenu
 
-if !NO_APP
-       menu "Application Options"
-               source "$(shell,$(UK_BASE)/support/scripts/uk_build_configure.sh -a '$(KCONFIG_APP_DIR)')"
-       endmenu
-endif
-
 config UK_NAME
        string "Image name"
        default UK_DEFNAME
index 240c0236d96b6eb3c22837e548c791a835e86038..51141c9db3291efeb9862a4d3efa7396175c63b8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -233,16 +233,18 @@ UK_FIXDEP             := $(KCONFIG_DIR)/fixdep
 KCONFIG_AUTOCONFIG    := $(KCONFIG_DIR)/auto.conf
 KCONFIG_TRISTATE      := $(KCONFIG_DIR)/tristate.config
 KCONFIG_AUTOHEADER    := $(KCONFIG_INCLUDES_DIR)/config.h
-KCONFIG_APP_DIR       := $(CONFIG_UK_APP)
 KCONFIG_LIB_IN        := $(KCONFIG_DIR)/libs.uk
-KCONFIG_DEF_PLATS     := $(shell find $(CONFIG_UK_PLAT)/* -maxdepth 0 \
-                          -type d \( -path $(CONFIG_UK_PLAT)/common -o \
-                          -path $(CONFIG_UK_PLAT)/drivers \
-                          \) -prune -o  -type d -print)
-KCONFIG_LIB_DIR       := $(shell find $(CONFIG_UK_LIB)/* -maxdepth 0 -type d) \
-                        $(CONFIG_UK_BASE)/lib $(ELIB_DIR)
-KCONFIG_PLAT_DIR      := $(KCONFIG_DEF_PLATS) $(EPLAT_DIR) $(CONFIG_UK_PLAT)
-KCONFIG_PLAT_IN       := $(KCONFIG_DIR)/plat.uk
+KCONFIG_LIB_BASE      := $(CONFIG_UK_BASE)/lib
+KCONFIG_ELIB_DIRS     := $(L)
+KCONFIG_PLAT_IN       := $(KCONFIG_DIR)/plats.uk
+KCONFIG_PLAT_BASE     := $(CONFIG_UK_BASE)/plat
+KCONFIG_EPLAT_DIRS    := $(E)
+KCONFIG_APP_IN        := $(KCONFIG_DIR)/app.uk
+ifneq ($(CONFIG_UK_BASE),$(CONFIG_UK_APP))
+KCONFIG_EAPP_DIR      := $(CONFIG_UK_APP)
+else
+KCONFIG_EAPP_DIR      :=
+endif
 
 # Makefile support scripts
 SCRIPTS_DIR := $(CONFIG_UK_BASE)/support/scripts
@@ -881,11 +883,14 @@ COMMON_CONFIG_ENV = \
        UK_FULLVERSION="$(UK_FULLVERSION)" \
        UK_CODENAME="$(UK_CODENAME)" \
        UK_ARCH="$(CONFIG_UK_ARCH)" \
-       KCONFIG_APP_DIR="$(KCONFIG_APP_DIR)" \
-       KCONFIG_LIB_DIR="$(KCONFIG_LIB_DIR)" \
        KCONFIG_LIB_IN="$(KCONFIG_LIB_IN)" \
-       KCONFIG_PLAT_DIR="$(KCONFIG_PLAT_DIR)" \
+       KCONFIG_LIB_BASE="$(KCONFIG_LIB_BASE)" \
+       KCONFIG_ELIB_DIRS="$(KCONFIG_ELIB_DIRS)" \
        KCONFIG_PLAT_IN="$(KCONFIG_PLAT_IN)" \
+       KCONFIG_PLAT_BASE="$(KCONFIG_PLAT_BASE)" \
+       KCONFIG_EPLAT_DIRS="$(KCONFIG_EPLAT_DIRS)" \
+       KCONFIG_APP_IN="$(KCONFIG_APP_IN)" \
+       KCONFIG_EAPP_DIR="$(KCONFIG_EAPP_DIR)" \
        UK_NAME="$(CONFIG_UK_NAME)"
 
 PHONY += scriptconfig scriptsyncconfig iscriptconfig kmenuconfig guiconfig \
diff --git a/support/build/config-submenu.sh b/support/build/config-submenu.sh
new file mode 100755 (executable)
index 0000000..3eb3426
--- /dev/null
@@ -0,0 +1,137 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2023, Unikraft GmbH and the Unikraft Authors.
+# Licensed under the BSD-3-Clause License (the "License").
+# You may not use this file except in compliance with the License.
+IFS_ORIG=$IFS
+IFS_NL=$'\n'
+
+usage()
+{
+       echo "Usage: $0 [OPTION]... [LIBRARY PATH]..."
+       echo "Generates a KConfig submenu by looping over Config.uk files"
+       echo ""
+       echo "  -h                         Display help and exit"
+       echo "  -q                         Quiet, do not print warnings to STDERR"
+       echo "  -t [TEXT]                  Generates a submenu with TEXT as title"
+       echo "  -l [PATH]                  Library directory"
+       echo "  -c [PATH:PATH:...]         Colon separated list of library directories"
+       echo "  -r [PATH]                  Search for library directories in subfolders"
+       echo "  -o [PATH]                  Write to output file instead of STDOUT"
+}
+
+ARG_OUT=
+ARG_PATHS=()
+ARG_TITLE=
+OPT_MODE="concat"
+OPT_QUIET=1
+while getopts :hqt:l:r:c:o: OPT; do
+       case ${OPT} in
+       h)
+               usage
+               exit 0
+               ;;
+       q)
+               OPT_QUIET=0
+               ;;
+       t)
+               ARG_TITLE="${OPTARG}"
+               OPT_MODE="menu"
+               ;;
+       l)
+               ARG_PATHS+=("${OPTARG}")
+               ;;
+       r)
+               if [ ! -z "${OPTARG}" ]; then
+                       for P in "${OPTARG}/"*; do
+                               [ -d "${P}" ] && ARG_PATHS+=("${P}")
+                       done
+               fi
+               ;;
+       c)
+               IFS=':'
+               for P in ${OPTARG}; do
+                       IFS=$IFS_ORIG
+                       ARG_PATHS+=("${P}")
+                       IFS=$IFS_NL
+               done
+               IFS=$IFS_ORIG
+               ;;
+       o)
+               ARG_OUT=("${OPTARG}")
+               ;;
+       \?)
+               echo "Unrecognized option -${OPTARG}" 1>&2
+               usage 1>&2
+               exit 1
+               ;;
+       esac
+done
+shift $(( OPTIND - 1 ))
+
+#
+# Handling OUTPUT
+#
+if [ ! -z "$ARG_OUT" ]; then
+       if [ -e "$ARG_OUT" -a ! -f "$ARG_OUT" ]; then
+               echo "$ARG_OUT already exists but is not a regular file" 1>&2
+               exit 2
+       fi
+       [ -f "$ARG_OUT" ] && rm -f "$ARG_OUT"
+
+       # open fd:7
+       exec 7<>"$ARG_OUT"
+       if [ $? -ne 0 ]; then
+               echo "Failed to open $ARG_OUT as output file" 1>&2
+               exit 1
+       fi
+
+       printf '# Auto generated file. DO NOT EDIT\n' >&7
+else
+       # duplicate stdout to fd:7
+       exec >&7
+fi
+
+#
+# HEADER
+#
+case "${OPT_MODE}" in
+       menu)
+               printf "menu \"%s\"\n" "${ARG_TITLE}" >&7
+               ;;
+       *)
+               ;;
+esac
+
+#
+# BODY
+#
+for ARG_PATH in "${ARG_PATHS[@]}" "$@"; do
+       CONFIG_UK="${ARG_PATH}/Config.uk"
+
+       if [ ! -f "${CONFIG_UK}" ]; then
+               if [ $OPT_QUIET -ne 0 ]; then
+                       echo "Could not find \"Config.uk\" under \"${ARG_PATH}\". Skipping..." 1>&2
+               fi
+               continue;
+       fi
+
+       printf "source \"%s\"\n" "$( readlink -f "${CONFIG_UK}" )" >&7
+done
+
+#
+# FOOTER
+#
+case "${OPT_MODE}" in
+       menu)
+               printf "endmenu\n" >&7
+               ;;
+       *)
+               ;;
+esac
+
+# close FD:7 and print filename
+if [ ! -z "$ARG_OUT" ]; then
+       printf '%s\n' "$( readlink -f $ARG_OUT )"
+       exec 7>&-
+fi
diff --git a/support/scripts/uk_build_configure.sh b/support/scripts/uk_build_configure.sh
deleted file mode 100755 (executable)
index 49e2481..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/usr/bin/env bash
-
-OPT_BASENAME=`basename $0`
-OPT_STRING="a:e:ho:p:"
-
-read -r -d '' OPT_HELP  <<- EOH
-       a - The application location
-       e - The location of the external libraries
-       p - The location of external platforms
-       o - The output configuration file
-       h - Print Usage
-EOH
-
-print_usage() {
-       printf "%s [%s]\n" ${OPT_BASENAME} ${OPT_STRING};
-       printf "%s\n" "${OPT_HELP}"
-}
-
-fetch_plats() {
-       local files=;
-       files=`find ${@} -maxdepth 1 -name "Config.uk"`
-       echo ${files}
-}
-
-fetch_libs() {
-       local files=;
-       files=`find ${@} -maxdepth 1 -name "Config.uk"`
-       echo ${files}
-}
-
-fetch_app() {
-       local files=;
-       files=`find ${1} -maxdepth 1 -name "Config.uk"`
-       echo ${files}
-}
-
-config_out_create() {
-
-       [[ -f ${2} ]] || touch ${2};
-
-       for file in ${1}
-       do
-               [[ -z `cat ${2} | grep ${file}` ]] && \
-                       { echo "source \"${file}\"" >> ${2}; }
-       done
-}
-
-if [ $# -eq 0 ];
-then
-       print_usage
-       exit 1;
-fi
-
-[[ -n ${CONFIG_UK_BASE} ]] && UK_BASE=${CONFIG_UK_BASE};
-[[ -n ${UK_BASE} ]] || UK_BASE=$(readlink -f $(dirname $0)/../..)
-
-CONFIG_FILES=;
-
-while getopts ${OPT_STRING} opt
-do
-       case ${opt} in
-       a)
-               APP_DIR="${OPTARG}"
-               [[ -d ${APP_DIR} ]] || \
-                       { echo "Cannot find the application"; exit 1; }
-               if [ ${UK_BASE} != ${APP_DIR} ]
-               then
-                       CONFIG_FILES=$(fetch_app ${APP_DIR})
-                       echo ${CONFIG_FILES};
-               else
-                       CONFIG_FILES=${BUILD_DIR}/app.uk
-                       [[ -f ${BUILD_DIR}/app.uk ]] || \
-                               { touch ${CONFIG_FILES}; }
-                       echo '# external application' >> ${CONFIG_FILES}
-                       echo 'comment "No external application specified"'\
-                                >> ${CONFIG_FILES}
-                       echo ${CONFIG_FILES};
-               fi
-               exit 0;
-       ;;
-       e)
-               CONFIG_FILES=`fetch_libs "${OPTARG}"`
-       ;;
-       p)
-               CONFIG_FILES=`fetch_plats "${OPTARG}"`
-       ;;
-       h)
-               print_usage;
-               exit 0;
-       ;;
-       o)
-               CONFIG_OUT_FILE=${OPTARG}
-       ;;
-       *)
-               print_usage
-               exit 1;
-       ;;
-       esac
-done
-
-config_out_create "${CONFIG_FILES}" ${CONFIG_OUT_FILE}
-echo ${CONFIG_OUT_FILE}