Skip to content

Commit d5df810

Browse files
committed
Updates to comments and tests
Co-authored-by: Ryan Bottriell <[email protected]> Signed-off-by: David Gilligan-Cook <[email protected]>
1 parent 2d07c49 commit d5df810

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

crates/spk-cli/group2/src/cmd_new.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ fn get_stub(name: &PkgNameBuf) -> String {
4444
4545
build:
4646
47-
# Set what level of host compatibility the built package should have:
48-
# - full: package can be used on any OS and any architecture
49-
# - os: package can be used anywhere that has the same OS type (mac, linux, windows)
50-
# - arch: package can be used anywhere that has the same OS and CPU architecture (x86_64, i386)
51-
# - distro: package can only be used on the same OS, CPU, and OS distribution version (eg linux distro)
52-
host_compat: distro
47+
# set which host related vars are added automatically to the built package:
48+
# - Distro: adds 'distro', 'arch', 'os' and '<distroname>' vars, so the package
49+
# can only be used on the same OS, CPU, and OS distribution version
50+
# (e.g. linux distro). This is the default.
51+
# - Arch: adds 'arch' and 'os' vars, so the package can be used anywhere that
52+
# has the same OS and CPU architecture (x86_64, i386)
53+
# - Os: adds 'os' var, so the package can be used anywhere that has the same
54+
# OS type (mac, linux, windows)
55+
# - None: adds no host vars, so package can be used on any OS and any architecture
56+
auto_host_vars: Distro
5357
5458
# options are all the inputs to the package build process, including
5559
# build-time dependencies

crates/spk-schema/crates/foundation/src/name/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ impl OptName {
238238

239239
impl OptNameBuf {
240240
/// Construct a valid OptNameBuf, invalid characters will be
241-
/// removed, the length will be padded or truncates, and uppercase
242-
/// letter will be lowercased to make a valid option name.
241+
/// removed, the length will be padded or truncated, and uppercase
242+
/// letters will be lowercased to make a valid option name.
243243
pub fn new_lossy<S: AsRef<str>>(s: &S) -> OptNameBuf {
244244
if validate_opt_base_name(s).is_ok() {
245245
return unsafe { OptNameBuf::from_string(s.as_ref().to_string()) };

crates/spk-schema/src/build_spec_test.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn test_host_compat_default() {
1919
#[case("None", true)]
2020
#[case("Tuesday", false)]
2121
fn test_build_spec_with_host_opt_value(#[case] value: &str, #[case] expected_result: bool) {
22-
// Tests the host_compat value is valid
22+
// Tests the auto_host_vars value is valid
2323
let res: serde_yaml::Result<BuildSpec> = serde_yaml::from_str(&format!(
2424
"{{
2525
auto_host_vars: {value},
@@ -38,7 +38,7 @@ fn test_build_spec_with_host_opt_contains_expected_names(
3838
#[case] value: &str,
3939
#[case] expected_names: Vec<String>,
4040
) {
41-
// Test the host_compat value generates the expected named options
41+
// Test the auto_host_vars value generates the expected named options
4242
let res: serde_yaml::Result<BuildSpec> = serde_yaml::from_str(&format!(
4343
"{{
4444
auto_host_vars: {value},
@@ -75,9 +75,9 @@ fn test_build_spec_with_host_opt_does_not_have_disallowed_names(
7575
#[case] value: &str,
7676
#[case] invalid_names: Vec<&str>,
7777
) {
78-
// Test the host_compat value does not create the options names
78+
// Test the auto_host_vars value does not create the options names
7979
// that are disallowed by that value. This test will have to
80-
// change if the host_compat validation is disabled.
80+
// change if the host compat validation is disabled.
8181
let res: serde_yaml::Result<BuildSpec> = serde_yaml::from_str(&format!(
8282
"{{
8383
auto_host_vars: {value},
@@ -110,13 +110,14 @@ fn test_build_spec_with_host_opt_does_not_have_disallowed_names(
110110
}
111111
}
112112

113-
// #[case("distro")] - not checked, it has no disallowed names
114113
#[rstest]
114+
#[should_panic] // distro has no disallowed names
115+
#[case("distro")]
115116
#[case("Arch")]
116117
#[case("Os")]
117118
#[case("None")]
118119
fn test_build_spec_with_host_opt_and_disallowed_name(#[case] value: &str) {
119-
// Test the host_compat value setting causes an error when there's
120+
// Test the auto_host_vars value setting causes an error when there's
120121
// a disallowed option name in the build options.
121122
let res: serde_yaml::Result<BuildSpec> = serde_yaml::from_str(&format!(
122123
"{{
@@ -132,7 +133,7 @@ fn test_build_spec_with_host_opt_and_disallowed_name(#[case] value: &str) {
132133
let result = build_spec.opts_for_variant(&build_spec.variants[0]);
133134
assert!(result.is_ok())
134135
}
135-
Err(err) => panic!("Fail: build spec didn't parse with host_compat {value}: {err:?}"),
136+
Err(err) => panic!("Fail: build spec didn't parse with 'auto_host_vars: {value}': {err:?}"),
136137
}
137138
}
138139

docs/ref/spec.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Fetches and extracts a tar archive as package source files.
7272
| options | _List[[BuildOption](#buildoption)]_ | The set of inputs for the package build process |
7373
| variants | _List[[OptionMap](#optionmap)]_ | The default variants of the package options to build |
7474
| validation | _[ValidationSpec](#validationspec)_ | Modifies the default package validation process |
75-
| auto_host_vars | _[HostCompat](#hostcompat)_ | The host compatibility setting for the package's builds. It covers distro, arch, os, and distro version |
75+
| auto_host_vars | _[HostCompat](#hostcompat)_ | The host compatibility setting for the package's builds. Depending on the value, it injects build options like distro, arch, os, and distro version |
7676

7777
### BuildOption
7878

@@ -126,7 +126,7 @@ options to each build, as described in the table:
126126

127127
| Value | Adds these host options |
128128
| ---------- | ---------------------------------------------- |
129-
| **Distro** | "distro", "arch", "os", and the "<distroname>" |
129+
| **Distro** (default) | "distro", "arch", "os", and the "<distroname>" |
130130
| **Arch** | "arch", "os", and the "<distroname>" |
131131
| **Os** | "os" |
132132
| **None** | |

0 commit comments

Comments
 (0)