diff mbox

[v2,4/4] build: don't fail if given a git submodule which does not exist

Message ID 20171027131412.18830-5-berrange@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel P. Berrangé Oct. 27, 2017, 1:14 p.m. UTC
If going back in time in git history, across a commit that introduces a new
submodule, the 'git-submodule.sh' script will fail, causing rebuild to fail.

This is because config-host.mak contains a GIT_SUBMODULES variable that lists
a submodule that only exists in the later commit. config-host.mak won't get
repopulated until config.status is invoked, but make won't get this far due to
the submodule error.

This change makes 'git-submodule.sh' check whether each module is known to git
and drops any which are not present. A warning message will be printed when any
submodule is dropped in this manner.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 scripts/git-submodule.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Alexey Kardashevskiy Oct. 28, 2017, 1:27 a.m. UTC | #1
On 28/10/17 00:14, Daniel P. Berrange wrote:
> If going back in time in git history, across a commit that introduces a new
> submodule, the 'git-submodule.sh' script will fail, causing rebuild to fail.
> 
> This is because config-host.mak contains a GIT_SUBMODULES variable that lists
> a submodule that only exists in the later commit. config-host.mak won't get
> repopulated until config.status is invoked, but make won't get this far due to
> the submodule error.
> 
> This change makes 'git-submodule.sh' check whether each module is known to git
> and drops any which are not present. A warning message will be printed when any
> submodule is dropped in this manner.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  scripts/git-submodule.sh | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/git-submodule.sh b/scripts/git-submodule.sh
> index 30fd83db55..60b3b9bdeb 100755
> --- a/scripts/git-submodule.sh
> +++ b/scripts/git-submodule.sh
> @@ -7,7 +7,7 @@ substat=".git-submodule-status"
>  
>  command=$1
>  shift
> -modules="$@"
> +maybe_modules="$@"
>  
>  test -z "$GIT" && GIT=git
>  
> @@ -16,12 +16,24 @@ error() {
>      exit 1
>  }
>  
> -if test -z "$modules"
> +if test -z "$maybe_modules"
>  then
>      test -e $substat || touch $substat
>      exit 0
>  fi
>  
> +modules=""
> +for m in $maybe_modules
> +do
> +    $GIT submodule status $m 1> /dev/null 2>&1
> +    if test $? == 0


./scripts/git-submodule.sh: 29: test: 0: unexpected operator

This helps:

-    if test $? == 0
+    if test "$?" -eq "0"



> +    then
> +        modules="$modules $m"
> +    else
> +        echo "warn: ignoring non-existant submodule $m"
> +    fi
> +done
> +
>  if ! test -e ".git"
>  then
>      echo "$0: unexpectedly called with submodules but no git checkout exists"
>
Eric Blake Oct. 28, 2017, 5:58 a.m. UTC | #2
On 10/28/2017 03:27 AM, Alexey Kardashevskiy wrote:
> On 28/10/17 00:14, Daniel P. Berrange wrote:
>> If going back in time in git history, across a commit that introduces a new
>> submodule, the 'git-submodule.sh' script will fail, causing rebuild to fail.
>>

>> +do
>> +    $GIT submodule status $m 1> /dev/null 2>&1
>> +    if test $? == 0
> 
> 
> ./scripts/git-submodule.sh: 29: test: 0: unexpected operator

Ah, right, == is a bashism.

> 
> This helps:
> 
> -    if test $? == 0
> +    if test "$?" -eq "0"

Or 'if test $? = 0'
diff mbox

Patch

diff --git a/scripts/git-submodule.sh b/scripts/git-submodule.sh
index 30fd83db55..60b3b9bdeb 100755
--- a/scripts/git-submodule.sh
+++ b/scripts/git-submodule.sh
@@ -7,7 +7,7 @@  substat=".git-submodule-status"
 
 command=$1
 shift
-modules="$@"
+maybe_modules="$@"
 
 test -z "$GIT" && GIT=git
 
@@ -16,12 +16,24 @@  error() {
     exit 1
 }
 
-if test -z "$modules"
+if test -z "$maybe_modules"
 then
     test -e $substat || touch $substat
     exit 0
 fi
 
+modules=""
+for m in $maybe_modules
+do
+    $GIT submodule status $m 1> /dev/null 2>&1
+    if test $? == 0
+    then
+        modules="$modules $m"
+    else
+        echo "warn: ignoring non-existant submodule $m"
+    fi
+done
+
 if ! test -e ".git"
 then
     echo "$0: unexpectedly called with submodules but no git checkout exists"