Skip to content

Commit db69d89

Browse files
committed
Reset submodule management to what master does
Basically just translate what's done on master in Rust to Python here.
1 parent 182a4ff commit db69d89

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

src/bootstrap/bootstrap.py

+50-19
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ def unpack(tarball, dst, verbose=False, match=None):
127127
shutil.move(tp, fp)
128128
shutil.rmtree(os.path.join(dst, fname))
129129

130-
def run(args, verbose=False, exception=False):
130+
def run(args, verbose=False, exception=False, cwd=None):
131131
if verbose:
132132
print("running: " + ' '.join(args))
133133
sys.stdout.flush()
134134
# Use Popen here instead of call() as it apparently allows powershell on
135135
# Windows to not lock up waiting for input presumably.
136-
ret = subprocess.Popen(args)
136+
ret = subprocess.Popen(args, cwd=cwd)
137137
code = ret.wait()
138138
if code != 0:
139139
err = "failed to run: " + ' '.join(args)
@@ -391,12 +391,21 @@ def build_bootstrap(self):
391391
args.append("--frozen")
392392
self.run(args, env)
393393

394-
def run(self, args, env=None):
395-
proc = subprocess.Popen(args, env=env)
394+
def run(self, args, env=None, cwd=None):
395+
proc = subprocess.Popen(args, env=env, cwd=cwd)
396396
ret = proc.wait()
397397
if ret != 0:
398398
sys.exit(ret)
399399

400+
def output(self, args, env=None, cwd=None):
401+
proc = subprocess.Popen(args, stdout=subprocess.PIPE, env=env, cwd=cwd)
402+
(out, err) = proc.communicate()
403+
ret = proc.wait()
404+
if ret != 0:
405+
print(out)
406+
sys.exit(ret)
407+
return out
408+
400409
def build_triple(self):
401410
default_encoding = sys.getdefaultencoding()
402411
config = self.get_toml('build')
@@ -541,25 +550,47 @@ def update_submodules(self):
541550
return
542551

543552
print('Updating submodules')
544-
self.run(["git", "-C", self.rust_root, "submodule", "-q", "sync"])
545-
# FIXME: nobody does, but this won't work well with whitespace in
546-
# submodule path
547-
submodules = [s.split()[1] for s in subprocess.check_output(
548-
["git", "config", "--file", os.path.join(
549-
self.rust_root, ".gitmodules"), "--get-regexp", "path"]).splitlines()]
550-
for module in submodules:
551-
if module.endswith(b"llvm") and \
553+
output = self.output(["git", "submodule", "status"], cwd=self.rust_root)
554+
submodules = []
555+
for line in output.splitlines():
556+
# NOTE `git submodule status` output looks like this:
557+
#
558+
# -5066b7dcab7e700844b0e2ba71b8af9dc627a59b src/liblibc
559+
# +b37ef24aa82d2be3a3cc0fe89bf82292f4ca181c src/compiler-rt (remotes/origin/..)
560+
# e058ca661692a8d01f8cf9d35939dfe3105ce968 src/jemalloc (3.6.0-533-ge058ca6)
561+
#
562+
# The first character can be '-', '+' or ' ' and denotes the
563+
# `State` of the submodule Right next to this character is the
564+
# SHA-1 of the submodule HEAD And after that comes the path to the
565+
# submodule
566+
path = line[1:].split(' ')[1]
567+
submodules.append([path, line[0]])
568+
569+
self.run(["git", "submodule", "sync"], cwd=self.rust_root)
570+
571+
for submod in submodules:
572+
path, status = submod
573+
if path.endswith(b"llvm") and \
552574
(self.get_toml('llvm-config') or self.get_mk('CFG_LLVM_ROOT')):
553575
continue
554-
if module.endswith(b"jemalloc") and \
576+
if path.endswith(b"jemalloc") and \
555577
(self.get_toml('jemalloc') or self.get_mk('CFG_JEMALLOC_ROOT')):
556578
continue
557-
self.run(["git", "-C", self.rust_root,
558-
"submodule", "update", "--init", module])
559-
self.run(["git", "-C", self.rust_root, "submodule", "-q",
560-
"foreach", "git", "reset", "-q", "--hard"])
561-
self.run(["git", "-C", self.rust_root, "submodule",
562-
"-q", "foreach", "git", "clean", "-qdfx"])
579+
submod_path = os.path.join(self.rust_root, path)
580+
581+
if status == ' ':
582+
self.run(["git", "reset", "--hard"], cwd=submod_path)
583+
self.run(["git", "clean", "-fdx"], cwd=submod_path)
584+
elif status == '+':
585+
self.run(["git", "submodule", "update", path], cwd=self.rust_root)
586+
self.run(["git", "reset", "--hard"], cwd=submod_path)
587+
self.run(["git", "clean", "-fdx"], cwd=submod_path)
588+
elif status == '-':
589+
self.run(["git", "submodule", "init", path], cwd=self.rust_root)
590+
self.run(["git", "submodule", "update", path], cwd=self.rust_root)
591+
else:
592+
raise ValueError('unknown submodule status: ' + status)
593+
563594
def bootstrap():
564595
parser = argparse.ArgumentParser(description='Build rust')
565596
parser.add_argument('--config')

src/tools/tidy/src/deps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static EXCEPTIONS: &'static [&'static str] = &[
3232
"openssl", // BSD+advertising clause, cargo, mdbook
3333
"pest", // MPL2, mdbook via handlebars
3434
"thread-id", // Apache-2.0, mdbook
35-
"strings", // not in published manifest
35+
"strings", // this is actually MIT/Apache-2.0 but it's not in the manifest yet
3636
];
3737

3838
pub fn check(path: &Path, bad: &mut bool) {

0 commit comments

Comments
 (0)