Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
raldone01 committed Dec 23, 2024
1 parent b32e27b commit 7d6ad9f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.0] - 2024-12-23

* Added proper support for workspace dependencies.
* Added support for target-specific dependencies.
* Added a proper test suite.

## [0.1.0] - 2024-12-19

Support reactive compilation using `proc_macro_tracked_env` and `track_path` nightly features.
Expand All @@ -14,6 +20,7 @@ Support reactive compilation using `proc_macro_tracked_env` and `track_path` nig

Initial release.

[Unreleased]: https://github.com/ink-feather-org/trait-cast-rs/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/ink-feather-org/trait-cast-rs/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/ink-feather-org/trait-cast-rs/releases/tag/v0.1.0...v0.2.0
[0.1.0]: https://github.com/ink-feather-org/trait-cast-rs/releases/tag/v0.0.1...v0.1.0
[0.0.1]: https://github.com/ink-feather-org/trait-cast-rs/releases/tag/v0.0.1
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ strip = "debuginfo"

[package]
name = "cargo-manifest-proc-macros"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
license = "MIT OR Apache-2.0"
description = "Find the syn::Path to your own crate from proc-macros reliably."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl CrateReExportingPolicy for SuperCrateReExportingPolicy {

/// We need to associate the re-exporting policy with the re-exporting crate name.
const SUPER_RE_EXPORTER_RESOLVER: KnownReExportingCrate<'_> = KnownReExportingCrate {
re_exporting_crate_name: "my-awesome-super-crate",
re_exporting_crate_package_name: "my-awesome-super-crate",
crate_re_exporting_policy: &SuperCrateReExportingPolicy {},
};

Expand Down
33 changes: 17 additions & 16 deletions src/cargo_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl CargoManifest {
.map(PathBuf::from)
.map(|mut path| {
path.push("Cargo.toml");
trace!("Loading CARGO_MANIFEST_PATH={:?}", path);
trace!("Loading CARGO_MANIFEST_PATH={}", path.display());

assert!(
path.exists(),
Expand All @@ -161,7 +161,7 @@ impl CargoManifest {
);
path
})
.expect("The CARGO_MANIFEST_DIR environment variable is not defined!");
.expect("The CARGO_MANIFEST_DIR environment variable must be defined!");

let crate_manifest = CargoManifest::parse_cargo_manifest(&cargo_manifest_path);

Expand Down Expand Up @@ -296,23 +296,23 @@ impl CargoManifest {
///
/// ```toml
/// [dependencies]
/// original-crate-name = "0.1"
/// package-crate-name = "0.1"
/// ```
///
/// The function would return `Some("original-crate-name")` for the `Item` above.
/// The function would return `Ok("package-crate-name")` for the `Item` above.
///
/// For the remapped crate case:
///
/// ```toml
/// [dependencies]
/// renamed-crate-name = { version = "0.1", package = "original-crate-name" }
/// renamed-crate-name = { version = "0.1", package = "package-crate-name" }
/// ```
///
/// The function would return `Some("renamed-crate-name")` for the `Item` above.
///
/// # Errors
///
/// If the crate name is ambiguous, an error is returned.
/// If the crate name is ambiguous or not found, an error is returned.
fn try_resolve_crate_path_internal(
&self,
query_crate_name: &str,
Expand All @@ -329,7 +329,10 @@ impl CargoManifest {
return match directly_mapped_crate_name {
DependencyState::Resolved(directly_mapped_crate_name) => {
// We have a direct dependency.
trace!("Found direct dependency: {}", directly_mapped_crate_name);
trace!(
"Found direct dependency: \"{}\"",
directly_mapped_crate_name
);
Ok(crate_name_to_syn_path(directly_mapped_crate_name))
},
DependencyState::Ambiguous(crate_name) => Err(
Expand Down Expand Up @@ -390,18 +393,17 @@ impl CargoManifest {
#[must_use]
fn resolve_workspace_manifest_path(cargo_manifest_path: &Path) -> PathBuf {
let stdout = Command::new(
proc_macro::tracked_env::var("CARGO")
.expect("The CARGO environment variable is not defined."),
proc_macro::tracked_env::var("CARGO").expect("The CARGO environment variable must be set!"),
)
.arg("locate-project")
.args(["--workspace", "--message-format=plain"])
.arg(format!("--manifest-path={}", cargo_manifest_path.display()))
.output()
.expect("Failed to run `cargo locate-project`")
.expect("Failed to run `cargo locate-project`!")
.stdout;

let path_string =
String::from_utf8(stdout).expect("Failed to parse `cargo locate-project` output");
String::from_utf8(stdout).expect("Failed to parse `cargo locate-project` output!");
let path_str = path_string.trim();

let resolved_path = if path_str.is_empty() {
Expand All @@ -415,7 +417,7 @@ impl CargoManifest {
};

trace!(
"Resolved workspace manifest path: {}",
"Resolved workspace manifest path: \"{}\"",
resolved_path.display()
);

Expand Down Expand Up @@ -467,14 +469,12 @@ impl CargoManifest {
query_crate_name: &str,
known_re_exporting_crates: &[&KnownReExportingCrate<'_>],
) -> Result<syn::Path, TryResolveCratePathError> {
info!("Trying to get the path for: {query_crate_name}");

trace!("Trying to get the path for: {query_crate_name}");
info!("Trying to get the path for: \"{query_crate_name}\"");

let ret = self.try_resolve_crate_path_internal(query_crate_name, known_re_exporting_crates);

info!(
"Computed path: {:?} for {}",
"Computed path: \"{:?}\" for \"{}\"",
ret.as_ref().map(pretty_format_syn_path),
query_crate_name
);
Expand All @@ -495,6 +495,7 @@ impl CargoManifest {
}

#[cfg(test)]
#[doc(hidden)]
mod tests {
use super::*;

Expand Down

0 comments on commit 7d6ad9f

Please sign in to comment.