diff mbox series

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

Message ID 20230208233111.398577-2-dinahbaum123@gmail.com
State New
Headers show
Series *** configure: Add 'mkdir build' check *** | expand

Commit Message

Dinah B Feb. 8, 2023, 11:31 p.m. UTC
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(-)

Comments

Dinah B Feb. 16, 2023, 5:48 a.m. UTC | #1
*ping*

Patch series:
https://lore.kernel.org/qemu-devel/20230208233111.398577-1-dinahbaum123@gmail.com/

-Dinah

On Wed, Feb 8, 2023 at 6:31 PM Dinah Baum <dinahbaum123@gmail.com> wrote:

> 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(-)
>
> diff --git a/configure b/configure
> index 64960c6000..3b384914ce 100755
> --- a/configure
> +++ b/configure
> @@ -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
> --
> 2.30.2
>
>
Peter Maydell Feb. 16, 2023, 2:21 p.m. UTC | #2
On Wed, 8 Feb 2023 at 23:32, Dinah Baum <dinahbaum123@gmail.com> wrote:
>
> 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
Signed-off-by: Your Name <your@email>

> ---
>  configure | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/configure b/configure
> index 64960c6000..3b384914ce 100755
> --- a/configure
> +++ b/configure
> @@ -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

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
diff mbox series

Patch

diff --git a/configure b/configure
index 64960c6000..3b384914ce 100755
--- a/configure
+++ b/configure
@@ -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