Skip to content

Commit 424151d

Browse files
authored
Merge pull request #12406 from jsquyres/pr/strengthen-autogen-submodule-checks
autogen.pl: strengthen submodule checks
2 parents 9fc7ee4 + 028750e commit 424151d

File tree

1 file changed

+62
-23
lines changed

1 file changed

+62
-23
lines changed

autogen.pl

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,42 +1397,81 @@ sub replace_config_sub_guess {
13971397
# Make sure we got a submodule-full clone. If not, abort and let a
13981398
# human figure it out.
13991399
if (-f ".gitmodules") {
1400-
open(IN, "git submodule status|")
1401-
|| die "Can't run \"git submodule status\"";
1400+
# Do a quick sanity check to ensure that non-3rd-party
1401+
# submodules are at least present (e.g., they won't be present
1402+
# if you downloaded a GitHub.com-created tarball).
1403+
open(IN, ".gitmodules") ||
1404+
die "Can't open .gitmodules";
14021405
while (<IN>) {
1403-
$_ =~ m/^(.)[0-9a-f]{40}\s+(\S+)/;
1404-
my $status = $1;
1405-
my $path = $2;
1406-
1407-
print("=== Submodule: $path\n");
1408-
if (index($path, "pmix") != -1 and list_contains("pmix", @disabled_3rdparty_packages)) {
1409-
print("Disabled - skipping openpmix");
1410-
next;
1406+
# Find "path = " lines
1407+
if (!($_ =~ m/^\s+path = (.+)$/)) {
1408+
next;
1409+
}
1410+
my $path = $1;
1411+
1412+
# Only care about paths that do not include "3rd-party"
1413+
if (index($path, "3rd-party") != -1) {
1414+
next;
1415+
}
1416+
1417+
# Check that the path exists and is non-empty.
1418+
my $happy = 1;
1419+
if (! -d $path) {
1420+
$happy = 0;
1421+
} else {
1422+
opendir(DIR, $path) ||
1423+
my_die "Can't open $path directory";
1424+
my @files = readdir(DIR);
1425+
closedir(DIR);
1426+
1427+
$happy = 0
1428+
if ($#files < 2);
14111429
}
1412-
if (index($path, "prrte") != -1 and list_contains("prrte", @disabled_3rdparty_packages)) {
1413-
print("Disabled - skipping prrte");
1414-
next;
1430+
1431+
if (!$happy) {
1432+
print(" ==> ERROR: Missing submodule\n\nThe submodule \"$path\" is missing.\n\n");
1433+
exit(1);
14151434
}
1435+
}
14161436

1417-
# Make sure the submodule is there
1418-
if ($status eq "-") {
1419-
print(" ==> ERROR: Missing
1437+
if (-d ".git") {
1438+
open(IN, "git submodule status|")
1439+
|| die "Can't run \"git submodule status\"";
1440+
while (<IN>) {
1441+
$_ =~ m/^(.)[0-9a-f]{40}\s+(\S+)/;
1442+
my $status = $1;
1443+
my $path = $2;
1444+
1445+
print("=== Submodule: $path\n");
1446+
if (index($path, "pmix") != -1 and list_contains("pmix", @disabled_3rdparty_packages)) {
1447+
print("Disabled - skipping openpmix");
1448+
next;
1449+
}
1450+
if (index($path, "prrte") != -1 and list_contains("prrte", @disabled_3rdparty_packages)) {
1451+
print("Disabled - skipping prrte");
1452+
next;
1453+
}
1454+
1455+
# Make sure the submodule is there
1456+
if ($status eq "-") {
1457+
print(" ==> ERROR: Missing
14201458
14211459
The submodule \"$path\" is missing.
14221460
14231461
Perhaps you forgot to \"git clone --recursive ...\", or you need to
14241462
\"git submodule update --init --recursive\"...?\n\n");
1425-
exit(1);
1426-
}
1463+
exit(1);
1464+
}
14271465

1428-
# See if the commit in the submodule is not the same as the
1429-
# commit that the git submodule thinks it should be.
1430-
elsif ($status eq "+") {
1466+
# See if the commit in the submodule is not the same as the
1467+
# commit that the git submodule thinks it should be.
1468+
elsif ($status eq "+") {
14311469
print(" ==> WARNING: Submodule hash is different than upstream.
14321470
If this is not intentional, you may want to run:
14331471
\"git submodule update --init --recursive\"\n");
1434-
} else {
1435-
print(" Local hash is what is expected by the submodule (good!)\n");
1472+
} else {
1473+
print(" Local hash is what is expected by the submodule (good!)\n");
1474+
}
14361475
}
14371476
}
14381477
}

0 commit comments

Comments
 (0)