From c32eeb3eb98470adf1d2a13c5f7983e5bea6730a Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Tue, 24 Dec 2019 13:15:45 -0500 Subject: [PATCH] autogen: add sanity checks for git submodules Signed-off-by: Jeff Squyres --- autogen.pl | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/autogen.pl b/autogen.pl index 9715c0ea1c..54323b78d1 100755 --- a/autogen.pl +++ b/autogen.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # -# Copyright (c) 2009-2017 Cisco Systems, Inc. All rights reserved +# Copyright (c) 2009-2019 Cisco Systems, Inc. All rights reserved # Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2013 Mellanox Technologies, Inc. # All rights reserved. @@ -1231,6 +1231,54 @@ $step. Checking tool versions\n\n"; #--------------------------------------------------------------------------- +++$step; +verbose "\n$step. Checking for git submodules\n\n"; + +# Make sure we got a submodule-full clone. If not, abort and let a +# human figure it out. +if (-f ".gitmodules") { + open(IN, "git submodule status|") + || die "Can't run \"git submodule status\""; + while () { + chomp; + $_ =~ m/^(.)(.{40}) ([^ ]+) *\(*([^\(\)]*)\)*$/; + my $status = $1; + my $local_hash = $2; + my $path = $3; + my $extra = $4; + + print("=== Submodule: $path\n"); + + # Make sure the submodule is there + if ($status eq "-") { + print(" ==> ERROR: Missing + +The submodule \"$path\" is missing. + +Perhaps you forgot to \"git clone --recursive ...\", or you need to +\"git submodule update --init --recursive\"...?\n\n"); + exit(1); + } + + # See if the submodule is at the expected git hash + # (it may be ok if it's not -- just warn the user) + $extra =~ m/-g(.+)/; + my $remote_hash = $1; + if ($remote_hash) { + my $abbrev_local_hash = substr($local_hash, 0, length($remote_hash)); + if ($remote_hash ne $abbrev_local_hash) { + print(" ==> WARNING: Submodule hash is different than upstream. + If this is not intentional, you may want to run: + \"git submodule update --init --recursive\"\n"); + } else { + print(" Local hash == remote hash (good!)\n"); + } + } + } +} + +#--------------------------------------------------------------------------- + # Save the platform file in the m4 $m4 .= "dnl Platform file\n";