Skip to content

Commit

Permalink
Merge branch 'bugfix/script-cargo-emits'
Browse files Browse the repository at this point in the history
  • Loading branch information
ventaquil committed Jan 2, 2023
2 parents dee296e + 1ebcb99 commit 3524c48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Changed `cargo:rust-env` to use quotes.

### Fixed

- Fixed treating version channel as stable one.

## [0.0.2] - 2022-12-28

### Added
Expand Down Expand Up @@ -52,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release.

[Unreleased]: https://github.com/ferric-bytes/chksum-build/compare/v0.0.2...HEAD
[0.0.2]: https://github.com/ferric-bytes/chksum-build/compare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/ferric-bytes/chksum-build/compare/v0.0.0...v0.0.1
[0.0.0]: https://github.com/ferric-bytes/chksum-build/releases/tag/v0.0.0
22 changes: 14 additions & 8 deletions src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use chrono::Local;

use crate::cargo::Profile;
use crate::error::Result;
use crate::rust::Toolchain;
use crate::rust::{Channel, Toolchain};

/// Wraps [`BuildScript::setup`] to return [`anyhow::Result`] instead of [`Result`].
///
Expand Down Expand Up @@ -76,7 +76,10 @@ impl BuildScript {
{
let datetime = Local::now().format("%Y-%m-%d %H:%M:%S");

writeln!(stdout, "cargo:rustc-env=CHKSUM_BUILD_INFO_BUILD_DATETIME={datetime}")?;
writeln!(
stdout,
"cargo:rustc-env=CHKSUM_BUILD_INFO_BUILD_DATETIME=\"{datetime}\""
)?;

Ok(())
}
Expand All @@ -91,7 +94,7 @@ impl BuildScript {
};

writeln!(stdout, "cargo:rustc-cfg={profile}")?;
writeln!(stdout, "cargo:rustc-env=CHKSUM_BUILD_INFO_CARGO_PROFILE={profile}")?;
writeln!(stdout, "cargo:rustc-env=CHKSUM_BUILD_INFO_CARGO_PROFILE=\"{profile}\"")?;

Ok(())
}
Expand All @@ -104,10 +107,13 @@ impl BuildScript {
let toolchain = env::var("RUSTUP_TOOLCHAIN")?;
Toolchain::from_str(&toolchain)?
};
let channel = toolchain.channel;
let channel = match toolchain.channel {
Channel::Version(_) => Channel::Stable,
channel => channel,
};

writeln!(stdout, "cargo:rustc-cfg={channel}")?;
writeln!(stdout, "cargo:rustc-env=CHKSUM_BUILD_INFO_RUST_CHANNEL={channel}")?;
writeln!(stdout, "cargo:rustc-env=CHKSUM_BUILD_INFO_RUST_CHANNEL=\"{channel}\"")?;

Ok(())
}
Expand All @@ -124,7 +130,7 @@ mod tests {
assert_eq!(
stdout.to_string(),
format!(
"cargo:rustc-env=CHKSUM_BUILD_INFO_BUILD_DATETIME={}\n",
"cargo:rustc-env=CHKSUM_BUILD_INFO_BUILD_DATETIME=\"{}\"\n",
Local::now().format("%Y-%m-%d %H:%M:%S")
)
);
Expand All @@ -138,7 +144,7 @@ mod tests {
assert!(BuildScript::default().setup_cargo(&mut stdout).is_ok());
assert_eq!(
stdout.to_string(),
"cargo:rustc-cfg=release\ncargo:rustc-env=CHKSUM_BUILD_INFO_CARGO_PROFILE=release\n"
"cargo:rustc-cfg=release\ncargo:rustc-env=CHKSUM_BUILD_INFO_CARGO_PROFILE=\"release\"\n"
);
}

Expand All @@ -150,7 +156,7 @@ mod tests {
assert!(BuildScript::default().setup_rust(&mut stdout).is_ok());
assert_eq!(
stdout.to_string(),
"cargo:rustc-cfg=nightly\ncargo:rustc-env=CHKSUM_BUILD_INFO_RUST_CHANNEL=nightly\n"
"cargo:rustc-cfg=nightly\ncargo:rustc-env=CHKSUM_BUILD_INFO_RUST_CHANNEL=\"nightly\"\n"
);
}
}

0 comments on commit 3524c48

Please sign in to comment.