Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Under MinGW, x.py fails to run with UnboundLocalError. #41661

Merged
merged 1 commit into from
May 2, 2017
Merged

Under MinGW, x.py fails to run with UnboundLocalError. #41661

merged 1 commit into from
May 2, 2017

Conversation

barik
Copy link
Contributor

@barik barik commented Apr 30, 2017

Under MinGW, x.py will fail with the following errors:

$ ./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):

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):

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.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 1, 2017
@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented May 1, 2017

📌 Commit 04e4d42 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented May 2, 2017

⌛ Testing commit 04e4d42 with merge e4f1dc7...

@bors
Copy link
Contributor

bors commented May 2, 2017

💔 Test failed - status-travis

@arielb1
Copy link
Contributor

arielb1 commented May 2, 2017

  • Travis mac builder craziness (logs are empty)
    @bors retry

@arielb1 arielb1 added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request May 2, 2017
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.
bors added a commit that referenced this pull request May 2, 2017
Rollup of 6 pull requests

- Successful merges: #41661, #41662, #41673, #41688, #41692, #41693
- Failed merges:
@bors bors merged commit 04e4d42 into rust-lang:master May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants