-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add x.py setup
#76631
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
Merged
Merged
Add x.py setup
#76631
Changes from all commits
Commits
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
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,88 @@ | ||
use crate::t; | ||
use std::path::{Path, PathBuf}; | ||
use std::{ | ||
env, fs, | ||
io::{self, Write}, | ||
}; | ||
|
||
pub fn setup(src_path: &Path, include_name: &str) { | ||
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from); | ||
|
||
if cfg_file.as_ref().map_or(false, |f| f.exists()) { | ||
let file = cfg_file.unwrap(); | ||
println!( | ||
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`", | ||
file.display() | ||
); | ||
println!( | ||
"help: try adding `profile = \"{}\"` at the top of {}", | ||
include_name, | ||
file.display() | ||
); | ||
println!( | ||
"note: this will use the configuration in {}/src/bootstrap/defaults/config.toml.{}", | ||
src_path.display(), | ||
include_name | ||
); | ||
std::process::exit(1); | ||
} | ||
|
||
let path = cfg_file.unwrap_or_else(|| src_path.join("config.toml")); | ||
let settings = format!( | ||
"# Includes one of the default files in src/bootstrap/defaults\n\ | ||
profile = \"{}\"\n", | ||
include_name | ||
); | ||
t!(fs::write(path, settings)); | ||
|
||
let include_path = | ||
format!("{}/src/bootstrap/defaults/config.toml.{}", src_path.display(), include_name); | ||
println!("`x.py` will now use the configuration at {}", include_path); | ||
|
||
let suggestions = match include_name { | ||
"codegen" | "compiler" => &["check", "build", "test"][..], | ||
"library" => &["check", "build", "test library/std", "doc"], | ||
"user" => &["dist", "build"], | ||
_ => return, | ||
}; | ||
|
||
println!("To get started, try one of the following commands:"); | ||
for cmd in suggestions { | ||
println!("- `x.py {}`", cmd); | ||
} | ||
|
||
if include_name != "user" { | ||
println!( | ||
"For more suggestions, see https://rustc-dev-guide.rust-lang.org/building/suggested.html" | ||
); | ||
} | ||
} | ||
|
||
// Used to get the path for `Subcommand::Setup` | ||
pub fn interactive_path() -> io::Result<String> { | ||
let mut input = String::new(); | ||
println!( | ||
"Welcome to the Rust project! What do you want to do with x.py? | ||
a) Contribute to the standard library | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
b) Contribute to the compiler | ||
c) Contribute to the compiler, and also modify LLVM or codegen | ||
d) Install Rust from source" | ||
); | ||
let template = loop { | ||
print!("Please choose one (a/b/c/d): "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interested in suggestions on how to make this more friendly than a/b/c/d :) |
||
io::stdout().flush()?; | ||
io::stdin().read_line(&mut input)?; | ||
break match input.trim().to_lowercase().as_str() { | ||
"a" | "lib" | "library" => "library", | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"b" | "compiler" => "compiler", | ||
"c" | "llvm" => "llvm", | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"d" | "user" | "maintainer" => "maintainer", | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ => { | ||
println!("error: unrecognized option '{}'", input.trim()); | ||
println!("note: press Ctrl+C to exit"); | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
} | ||
}; | ||
}; | ||
Ok(template.to_owned()) | ||
} |
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.