-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Remove unused version handling
Previously (before open sourcing Hipcheck) we'd update the `Cargo.toml` file for the Hipcheck crate after releasing a new version to reflect that we're now working on a pre-release of the _next_ version, and we had special handling in Hipcheck itself to identify at build time when we were building one of these pre-release versions and add the commit hash of the repository itself to Hipcheck's version. This was cool, and the idea was to make it obvious when you were running a pre-release build of Hipcheck and _which_ pre-release build you were running. However, when we transitioned to open source, we changed how releases happen, and stopped doing the pre-release marking, which means this special handling code hadn't been used at all since then. What's more, it's an extra piece of complexity that we've been carrying around. Rather than try to once again change our release flow, I'm removing the special handling code since it's unused. Signed-off-by: Andrew Lilley Brinker <[email protected]>
- Loading branch information
1 parent
3963760
commit 7a23a93
Showing
4 changed files
with
3 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use anyhow::anyhow; | ||
use anyhow::Context as _; | ||
use anyhow::Result; | ||
use std::convert::AsRef; | ||
use std::ffi::OsStr; | ||
use std::iter::IntoIterator; | ||
use std::ops::Not as _; | ||
use std::path::Path; | ||
use std::process::Command; | ||
use which::which; | ||
|
||
fn main() -> Result<()> { | ||
let repo_dir = env!("CARGO_MANIFEST_DIR", "can't find Cargo manifest directory"); | ||
let head = get_head_commit(repo_dir).unwrap_or_default(); | ||
|
||
fn main() -> anyhow::Result<()> { | ||
tonic_build::compile_protos("proto/hipcheck.proto")?; | ||
|
||
println!("cargo:rustc-env=HC_HEAD_COMMIT={}", head); | ||
Ok(()) | ||
} | ||
|
||
fn get_head_commit<P: AsRef<Path>>(path: P) -> Result<String> { | ||
fn inner(path: &Path) -> Result<String> { | ||
let output = GitCommand::for_repo(path, ["rev-parse", "--short", "HEAD"])? | ||
.output() | ||
.context("can't get HEAD commit hash")?; | ||
|
||
Ok(output.trim().to_owned()) | ||
} | ||
|
||
inner(path.as_ref()) | ||
} | ||
|
||
struct GitCommand { | ||
command: Command, | ||
} | ||
|
||
impl GitCommand { | ||
fn for_repo<I, S>(repo_path: &Path, args: I) -> Result<GitCommand> | ||
where | ||
I: IntoIterator<Item = S> + Copy, | ||
S: AsRef<OsStr>, | ||
{ | ||
// Init the command. | ||
let git_path = which("git").context("can't find git command")?; | ||
let mut command = Command::new(git_path); | ||
command.args(args); | ||
|
||
// Set the path if necessary | ||
command.current_dir(repo_path); | ||
|
||
if cfg!(windows) { | ||
// this method is broken on Windows. See: https://github.com/rust-lang/rust/issues/31259 | ||
//command.env_clear() | ||
} else { | ||
command.env_clear(); | ||
}; | ||
|
||
Ok(GitCommand { command }) | ||
} | ||
|
||
fn output(&mut self) -> Result<String> { | ||
let output = self.command.output()?; | ||
|
||
if output.status.success() { | ||
let output_text = String::from_utf8_lossy(&output.stdout).to_string(); | ||
return Ok(output_text); | ||
} | ||
|
||
match String::from_utf8(output.stderr) { | ||
Ok(msg) if msg.is_empty().not() => Err(anyhow!( | ||
"git failed with message '{}' [status: {}]", | ||
msg.trim(), | ||
output.status | ||
)), | ||
_ => Err(anyhow!("git failed [status: {}]", output.status)), | ||
} | ||
} | ||
} |
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