-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
build_helper
crate to share code between tidy and bootstrap
- Loading branch information
Showing
14 changed files
with
102 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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,8 @@ | ||
[package] | ||
name = "build_helper" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains 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,40 @@ | ||
use std::process::Command; | ||
|
||
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | ||
pub enum CiEnv { | ||
/// Not a CI environment. | ||
None, | ||
/// The Azure Pipelines environment, for Linux (including Docker), Windows, and macOS builds. | ||
AzurePipelines, | ||
/// The GitHub Actions environment, for Linux (including Docker), Windows and macOS builds. | ||
GitHubActions, | ||
} | ||
|
||
impl CiEnv { | ||
/// Obtains the current CI environment. | ||
pub fn current() -> CiEnv { | ||
if std::env::var("TF_BUILD").map_or(false, |e| e == "True") { | ||
CiEnv::AzurePipelines | ||
} else if std::env::var("GITHUB_ACTIONS").map_or(false, |e| e == "true") { | ||
CiEnv::GitHubActions | ||
} else { | ||
CiEnv::None | ||
} | ||
} | ||
|
||
pub fn is_ci() -> bool { | ||
Self::current() != CiEnv::None | ||
} | ||
|
||
/// If in a CI environment, forces the command to run with colors. | ||
pub fn force_coloring_in_ci(self, cmd: &mut Command) { | ||
if self != CiEnv::None { | ||
// Due to use of stamp/docker, the output stream of rustbuild is not | ||
// a TTY in CI, so coloring is by-default turned off. | ||
// The explicit `TERM=xterm` environment is needed for | ||
// `--color always` to actually work. This env var was lost when | ||
// compiling through the Makefile. Very strange. | ||
cmd.env("TERM", "xterm").args(&["--color", "always"]); | ||
} | ||
} | ||
} |
This file contains 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,30 @@ | ||
use std::process::Command; | ||
|
||
/// Finds the remote for rust-lang/rust. | ||
/// For example for these remotes it will return `upstream`. | ||
/// ```text | ||
/// origin https://github.com/Nilstrieb/rust.git (fetch) | ||
/// origin https://github.com/Nilstrieb/rust.git (push) | ||
/// upstream https://github.com/rust-lang/rust (fetch) | ||
/// upstream https://github.com/rust-lang/rust (push) | ||
/// ``` | ||
pub fn get_rust_lang_rust_remote() -> Result<String, String> { | ||
let mut git = Command::new("git"); | ||
git.args(["config", "--local", "--get-regex", "remote\\..*\\.url"]); | ||
|
||
let output = git.output().map_err(|err| format!("{err:?}"))?; | ||
if !output.status.success() { | ||
return Err("failed to execute git config command".to_owned()); | ||
} | ||
|
||
let stdout = String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))?; | ||
|
||
let rust_lang_remote = stdout | ||
.lines() | ||
.find(|remote| remote.contains("rust-lang")) | ||
.ok_or_else(|| "rust-lang/rust remote not found".to_owned())?; | ||
|
||
let remote_name = | ||
rust_lang_remote.split('.').nth(1).ok_or_else(|| "remote name not found".to_owned())?; | ||
Ok(remote_name.into()) | ||
} |
This file contains 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,2 @@ | ||
pub mod ci; | ||
pub mod git; |
This file contains 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 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