Skip to contentSkip to conversation

*** configure: Add 'mkdir build' check ***

PATCH Superseded Dinah Baum 2 participants 6 messages Feb 8, 2023 – Feb 16, 2023

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/2 configure: Add 'mkdir build' check

In reply to Dinah Baum

QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created.

Checking if 'mkdir dir' succeeds prevents this error.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321

---
 configure | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
configure +10 -5
index 64960c6000..3b384914ce 100755
@@ -31,10 +31,11 @@ then
         fi
     fi
 
-    mkdir build
-    touch $MARKER
+    if mkdir build
+    then
+        touch $MARKER
 
-    cat > GNUmakefile <<'EOF'
+        cat > GNUmakefile <<'EOF'
 # This file is auto-generated by configure to support in-source tree
 # 'make' command invocation
 
@@ -56,8 +57,12 @@ force: ;
 GNUmakefile: ;
 
 EOF
-    cd build
-    exec "$source_path/configure" "$@"
+        cd build
+        exec "$source_path/configure" "$@"
+    else
+        echo "ERROR: Unable to use ./build dir, try using a ../qemu/configure build"
+        exit 1
+    fi
 fi
 
 # Temporary directory used for files created while
Signature · 1 line
2.30.2

Dinah Baum

author
#0 lore raw

cover *** configure: Add 'mkdir build' check ***

QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created.

1 - Checking if 'mkdir dir' succeeds and if the directory is writeable prevents this error.

2 - Since we exit early on error in (1), code for reading in arguments has been moved before that

Changes since v1:
- Fix review comments from Peter Maydell

Dinah Baum (2):
configure: Add 'mkdir build' check
configure: './configure --help' should work

 configure | 691 +++++++++++++++++++++++++++---------------------------
 1 file changed, 348 insertions(+), 343 deletions(-)
Signature · 1 line
2.30.2
author
#4 lore raw

PATCH 2/2 configure: './configure --help' should work

Always initialize --help display option

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321

---
 configure | 676 +++++++++++++++++++++++++++---------------------------
 1 file changed, 338 insertions(+), 338 deletions(-)
configure +338 -338
index 3b384914ce..1fb4d145f1 100755
@@ -14,6 +14,344 @@ export CCACHE_RECACHE=yes
 # make source path absolute
 source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+werror=""
+
+print_error() {
+    (echo
+    echo "ERROR: $1"
+    while test -n "$2"; do
+        echo "       $2"
+        shift
+    done
+    echo) >&2
+}
+
+error_exit() {
+    print_error "$@"
+    exit 1
+}
+
+meson_option_build_array() {
+  printf '['
+  (if test "$targetos" = windows; then
+    IFS=\;
+  else
+    IFS=:
+  fi
+  for e in $1; do
+    printf '"""'
+    # backslash escape any '\' and '"' characters
+    printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
+    printf '""",'
+  done)
+  printf ']\n'
+}
+
+. "$source_path/scripts/meson-buildoptions.sh"
+
+quote_sh() {
+    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
+}
+
+meson_options=
+meson_option_add() {
+  meson_options="$meson_options $(quote_sh "$1")"
+}
+meson_option_parse() {
+  meson_options="$meson_options $(_meson_option_parse "$@")"
+  if test $? -eq 1; then
+    echo "ERROR: unknown option $1"
+    echo "Try '$0 --help' for more information"
+    exit 1
+  fi
+}
+
+for opt do
+  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
+  case "$opt" in
+  --help|-h) show_help=yes
+  ;;
+  --version|-V) exec cat "$source_path/VERSION"
+  ;;
+  --prefix=*) prefix="$optarg"
+  ;;
+  --cross-prefix=*)
+  ;;
+  --cc=*)
+  ;;
+  --host-cc=*) host_cc="$optarg"
+  ;;
+  --cxx=*)
+  ;;
+  --objcc=*) objcc="$optarg"
+  ;;
+  --make=*) make="$optarg"
+  ;;
+  --install=*)
+  ;;
+  --python=*) python="$optarg" ; explicit_python=yes
+  ;;
+  --skip-meson) skip_meson=yes
+  ;;
+  --meson=*) meson="$optarg"
+  ;;
+  --ninja=*) ninja="$optarg"
+  ;;
+  --smbd=*) smbd="$optarg"
+  ;;
+  --extra-cflags=*)
+  ;;
+  --extra-cxxflags=*)
+  ;;
+  --extra-objcflags=*)
+  ;;
+  --extra-ldflags=*)
+  ;;
+  --cross-cc-*)
+  ;;
+  --cross-prefix-*)
+  ;;
+  --enable-debug-info) meson_option_add -Ddebug=true
+  ;;
+  --disable-debug-info) meson_option_add -Ddebug=false
+  ;;
+  --enable-modules)
+      modules="yes"
+  ;;
+  --disable-modules)
+      modules="no"
+  ;;
+  --cpu=*)
+  ;;
+  --target-list=*) target_list="$optarg"
+                   if test "$target_list_exclude"; then
+                       error_exit "Can't mix --target-list with --target-list-exclude"
+                   fi
+  ;;
+  --target-list-exclude=*) target_list_exclude="$optarg"
+                   if test "$target_list"; then
+                       error_exit "Can't mix --target-list-exclude with --target-list"
+                   fi
+  ;;
+  --with-default-devices) meson_option_add -Ddefault_devices=true
+  ;;
+  --without-default-devices) meson_option_add -Ddefault_devices=false
+  ;;
+  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
+  ;;
+  --with-devices-*) device_arch=${opt#--with-devices-};
+                    device_arch=${device_arch%%=*}
+                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
+                    if test -f "$cf"; then
+                        device_archs="$device_archs $device_arch"
+                        eval "devices_${device_arch}=\$optarg"
+                    else
+                        error_exit "File $cf does not exist"
+                    fi
+  ;;
+  --without-default-features) # processed above
+  ;;
+  --static)
+    static="yes"
+    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
+  ;;
+  --bindir=*) bindir="$optarg"
+  ;;
+  --with-suffix=*) qemu_suffix="$optarg"
+  ;;
+  --host=*|--build=*|\
+  --disable-dependency-tracking|\
+  --sbindir=*|--sharedstatedir=*|\
+  --oldincludedir=*|--datarootdir=*|--infodir=*|\
+  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
+    # These switches are silently ignored, for compatibility with
+    # autoconf-generated configure scripts. This allows QEMU's
+    # configure to be used by RPM and similar macros that set
+    # lots of directory switches by default.
+  ;;
+  --enable-debug-tcg) debug_tcg="yes"
+  ;;
+  --disable-debug-tcg) debug_tcg="no"
+  ;;
+  --enable-debug)
+      # Enable debugging options that aren't excessively noisy
+      debug_tcg="yes"
+      meson_option_parse --enable-debug-mutex ""
+      meson_option_add -Doptimization=0
+      fortify_source="no"
+  ;;
+  --enable-sanitizers) sanitizers="yes"
+  ;;
+  --disable-sanitizers) sanitizers="no"
+  ;;
+  --enable-tsan) tsan="yes"
+  ;;
+  --disable-tsan) tsan="no"
+  ;;
+  --disable-tcg) tcg="disabled"
+                 plugins="no"
+  ;;
+  --enable-tcg) tcg="enabled"
+  ;;
+  --disable-system) softmmu="no"
+  ;;
+  --enable-system) softmmu="yes"
+  ;;
+  --disable-user)
+      linux_user="no" ;
+      bsd_user="no" ;
+  ;;
+  --enable-user) ;;
+  --disable-linux-user) linux_user="no"
+  ;;
+  --enable-linux-user) linux_user="yes"
+  ;;
+  --disable-bsd-user) bsd_user="no"
+  ;;
+  --enable-bsd-user) bsd_user="yes"
+  ;;
+  --enable-pie) pie="yes"
+  ;;
+  --disable-pie) pie="no"
+  ;;
+  --enable-werror) werror="yes"
+  ;;
+  --disable-werror) werror="no"
+  ;;
+  --enable-stack-protector) stack_protector="yes"
+  ;;
+  --disable-stack-protector) stack_protector="no"
+  ;;
+  --enable-safe-stack) safe_stack="yes"
+  ;;
+  --disable-safe-stack) safe_stack="no"
+  ;;
+  --enable-cfi)
+      cfi="true";
+      meson_option_add -Db_lto=true
+  ;;
+  --disable-cfi) cfi="false"
+  ;;
+  --disable-fdt) fdt="disabled"
+  ;;
+  --enable-fdt) fdt="enabled"
+  ;;
+  --enable-fdt=git) fdt="internal"
+  ;;
+  --enable-fdt=*) fdt="$optarg"
+  ;;
+  --with-coroutine=*) coroutine="$optarg"
+  ;;
+  --with-git=*) git="$optarg"
+  ;;
+  --with-git-submodules=*)
+      git_submodules_action="$optarg"
+  ;;
+  --enable-plugins) if test "$mingw32" = "yes"; then
+                        error_exit "TCG plugins not currently supported on Windows platforms"
+                    else
+                        plugins="yes"
+                    fi
+  ;;
+  --disable-plugins) plugins="no"
+  ;;
+  --enable-containers) use_containers="yes"
+  ;;
+  --disable-containers) use_containers="no"
+  ;;
+  --gdb=*) gdb_bin="$optarg"
+  ;;
+  --enable-vfio-user-server) vfio_user_server="enabled"
+  ;;
+  --disable-vfio-user-server) vfio_user_server="disabled"
+  ;;
+  # everything else has the same name in configure and meson
+  --*) meson_option_parse "$opt" "$optarg"
+  ;;
+  esac
+done
+
+# test for any invalid configuration combinations
+if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
+    error_exit "Can't enable plugins on non-TCG builds"
+fi
+
+if test x"$show_help" = x"yes" ; then
+cat << EOF
+
+Usage: configure [options]
+Options: [defaults in brackets after descriptions]
+
+Standard options:
+  --help                   print this message
+  --prefix=PREFIX          install in PREFIX [$prefix]
+  --target-list=LIST       set target list (default: build all)
+$(echo Available targets: $default_target_list | \
+  fold -s -w 53 | sed -e 's/^/                           /')
+  --target-list-exclude=LIST exclude a set of targets from the default target-list
+
+Advanced options (experts only):
+  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
+  --cc=CC                  use C compiler CC [$cc]
+  --host-cc=CC             use C compiler CC [$host_cc] for code run at
+                           build time
+  --cxx=CXX                use C++ compiler CXX [$cxx]
+  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
+  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
+  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
+  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
+  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
+  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
+  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
+  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
+  --make=MAKE              use specified make [$make]
+  --python=PYTHON          use specified python [$python]
+  --meson=MESON            use specified meson [$meson]
+  --ninja=NINJA            use specified ninja [$ninja]
+  --smbd=SMBD              use specified smbd [$smbd]
+  --with-git=GIT           use specified git [$git]
+  --with-git-submodules=update   update git submodules (default if .git dir exists)
+  --with-git-submodules=validate fail if git submodules are not up to date
+  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
+  --static                 enable static build [$static]
+  --bindir=PATH            install binaries in PATH
+  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
+  --without-default-features default all --enable-* options to "disabled"
+  --without-default-devices  do not include any device that is not needed to
+                           start the emulator (only use if you are including
+                           desired devices in configs/devices/)
+  --with-devices-ARCH=NAME override default configs/devices
+  --enable-debug           enable common debug build options
+  --enable-sanitizers      enable default sanitizers
+  --enable-tsan            enable thread sanitizer
+  --disable-werror         disable compilation abort on warning
+  --disable-stack-protector disable compiler-provided stack protection
+  --cpu=CPU                Build for host CPU [$cpu]
+  --with-coroutine=BACKEND coroutine backend. Supported options:
+                           ucontext, sigaltstack, windows
+  --enable-plugins
+                           enable plugins via shared library loading
+  --disable-containers     don't use containers for cross-building
+  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
+EOF
+  meson_options_help
+cat << EOF
+  system          all system emulation targets
+  user            supported user emulation targets
+  linux-user      all linux usermode emulation targets
+  bsd-user        all BSD usermode emulation targets
+  pie             Position Independent Executables
+  modules         modules support (non-Windows)
+  debug-tcg       TCG debugging (default is disabled)
+  debug-info      debugging information
+  safe-stack      SafeStack Stack Smash Protection. Depends on
+                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
+
+NOTE: The object files are built at the place where configure is launched
+EOF
+exit 0
+fi
+
 if test "$PWD" = "$source_path"
 then
     echo "Using './build' as the directory for build output"
@@ -93,25 +431,6 @@ invoke=$(printf " '%s'" "$0" "$@")
 test -n "$GITLAB_CI" && echo "configuring with: $invoke"
 { echo "$invoke"; echo; echo "#"; } >> config.log
 
-quote_sh() {
-    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
-}
-
-print_error() {
-    (echo
-    echo "ERROR: $1"
-    while test -n "$2"; do
-        echo "       $2"
-        shift
-    done
-    echo) >&2
-}
-
-error_exit() {
-    print_error "$@"
-    exit 1
-}
-
 do_compiler() {
   # Run the compiler, capturing its output to the log. First argument
   # is compiler binary to execute.
@@ -639,249 +958,6 @@ if test "$mingw32" = "yes" ; then
   qemu_suffix=""
 fi
 
-werror=""
-
-meson_option_build_array() {
-  printf '['
-  (if test "$targetos" = windows; then
-    IFS=\;
-  else
-    IFS=:
-  fi
-  for e in $1; do
-    printf '"""'
-    # backslash escape any '\' and '"' characters
-    printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
-    printf '""",'
-  done)
-  printf ']\n'
-}
-
-. "$source_path/scripts/meson-buildoptions.sh"
-
-meson_options=
-meson_option_add() {
-  meson_options="$meson_options $(quote_sh "$1")"
-}
-meson_option_parse() {
-  meson_options="$meson_options $(_meson_option_parse "$@")"
-  if test $? -eq 1; then
-    echo "ERROR: unknown option $1"
-    echo "Try '$0 --help' for more information"
-    exit 1
-  fi
-}
-
-for opt do
-  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
-  case "$opt" in
-  --help|-h) show_help=yes
-  ;;
-  --version|-V) exec cat "$source_path/VERSION"
-  ;;
-  --prefix=*) prefix="$optarg"
-  ;;
-  --cross-prefix=*)
-  ;;
-  --cc=*)
-  ;;
-  --host-cc=*) host_cc="$optarg"
-  ;;
-  --cxx=*)
-  ;;
-  --objcc=*) objcc="$optarg"
-  ;;
-  --make=*) make="$optarg"
-  ;;
-  --install=*)
-  ;;
-  --python=*) python="$optarg" ; explicit_python=yes
-  ;;
-  --skip-meson) skip_meson=yes
-  ;;
-  --meson=*) meson="$optarg"
-  ;;
-  --ninja=*) ninja="$optarg"
-  ;;
-  --smbd=*) smbd="$optarg"
-  ;;
-  --extra-cflags=*)
-  ;;
-  --extra-cxxflags=*)
-  ;;
-  --extra-objcflags=*)
-  ;;
-  --extra-ldflags=*)
-  ;;
-  --cross-cc-*)
-  ;;
-  --cross-prefix-*)
-  ;;
-  --enable-debug-info) meson_option_add -Ddebug=true
-  ;;
-  --disable-debug-info) meson_option_add -Ddebug=false
-  ;;
-  --enable-modules)
-      modules="yes"
-  ;;
-  --disable-modules)
-      modules="no"
-  ;;
-  --cpu=*)
-  ;;
-  --target-list=*) target_list="$optarg"
-                   if test "$target_list_exclude"; then
-                       error_exit "Can't mix --target-list with --target-list-exclude"
-                   fi
-  ;;
-  --target-list-exclude=*) target_list_exclude="$optarg"
-                   if test "$target_list"; then
-                       error_exit "Can't mix --target-list-exclude with --target-list"
-                   fi
-  ;;
-  --with-default-devices) meson_option_add -Ddefault_devices=true
-  ;;
-  --without-default-devices) meson_option_add -Ddefault_devices=false
-  ;;
-  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
-  ;;
-  --with-devices-*) device_arch=${opt#--with-devices-};
-                    device_arch=${device_arch%%=*}
-                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
-                    if test -f "$cf"; then
-                        device_archs="$device_archs $device_arch"
-                        eval "devices_${device_arch}=\$optarg"
-                    else
-                        error_exit "File $cf does not exist"
-                    fi
-  ;;
-  --without-default-features) # processed above
-  ;;
-  --static)
-    static="yes"
-    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
-  ;;
-  --bindir=*) bindir="$optarg"
-  ;;
-  --with-suffix=*) qemu_suffix="$optarg"
-  ;;
-  --host=*|--build=*|\
-  --disable-dependency-tracking|\
-  --sbindir=*|--sharedstatedir=*|\
-  --oldincludedir=*|--datarootdir=*|--infodir=*|\
-  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
-    # These switches are silently ignored, for compatibility with
-    # autoconf-generated configure scripts. This allows QEMU's
-    # configure to be used by RPM and similar macros that set
-    # lots of directory switches by default.
-  ;;
-  --enable-debug-tcg) debug_tcg="yes"
-  ;;
-  --disable-debug-tcg) debug_tcg="no"
-  ;;
-  --enable-debug)
-      # Enable debugging options that aren't excessively noisy
-      debug_tcg="yes"
-      meson_option_parse --enable-debug-mutex ""
-      meson_option_add -Doptimization=0
-      fortify_source="no"
-  ;;
-  --enable-sanitizers) sanitizers="yes"
-  ;;
-  --disable-sanitizers) sanitizers="no"
-  ;;
-  --enable-tsan) tsan="yes"
-  ;;
-  --disable-tsan) tsan="no"
-  ;;
-  --disable-tcg) tcg="disabled"
-                 plugins="no"
-  ;;
-  --enable-tcg) tcg="enabled"
-  ;;
-  --disable-system) softmmu="no"
-  ;;
-  --enable-system) softmmu="yes"
-  ;;
-  --disable-user)
-      linux_user="no" ;
-      bsd_user="no" ;
-  ;;
-  --enable-user) ;;
-  --disable-linux-user) linux_user="no"
-  ;;
-  --enable-linux-user) linux_user="yes"
-  ;;
-  --disable-bsd-user) bsd_user="no"
-  ;;
-  --enable-bsd-user) bsd_user="yes"
-  ;;
-  --enable-pie) pie="yes"
-  ;;
-  --disable-pie) pie="no"
-  ;;
-  --enable-werror) werror="yes"
-  ;;
-  --disable-werror) werror="no"
-  ;;
-  --enable-stack-protector) stack_protector="yes"
-  ;;
-  --disable-stack-protector) stack_protector="no"
-  ;;
-  --enable-safe-stack) safe_stack="yes"
-  ;;
-  --disable-safe-stack) safe_stack="no"
-  ;;
-  --enable-cfi)
-      cfi="true";
-      meson_option_add -Db_lto=true
-  ;;
-  --disable-cfi) cfi="false"
-  ;;
-  --disable-fdt) fdt="disabled"
-  ;;
-  --enable-fdt) fdt="enabled"
-  ;;
-  --enable-fdt=git) fdt="internal"
-  ;;
-  --enable-fdt=*) fdt="$optarg"
-  ;;
-  --with-coroutine=*) coroutine="$optarg"
-  ;;
-  --with-git=*) git="$optarg"
-  ;;
-  --with-git-submodules=*)
-      git_submodules_action="$optarg"
-  ;;
-  --enable-plugins) if test "$mingw32" = "yes"; then
-                        error_exit "TCG plugins not currently supported on Windows platforms"
-                    else
-                        plugins="yes"
-                    fi
-  ;;
-  --disable-plugins) plugins="no"
-  ;;
-  --enable-containers) use_containers="yes"
-  ;;
-  --disable-containers) use_containers="no"
-  ;;
-  --gdb=*) gdb_bin="$optarg"
-  ;;
-  --enable-vfio-user-server) vfio_user_server="enabled"
-  ;;
-  --disable-vfio-user-server) vfio_user_server="disabled"
-  ;;
-  # everything else has the same name in configure and meson
-  --*) meson_option_parse "$opt" "$optarg"
-  ;;
-  esac
-done
-
-# test for any invalid configuration combinations
-if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
-    error_exit "Can't enable plugins on non-TCG builds"
-fi
-
 case $git_submodules_action in
     update|validate)
         if test ! -e "$source_path/.git"; then
@@ -954,82 +1030,6 @@ for config in $mak_wilds; do
     fi
 done
 
-if test x"$show_help" = x"yes" ; then
-cat << EOF
-
-Usage: configure [options]
-Options: [defaults in brackets after descriptions]
-
-Standard options:
-  --help                   print this message
-  --prefix=PREFIX          install in PREFIX [$prefix]
-  --target-list=LIST       set target list (default: build all)
-$(echo Available targets: $default_target_list | \
-  fold -s -w 53 | sed -e 's/^/                           /')
-  --target-list-exclude=LIST exclude a set of targets from the default target-list
-
-Advanced options (experts only):
-  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
-  --cc=CC                  use C compiler CC [$cc]
-  --host-cc=CC             use C compiler CC [$host_cc] for code run at
-                           build time
-  --cxx=CXX                use C++ compiler CXX [$cxx]
-  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
-  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
-  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
-  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
-  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
-  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
-  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
-  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
-  --make=MAKE              use specified make [$make]
-  --python=PYTHON          use specified python [$python]
-  --meson=MESON            use specified meson [$meson]
-  --ninja=NINJA            use specified ninja [$ninja]
-  --smbd=SMBD              use specified smbd [$smbd]
-  --with-git=GIT           use specified git [$git]
-  --with-git-submodules=update   update git submodules (default if .git dir exists)
-  --with-git-submodules=validate fail if git submodules are not up to date
-  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
-  --static                 enable static build [$static]
-  --bindir=PATH            install binaries in PATH
-  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
-  --without-default-features default all --enable-* options to "disabled"
-  --without-default-devices  do not include any device that is not needed to
-                           start the emulator (only use if you are including
-                           desired devices in configs/devices/)
-  --with-devices-ARCH=NAME override default configs/devices
-  --enable-debug           enable common debug build options
-  --enable-sanitizers      enable default sanitizers
-  --enable-tsan            enable thread sanitizer
-  --disable-werror         disable compilation abort on warning
-  --disable-stack-protector disable compiler-provided stack protection
-  --cpu=CPU                Build for host CPU [$cpu]
-  --with-coroutine=BACKEND coroutine backend. Supported options:
-                           ucontext, sigaltstack, windows
-  --enable-plugins
-                           enable plugins via shared library loading
-  --disable-containers     don't use containers for cross-building
-  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
-EOF
-  meson_options_help
-cat << EOF
-  system          all system emulation targets
-  user            supported user emulation targets
-  linux-user      all linux usermode emulation targets
-  bsd-user        all BSD usermode emulation targets
-  pie             Position Independent Executables
-  modules         modules support (non-Windows)
-  debug-tcg       TCG debugging (default is disabled)
-  debug-info      debugging information
-  safe-stack      SafeStack Stack Smash Protection. Depends on
-                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
-
-NOTE: The object files are built at the place where configure is launched
-EOF
-exit 0
-fi
-
 # Remove old dependency files to make sure that they get properly regenerated
 rm -f ./*/config-devices.mak.d
 
Signature · 1 line
2.30.2
author
#2 lore raw

Re: [PATCH 1/2] configure: Add 'mkdir build' check

In reply to Dinah Baum

*ping*

Patch series:
https://lore.kernel.org/qemu-devel/[email protected]/

-Dinah

Quoted 49 lines · Dinah Baum

QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created.

Checking if 'mkdir dir' succeeds prevents this error.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321

---
 configure | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
configure +8 -5
index 64960c6000..3b384914ce 100755
@@ -31,10 +31,11 @@ then
         fi
     fi
 
-    mkdir build
-    touch $MARKER
+    if mkdir build
+    then
+        touch $MARKER
 
-    cat > GNUmakefile <<'EOF'
+        cat > GNUmakefile <<'EOF'
 # This file is auto-generated by configure to support in-source tree
 # 'make' command invocation
 
@@ -56,8 +57,12 @@ force: ;
 GNUmakefile: ;
 
 EOF
-    cd build
-    exec "$source_path/configure" "$@"
+        cd build
+        exec "$source_path/configure" "$@"
+    else
+        echo "ERROR: Unable to use ./build dir, try using a

../qemu/configure build"

configure +2 -1
+        exit 1
+    fi
 fi
 
 # Temporary directory used for files created while
--

2.30.2

#5 lore raw
In reply to Dinah Baum
Quoted 9 lines · Dinah Baum

QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created.

1 - Checking if 'mkdir dir' succeeds and if the directory is writeable prevents this error.

2 - Since we exit early on error in (1), code for reading in arguments has been moved before that

Unfortunately this patch series changes the output of the --help message, because it moves the code that prints it so that it is before some of the other bits of configure that identify various default values to print as part of the help message. You can see this if you do './configure --help > help.txt' before and after the changes and compare the outputs:

tmp/new-help 2023-02-16 13:56:05.579389660 +0000 renamed from tmp/old.help 2023-02-16 13:58:45.302662220 +0000 +2 -28
@@ -1,47 +1,21 @@
-Using './build' as the directory for build output
 
 Usage: configure [options]
 Options: [defaults in brackets after descriptions]
 
 Standard options:
   --help                   print this message
-  --prefix=PREFIX          install in PREFIX [/usr/local]
+  --prefix=PREFIX          install in PREFIX []
   --target-list=LIST       set target list (default: build all)
-                           Available targets: aarch64-softmmu alpha-softmmu
-                           arm-softmmu avr-softmmu cris-softmmu hppa-softmmu
-                           i386-softmmu loongarch64-softmmu m68k-softmmu
-                           microblaze-softmmu microblazeel-softmmu mips-softmmu
-                           mips64-softmmu mips64el-softmmu mipsel-softmmu
-                           nios2-softmmu or1k-softmmu ppc-softmmu ppc64-softmmu
-                           riscv32-softmmu riscv64-softmmu rx-softmmu
-                           s390x-softmmu sh4-softmmu sh4eb-softmmu
-                           sparc-softmmu sparc64-softmmu tricore-softmmu
-                           x86_64-softmmu xtensa-softmmu xtensaeb-softmmu
-                           aarch64-linux-user aarch64_be-linux-user
-                           alpha-linux-user arm-linux-user armeb-linux-user
-                           cris-linux-user hexagon-linux-user hppa-linux-user
-                           i386-linux-user loongarch64-linux-user
-                           m68k-linux-user microblaze-linux-user
-                           microblazeel-linux-user mips-linux-user
-                           mips64-linux-user mips64el-linux-user
-                           mipsel-linux-user mipsn32-linux-user
-                           mipsn32el-linux-user nios2-linux-user
-                           or1k-linux-user ppc-linux-user ppc64-linux-user
-                           ppc64le-linux-user riscv32-linux-user
-                           riscv64-linux-user s390x-linux-user sh4-linux-user
-                           sh4eb-linux-user sparc-linux-user
-                           sparc32plus-linux-user sparc64-linux-user
-                           x86_64-linux-user xtensa-linux-user
-                           xtensaeb-linux-user
+                           Available targets:
   --target-list-exclude=LIST exclude a set of targets from the

default target-list

Advanced options (experts only):

   --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank []
-  --cc=CC                  use C compiler CC [cc]
-  --host-cc=CC             use C compiler CC [cc] for code run at
+  --cc=CC                  use C compiler CC []
+  --host-cc=CC             use C compiler CC [] for code run at

build time
(etc)

You can see that the new output doesn't show the available target list or the default values in [] for options like --cc and --host-cc.

This is kind of awkward to fix because some of the code we run to figure out those default values probably assumes that the current directory is writeable and/or that the build directory was created.

My suggestion is that because the case we're trying to fix is really a corner case (accidentally running configure in a read-only directory), and our hope for the future is to move still more of this code out of configure and into meson.build, that we should take the simple approach:
* just do something like patch 1, which exits immediately if it finds that it couldn't create the build directory
* accept that in this situation, --help doesn't work. This is already the case for some other early error paths, like the one where we failed to create the temporary directory TMPDIR1

I think that's OK if we have a suitably clear error message. I'll go and review patch 1 specifically now, assuming this approach.

thanks
-- PMM

#3 lore raw

Re: [PATCH 1/2] configure: Add 'mkdir build' check

In reply to Dinah Baum
Quoted 7 lines · Dinah Baum

QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created.

Checking if 'mkdir dir' succeeds prevents this error.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321

This commit message needs your Signed-off-by: line on it. This is how you say that you're legally OK to put the change into QEMU and that you're happy for it to happen; the details are at
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#patch-emails-must-include-a-signed-off-by-line

It's just a line

Quoted 26 lines
---
 configure | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
configure +4 -3
index 64960c6000..3b384914ce 100755
@@ -31,10 +31,11 @@ then
         fi
     fi
 
-    mkdir build
-    touch $MARKER
+    if mkdir build
+    then
+        touch $MARKER
 
-    cat > GNUmakefile <<'EOF'
+        cat > GNUmakefile <<'EOF'
 # This file is auto-generated by configure to support in-source tree
 # 'make' command invocation
 
@@ -56,8 +57,12 @@ force: ;
 GNUmakefile: ;
 

configure force: ; · line 66

Quoted 10 lines
configure +6 -2
 EOF
-    cd build
-    exec "$source_path/configure" "$@"
+        cd build
+        exec "$source_path/configure" "$@"
+    else
+        echo "ERROR: Unable to use ./build dir, try using a ../qemu/configure build"
+        exit 1
+    fi
 fi

Hi; I think that because the "happy path" inside this if..then is quite large, we can make the code more readable by reversing the sense of the condition and putting the error exit early, like this:

if ! mkdir build || ! touch $MARKER ; then
echo "ERROR ..."
exit 1
fi

cat > GNUmakefile <<'EOF'
etc etc as before

I'm also going to suggest a tweak to the error text:

"ERROR: Could not create ./build directory. Check the permissions on
your source directory, or try doing an out-of-tree build."

thanks
-- PMM