about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-05-02 09:09:54 -0400
committerGitHub <noreply@github.com>2017-05-02 09:09:54 -0400
commit5b4e8d0917f3c1d2fa746c5fd1bef86f05d75132 (patch)
treefe6d2d8dba0c761ef1dab6d5fcd9ced27a9cfec2
parent50517d58a2f43779c27478baf77f938c0b3ebba0 (diff)
parent04e4d426a169a26d498bf22d2c2d01bc7b14fbcd (diff)
downloadrust-5b4e8d0917f3c1d2fa746c5fd1bef86f05d75132.tar.gz
rust-5b4e8d0917f3c1d2fa746c5fd1bef86f05d75132.zip
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.
-rw-r--r--src/bootstrap/bootstrap.py4
-rwxr-xr-xx.py2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 2bccdef9b0a..ad3cf31c1b9 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -414,8 +414,8 @@ class RustBuild(object):
         # The goal here is to come up with the same triple as LLVM would,
         # at least for the subset of platforms we're willing to target.
         if ostype == 'Linux':
-            os = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding)
-            if os == 'Android':
+            os_from_sp = subprocess.check_output(['uname', '-o']).strip().decode(default_encoding)
+            if os_from_sp == 'Android':
                 ostype = 'linux-android'
             else:
                 ostype = 'unknown-linux-gnu'
diff --git a/x.py b/x.py
index 8f528889d60..e277ab98be1 100755
--- a/x.py
+++ b/x.py
@@ -9,7 +9,7 @@
 # option. This file may not be copied, modified, or distributed
 # except according to those terms.
 
-# This file is only a "symlink" to boostrap.py, all logic should go there.
+# This file is only a "symlink" to bootstrap.py, all logic should go there.
 
 import os
 import sys