Nicholas Bishop | 82a3feb | 2021-06-23 13:18:18 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # pylint: disable=missing-docstring |
| 3 | |
| 4 | import os |
| 5 | import subprocess |
| 6 | import sys |
| 7 | |
| 8 | |
| 9 | def main(): |
| 10 | repo_dir = os.path.dirname(os.path.realpath(__file__)) |
Nicholas Bishop | bd51790 | 2021-06-23 17:13:27 -0400 | [diff] [blame] | 11 | tools_dir = os.path.join(repo_dir, 'tools') |
| 12 | tools_manifest = os.path.join(tools_dir, 'Cargo.toml') |
Nicholas Bishop | 82a3feb | 2021-06-23 13:18:18 -0400 | [diff] [blame] | 13 | |
Nicholas Bishop | 2147fa8 | 2021-06-23 14:27:33 -0400 | [diff] [blame] | 14 | cmd = ['cargo', 'run', '--quiet', '--manifest-path', tools_manifest, '--'] |
Nicholas Bishop | 82a3feb | 2021-06-23 13:18:18 -0400 | [diff] [blame] | 15 | cmd += ['--repo', repo_dir] |
| 16 | cmd += sys.argv[1:] |
| 17 | |
Nicholas Bishop | bd51790 | 2021-06-23 17:13:27 -0400 | [diff] [blame] | 18 | # Make rustc use absolute paths for messages. |
| 19 | var_name = 'RUSTFLAGS' |
| 20 | env = dict(os.environ) |
| 21 | flags = env.get(var_name, '') |
| 22 | flags += ' --remap-path-prefix=src={}/src'.format(tools_dir) |
| 23 | env[var_name] = flags |
| 24 | |
Nicholas Bishop | 49794fd | 2021-06-23 18:55:21 -0400 | [diff] [blame] | 25 | res = subprocess.run(cmd, check=False, env=env) |
| 26 | # Exit with the child's return code. Do it this way instead of |
| 27 | # using check=True because we don't want a stack trace. |
| 28 | if res.returncode != 0: |
| 29 | sys.exit(res.returncode) |
Nicholas Bishop | 82a3feb | 2021-06-23 13:18:18 -0400 | [diff] [blame] | 30 | |
| 31 | |
| 32 | if __name__ == '__main__': |
| 33 | main() |