Skip to content

Commit 5b4e8d0

Browse files
authored
Rollup merge of #41661 - barik:master, r=alexcrichton
Under MinGW, x.py fails to run with UnboundLocalError. Under MinGW, `x.py` will fail with the following errors: ```bash $ ./x.py Traceback (most recent call last): File "./x.py", line 20, in <module> bootstrap.main() File "C:/src/rust/src/bootstrap/bootstrap.py", line 620, in main bootstrap() File "C:/src/rust/src/bootstrap/bootstrap.py", line 601, in bootstrap rb.build = rb.build_triple() File "C:/src/rust/src/bootstrap/bootstrap.py", line 459, in build_triple if os.environ.get('MSYSTEM') == 'MINGW64': UnboundLocalError: local variable 'os' referenced before assignment ``` The reason is due to the `build_triple` function in `src/bootstrap/bootstrap.py` (Line 416): ```python if ostype == 'Linux': os = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding) ``` Here, the assignment to `os` is causing the `os` module to be shadowed. Then, in (Line 459): ```python if os.environ.get('MSYSTEM') == 'MINGW64': cputype = 'x86_64' ``` `os` now refers to the uninitialized local variable, not the `os` module. Easiest fix is to simply rename the `os` variable to something like `os_from_sp`. Also, there is a small typo fix in `x.py` referencing the wrong file name.
2 parents 50517d5 + 04e4d42 commit 5b4e8d0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/bootstrap/bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ def build_triple(self):
414414
# The goal here is to come up with the same triple as LLVM would,
415415
# at least for the subset of platforms we're willing to target.
416416
if ostype == 'Linux':
417-
os = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding)
418-
if os == 'Android':
417+
os_from_sp = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding)
418+
if os_from_sp == 'Android':
419419
ostype = 'linux-android'
420420
else:
421421
ostype = 'unknown-linux-gnu'

x.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# option. This file may not be copied, modified, or distributed
1010
# except according to those terms.
1111

12-
# This file is only a "symlink" to boostrap.py, all logic should go there.
12+
# This file is only a "symlink" to bootstrap.py, all logic should go there.
1313

1414
import os
1515
import sys

0 commit comments

Comments
 (0)