Merge "Give a warning to use --copy-out" am: ca84c4bb2f am: f1970ff373

Original change: https://android-review.googlesource.com/c/platform/development/+/1486487

Change-Id: If6a1cfdac0cb6cf723bb7fb5a5e4c2cfc4a5a80a
This commit is contained in:
Chih-hung Hsieh
2020-11-05 01:15:46 +00:00
committed by Automerger Merge Worker

View File

@@ -1116,24 +1116,33 @@ class Runner(object):
rust_version = version rust_version = version
return '.'.join(rust_version) return '.'.join(rust_version)
def copy_out_files(self): def find_out_files(self):
"""Copy build.rs output files to ./out and set up build_out_files."""
if not self.args.copy_out or self.checked_out_files:
return
self.checked_out_files = True
# list1 has build.rs output for normal crates # list1 has build.rs output for normal crates
list1 = glob.glob(TARGET_TMP + '/*/*/build/' + self.root_pkg + '-*/out/*') list1 = glob.glob(TARGET_TMP + '/*/*/build/' + self.root_pkg + '-*/out/*')
# list2 has build.rs output for proc-macro crates # list2 has build.rs output for proc-macro crates
list2 = glob.glob(TARGET_TMP + '/*/build/' + self.root_pkg + '-*/out/*') list2 = glob.glob(TARGET_TMP + '/*/build/' + self.root_pkg + '-*/out/*')
return list1 + list2
def copy_out_files(self):
"""Copy build.rs output files to ./out and set up build_out_files."""
if self.checked_out_files:
return
self.checked_out_files = True
cargo_out_files = self.find_out_files()
out_files = set() out_files = set()
if list1 or list2: if cargo_out_files:
os.makedirs('out', exist_ok=True) os.makedirs('out', exist_ok=True)
for path in list1 + list2: for path in cargo_out_files:
file_name = path.split('/')[-1] file_name = path.split('/')[-1]
out_files.add(file_name) out_files.add(file_name)
shutil.copy(path, 'out/' + file_name) shutil.copy(path, 'out/' + file_name)
self.build_out_files = sorted(out_files) self.build_out_files = sorted(out_files)
def has_used_out_dir(self):
"""Returns true if env!("OUT_DIR") is found."""
return 0 == os.system('grep -rl --exclude build.rs --include \\*.rs' +
' \'env!("OUT_DIR")\' * > /dev/null')
def copy_out_module_name(self): def copy_out_module_name(self):
if self.args.copy_out and self.build_out_files: if self.args.copy_out and self.build_out_files:
return 'copy_' + self.root_pkg + '_build_out' return 'copy_' + self.root_pkg + '_build_out'
@@ -1328,7 +1337,8 @@ class Runner(object):
return self return self
if self.args.verbose: if self.args.verbose:
print('### INFO: applying local patch file:', self.args.patch) print('### INFO: applying local patch file:', self.args.patch)
os.system('patch -s --no-backup-if-mismatch ./Android.bp ' + self.args.patch) os.system('patch -s --no-backup-if-mismatch ./Android.bp ' +
self.args.patch)
return self return self
def gen_bp(self): def gen_bp(self):
@@ -1337,7 +1347,11 @@ class Runner(object):
print('Dry-run skip: read', CARGO_OUT, 'write Android.bp') print('Dry-run skip: read', CARGO_OUT, 'write Android.bp')
elif os.path.exists(CARGO_OUT): elif os.path.exists(CARGO_OUT):
self.find_root_pkg() self.find_root_pkg()
self.copy_out_files() if self.args.copy_out:
self.copy_out_files()
elif self.find_out_files() and self.has_used_out_dir():
print('WARNING: ' + self.root_pkg + ' has cargo output files; ' +
'please rerun with the --copy-out flag.')
with open(CARGO_OUT, 'r') as cargo_out: with open(CARGO_OUT, 'r') as cargo_out:
self.parse(cargo_out, 'Android.bp') self.parse(cargo_out, 'Android.bp')
self.crates.sort(key=get_module_name) self.crates.sort(key=get_module_name)