Fix run_gnrt.py to not be confused by a random rustc in PATH.
For now, encode some knowledge about gnrt into the script helper, since
only the `gen` subcommand takes the `--rustc-path` flag. In the future,
this may be extended, especially if the `download` subcommand gets a
`--recursive` or `--transitive` mode.
Also simplify passing through additional arguments to gnrt by taking
advantage of nargs.
Bug: 1492354
Change-Id: I3b88d944589cb94160d40adf0019a0d9139a649c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4936788
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210446}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
a29efec7a3
commit
cefe34f636
@@ -24,27 +24,32 @@ def main():
|
||||
parser.add_argument('--out-dir',
|
||||
default='out/gnrt',
|
||||
help='put target and cargo home dir here')
|
||||
args, rest = parser.parse_known_args()
|
||||
parser.add_argument('gnrt_args',
|
||||
nargs='*',
|
||||
help='additional arguments to pass to gnrt, e.g. "gen"')
|
||||
args = parser.parse_args()
|
||||
|
||||
exe = ''
|
||||
if sys.platform == 'win32':
|
||||
exe = '.exe'
|
||||
|
||||
cargo_bin = os.path.join(args.rust_sysroot, 'bin', f'cargo{exe}')
|
||||
rustc_bin = os.path.join(args.rust_sysroot, 'bin', f'rustc{exe}')
|
||||
cargo_bin = os.path.abspath(
|
||||
os.path.join(args.rust_sysroot, 'bin', f'cargo{exe}'))
|
||||
rustc_bin = os.path.abspath(
|
||||
os.path.join(args.rust_sysroot, 'bin', f'rustc{exe}'))
|
||||
|
||||
cargo_env = os.environ
|
||||
cargo_env['CARGO_HOME'] = os.path.abspath(
|
||||
os.path.join(args.out_dir, 'cargo_home'))
|
||||
target_dir = os.path.abspath(os.path.join(args.out_dir, 'target'))
|
||||
|
||||
gnrt_args = rest
|
||||
if gnrt_args[0] == '--':
|
||||
gnrt_args = gnrt_args[1:]
|
||||
|
||||
gnrt_args = args.gnrt_args
|
||||
if gnrt_args and gnrt_args[0] == 'gen':
|
||||
gnrt_args.extend(['--rustc-path', rustc_bin])
|
||||
return subprocess.run([
|
||||
cargo_bin, '--locked', 'run', '--release', '--manifest-path',
|
||||
GNRT_MANIFEST_PATH, '--target-dir', target_dir, '--'
|
||||
GNRT_MANIFEST_PATH, '--target-dir', target_dir, '--config',
|
||||
f'build.rustc="{rustc_bin}"', '--'
|
||||
] + gnrt_args).returncode
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user