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

make crates.io version not depend on the git tool #259

Merged
merged 4 commits into from
Nov 16, 2020
Merged

make crates.io version not depend on the git tool #259

merged 4 commits into from
Nov 16, 2020

Conversation

japaric
Copy link
Member

@japaric japaric commented Nov 16, 2020

also error if git version is used but git is not installed
prompt the user to install git in that case

fixes #256


we need git when the git version is used because we use the commit hash to check if probe-run is compatible with the firmware-side defmt
instead of panicking when git is not installed we could:

  • depend on the libgit2 crate and use that to retrieve the commit hash (from what I remember libgit2 is as, or more, annoying to install as git on Windows (not WSL))
  • implement git rev-parse HEAD using just the std library. It seems reading the .git/HEAD file and then reading the file specified there (e.g. .git/refs/heads/main, which contains the full hash) should do the trick but it does feel a bit brittle

also error if git version is used but `git` is not installed
prompt the user to install `git` in that case

fixes #256
String::from_utf8(output.stdout).unwrap()
let hash = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output() call itself will fail if the program cannot be found, so I don't think the fix can use .map

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original was not checking the .git path if git was not installed but the new version should

} else {
assert!(!Path::new(".git").exists(), "you need to install the `git` command line tool to install the git version of `probe-run`");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test that this is the right path? I'm not sure in which working directory build scripts are executed. If it's the Cargo workspace root this seems correct, but it seems like it might be the package root, which means that this would be wrong for the decoder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there's an old commit that removes a panic!("{:?}, env::current_dir()) statement from the build script. I used to inspect the directory from which the build script was invoked. It was the package root and not the workspace root.

I guess I could also use CARGO_MANIFEST_DIR (was that the path to the directory that contains the Cargo.toml file?) instead of relying on current_dir. Perhaps that'd be more reliable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way seems fine to me

@japaric japaric merged commit cdb2f7c into main Nov 16, 2020
@japaric japaric deleted the gh256 branch November 16, 2020 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using defmt on WSL provides a cryptic error message if git is missing
2 participants