Skip to content

Commit

Permalink
Merge pull request #1092 from varphone/develop
Browse files Browse the repository at this point in the history
Add global environment variables to the root package of the workspace
  • Loading branch information
sagiegurari authored May 31, 2024
2 parents e174180 + 6188d2d commit 8c9aee1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,14 @@ The following environment variables will be set by cargo-make if `Cargo.toml` fi
* **`CARGO_MAKE_CRATE_HOMEPAGE`** - Holds the crate homepage link from the `Cargo.toml` file in the current working directory.
* **`CARGO_MAKE_CRATE_REPOSITORY`** - Holds the crate repository link from the `Cargo.toml` file in the current working directory.

* **`CARGO_MAKE_WORKSPACE_PACKAGE_NAME`** - Holds the root package name of the workspace from the `Cargo.toml` file in the current working directory.
* **`CARGO_MAKE_WORKSPACE_PACKAGE_VERSION`** - Holds the root package version of the workspace from the `Cargo.toml` file in the current working directory.
* **`CARGO_MAKE_WORKSPACE_PACKAGE_DESCRIPTION`** - Holds the root package description of the workspace from the `Cargo.toml` file in the current working directory.
* **`CARGO_MAKE_WORKSPACE_PACKAGE_LICENSE`** - Holds the root package license of the workspace from the `Cargo.toml` file in the current working directory.
* **`CARGO_MAKE_WORKSPACE_PACKAGE_DOCUMENTATION`** - Holds the root package documentation link of the workspace from the `Cargo.toml` file in the current working directory.
* **`CARGO_MAKE_WORKSPACE_PACKAGE_HOMEPAGE`** - Holds the root package homepage link of the workspace from the `Cargo.toml` file in the current working directory.
* **`CARGO_MAKE_WORKSPACE_PACKAGE_REPOSITORY`** - Holds the root package repository link of the workspace from the `Cargo.toml` file in the current working directory.

The following environment variables will be set by cargo-make if the project is part of a git repo:

* **`CARGO_MAKE_GIT_BRANCH`** - The current branch name.
Expand Down
19 changes: 19 additions & 0 deletions src/lib/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,25 @@ fn setup_env_for_crate(home: Option<PathBuf>) -> CrateInfo {
env_options.separator = Some(",".to_string());
envmnt::set_list_with_options("CARGO_MAKE_CRATE_WORKSPACE_MEMBERS", &members, &env_options);

if let Some(package) = workspace.package.as_ref() {
envmnt::set_optional("CARGO_MAKE_WORKSPACE_PACKAGE_NAME", &package.name);
envmnt::set_optional("CARGO_MAKE_WORKSPACE_PACKAGE_VERSION", &package.version);
envmnt::set_optional(
"CARGO_MAKE_WORKSPACE_PACKAGE_DESCRIPTION",
&package.description,
);
envmnt::set_optional("CARGO_MAKE_WORKSPACE_PACKAGE_LICENSE", &package.license);
envmnt::set_optional(
"CARGO_MAKE_WORKSPACE_PACKAGE_DOCUMENTATION",
&package.documentation,
);
envmnt::set_optional("CARGO_MAKE_WORKSPACE_PACKAGE_HOMEPAGE", &package.homepage);
envmnt::set_optional(
"CARGO_MAKE_WORKSPACE_PACKAGE_REPOSITORY",
&package.repository,
);
}

// check if Cargo.lock file exists in working directory
let lock_file = Path::new("Cargo.lock");
let lock_file_exists = lock_file.exists();
Expand Down
17 changes: 17 additions & 0 deletions src/lib/execution_plan_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ fn create_workspace_task_no_members() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let task = create_workspace_task(&crate_info, "some_task");
Expand All @@ -189,6 +190,7 @@ fn create_workspace_task_with_members() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

envmnt::remove("CARGO_MAKE_USE_WORKSPACE_PROFILE");
Expand Down Expand Up @@ -235,6 +237,7 @@ fn create_workspace_task_with_members_no_workspace_profile() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

envmnt::set_bool("CARGO_MAKE_USE_WORKSPACE_PROFILE", false);
Expand Down Expand Up @@ -278,6 +281,7 @@ fn create_workspace_task_with_members_and_arguments() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

envmnt::remove("CARGO_MAKE_USE_WORKSPACE_PROFILE");
Expand Down Expand Up @@ -332,6 +336,7 @@ fn create_workspace_task_with_included_members() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

envmnt::set_list(
Expand Down Expand Up @@ -385,6 +390,7 @@ fn create_workspace_task_with_included_and_skipped_members() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

envmnt::set_list(
Expand Down Expand Up @@ -431,6 +437,7 @@ fn create_workspace_task_extend_workspace_makefile() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

envmnt::set("CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE", "true");
Expand Down Expand Up @@ -459,6 +466,7 @@ fn is_workspace_flow_true_default() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let task = Task::new();
Expand Down Expand Up @@ -486,6 +494,7 @@ fn is_workspace_flow_false_in_config() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let task = Task::new();
Expand Down Expand Up @@ -516,6 +525,7 @@ fn is_workspace_flow_true_in_config() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let task = Task::new();
Expand Down Expand Up @@ -546,6 +556,7 @@ fn is_workspace_flow_true_in_task() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let mut task = Task::new();
Expand Down Expand Up @@ -574,6 +585,7 @@ fn is_workspace_flow_default_false_in_task_and_sub_flow() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let task = Task::new();
Expand Down Expand Up @@ -601,6 +613,7 @@ fn is_workspace_flow_true_in_task_and_sub_flow() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let mut task = Task::new();
Expand Down Expand Up @@ -629,6 +642,7 @@ fn is_workspace_flow_false_in_task_and_sub_flow() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let mut task = Task::new();
Expand Down Expand Up @@ -657,6 +671,7 @@ fn is_workspace_flow_task_not_defined() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let config = Config {
Expand Down Expand Up @@ -703,6 +718,7 @@ fn is_workspace_flow_disabled_via_cli() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let mut task = Task::new();
Expand Down Expand Up @@ -731,6 +747,7 @@ fn is_workspace_flow_disabled_via_task() {
members: Some(members),
exclude: None,
dependencies: None,
package: None,
});

let mut task = Task::new();
Expand Down
4 changes: 3 additions & 1 deletion src/lib/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ pub struct Workspace {
pub exclude: Option<Vec<String>>,
/// workspace level dependencies
pub dependencies: Option<IndexMap<String, CrateDependency>>,
/// root package
pub package: Option<PackageInfo>,
}

impl Workspace {
Expand All @@ -232,7 +234,7 @@ impl Workspace {
}
}

#[derive(Deserialize, Debug, Clone, Default)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
/// Holds crate package information loaded from the Cargo.toml file package section.
pub struct PackageInfo {
/// name
Expand Down

0 comments on commit 8c9aee1

Please sign in to comment.