- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
no python in shell scripts #107812
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
          
     Closed
      
      
            onur-ozkan
  wants to merge
  5
  commits into
  rust-lang:master
from
onur-ozkan:no-python-in-shell-scripts
  
      
      
   
      
    
  
     Closed
                    no python in shell scripts #107812
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      ea813a0
              
                [wip] Add bootstrap-shim and package it on nightly
              
              
                jyn514 8ae63b1
              
                Unify `MinimalConfig::parse` and `Config::parse`
              
              
                onur-ozkan 8a6c18f
              
                Also re-download bootstrap if `build_helper` changes
              
              
                jyn514 a8f85ae
              
                move `min_config` related options from `config` module
              
              
                onur-ozkan 8ad8906
              
                refactor `src/tools/x`
              
              
                onur-ozkan File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| use std::{ | ||
| env, io, | ||
| process::{self, Command, ExitStatus}, | ||
| }; | ||
|  | ||
| use bootstrap::{Flags, MinimalConfig}; | ||
|  | ||
| #[path = "../../../src/tools/x/src/main.rs"] | ||
| mod x; | ||
|  | ||
| /// We are planning to exclude python logic from x script by executing bootstrap-shim | ||
| /// immediately. Since `find_and_run_available_bootstrap_script` executes x script first, | ||
| /// any changes on bootstrap will not be seen. To prevent this problem, in bootstrap-shim | ||
| /// we want to call the python script directly. | ||
| fn find_and_run_py_bootstrap_script() { | ||
| #[cfg(unix)] | ||
| fn exec_or_status(command: &mut Command) -> io::Result<ExitStatus> { | ||
| use std::os::unix::process::CommandExt; | ||
| Err(command.exec()) | ||
| } | ||
|  | ||
| #[cfg(not(unix))] | ||
| fn exec_or_status(command: &mut Command) -> io::Result<ExitStatus> { | ||
| command.status() | ||
| } | ||
|  | ||
| let current_path = match env::current_dir() { | ||
| Ok(dir) => dir, | ||
| Err(err) => { | ||
| eprintln!("Failed to get current directory: {err}"); | ||
| process::exit(1); | ||
| } | ||
| }; | ||
|  | ||
| for dir in current_path.ancestors() { | ||
| let candidate = dir.join("x.py"); | ||
| if candidate.exists() { | ||
| let mut cmd: Command; | ||
| cmd = Command::new(x::python()); | ||
| cmd.arg(&candidate).args(env::args().skip(1)).current_dir(dir); | ||
| let result = exec_or_status(&mut cmd); | ||
|  | ||
| match result { | ||
| Err(error) => { | ||
| eprintln!("Failed to invoke `{:?}`: {}", cmd, error); | ||
| } | ||
| Ok(status) => { | ||
| process::exit(status.code().unwrap_or(1)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|  | ||
| fn main() { | ||
| let args = env::args().skip(1).collect::<Vec<_>>(); | ||
| let flags = Flags::parse(&args); | ||
|  | ||
| // If there are no untracked changes to bootstrap, download it from CI. | ||
| // Otherwise, build it from source. Use python to build to avoid duplicating the code between python and rust. | ||
| let config = MinimalConfig::parse(&flags, None); | ||
| let bootstrap_bin = if let Some(commit) = last_modified_bootstrap_commit(&config) { | ||
| config.download_bootstrap(&commit) | ||
| } else { | ||
| return find_and_run_py_bootstrap_script(); | ||
| }; | ||
|  | ||
| let args: Vec<_> = std::env::args().skip(1).collect(); | ||
| println!("Running pre-compiled bootstrap binary"); | ||
| Command::new(bootstrap_bin).args(args).status().expect("failed to spawn bootstrap binairy"); | ||
|         
                  onur-ozkan marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
|  | ||
| fn last_modified_bootstrap_commit(config: &MinimalConfig) -> Option<String> { | ||
| config.last_modified_commit( | ||
| &["src/bootstrap", "src/tools/build_helper", "src/tools/x"], | ||
| "download-bootstrap", | ||
| true, | ||
| ) | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.