Skip to content

Commit 92d2ec4

Browse files
committed
Removes host_compat validation check, error, and config option
Signed-off-by: David Gilligan-Cook <[email protected]>
1 parent 727dc76 commit 92d2ec4

File tree

4 files changed

+15
-67
lines changed

4 files changed

+15
-67
lines changed

crates/spk-config/src/config.rs

-9
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ pub struct Statsd {
112112
pub format: String,
113113
}
114114

115-
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
116-
#[serde(default)]
117-
pub struct HostCompat {
118-
/// Whether to turn on host compatibility validation of the option
119-
/// names in a build spec.
120-
pub validate: bool,
121-
}
122-
123115
/// Configuration values for spk.
124116
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
125117
#[serde(default)]
@@ -131,7 +123,6 @@ pub struct Config {
131123
pub solver: Solver,
132124
pub statsd: Statsd,
133125
pub metadata: Metadata,
134-
pub host_compat: HostCompat,
135126
}
136127

137128
impl Config {

crates/spk-schema/src/build_spec.rs

+14-43
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const ANY_ADDS: &[&OptName] = &[];
3030

3131
// Each HostCompat value disallows certain var names when host_compat
3232
// validation is enabled in the config file.
33-
// TODO: move these to config
34-
const DISTRO_DISALLOWS: &[&OptName] = &[];
35-
const ARCH_DISALLOWS: &[&OptName] = &[OptName::distro()];
36-
const OS_DISALLOWS: &[&OptName] = &[OptName::distro(), OptName::arch()];
37-
const ANY_DISALLOWS: &[&OptName] = &[OptName::distro(), OptName::arch(), OptName::os()];
33+
// TODO: these will be used when the linting is added, so haven't removed them
34+
// const DISTRO_DISALLOWS: &[&OptName] = &[];
35+
// const ARCH_DISALLOWS: &[&OptName] = &[OptName::distro()];
36+
// const OS_DISALLOWS: &[&OptName] = &[OptName::distro(), OptName::arch()];
37+
// const ANY_DISALLOWS: &[&OptName] = &[OptName::distro(), OptName::arch(), OptName::os()];
3838

3939
/// Set what level of cross-platform compatibility the built package
4040
/// should have.
@@ -106,35 +106,15 @@ impl HostCompat {
106106
Ok(settings)
107107
}
108108

109-
fn names_disallowed(&self) -> &[&OptName] {
110-
match self {
111-
HostCompat::Distro => DISTRO_DISALLOWS,
112-
HostCompat::Arch => ARCH_DISALLOWS,
113-
HostCompat::Os => OS_DISALLOWS,
114-
HostCompat::Any => ANY_DISALLOWS,
115-
}
116-
}
117-
118-
/// Check the given options are compatible with the HostCompat
119-
/// setting.
120-
pub fn validate_host_opts(&self, options: &[Opt]) -> Result<()> {
121-
let known = options.iter().map(Opt::full_name).collect::<HashSet<_>>();
122-
123-
let disallowed_names = self.names_disallowed();
124-
125-
for name in disallowed_names {
126-
// If a name that this setting would add is already in the
127-
// given options then flag it as an error.
128-
if known.contains(name) {
129-
return Err(Error::HostOptionNotAllowedInVariantError(
130-
name.to_string(),
131-
self.to_string(),
132-
));
133-
}
134-
}
135-
136-
Ok(())
137-
}
109+
// TODO: comment this back in when adding linting for host_compats
110+
// fn names_disallowed(&self) -> &[&OptName] {
111+
// match self {
112+
// HostCompat::Distro => DISTRO_DISALLOWS,
113+
// HostCompat::Arch => ARCH_DISALLOWS,
114+
// HostCompat::Os => OS_DISALLOWS,
115+
// HostCompat::Any => ANY_DISALLOWS,
116+
// }
117+
//}
138118
}
139119

140120
/// A set of structured inputs used to build a package.
@@ -198,18 +178,9 @@ impl BuildSpec {
198178
}
199179
}
200180

201-
// Optionally, check the opts aren't setting an option
202-
// controlled by the host compatibility setting.
203-
let config = spk_config::get_config()?;
204-
if config.host_compat.validate {
205-
self.host_compat.validate_host_opts(&opts)?;
206-
}
207-
208181
// Add any host options that are not already present.
209182
let host_opts = self.host_compat.host_options()?;
210183
for opt in host_opts.iter() {
211-
//let mut opt = Opt::Var(VarOpt::new(name)?);
212-
//opt.set_value(value.to_string())?;
213184
if known.insert(opt.full_name().to_owned()) {
214185
opts.push(opt.clone());
215186
}

crates/spk-schema/src/build_spec_test.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,7 @@ fn test_build_spec_with_host_opt_and_disallowed_name(#[case] value: &str) {
130130
// This return an error because of the "distro/centos" var
131131
// setting in the variant
132132
let result = build_spec.opts_for_variant(&build_spec.variants[0]);
133-
let config = spk_config::get_config().unwrap();
134-
if config.host_compat.validate {
135-
// With the checks, this should fail validation
136-
assert!(result.is_err())
137-
} else {
138-
// Without the checks, this should be ok
139-
assert!(result.is_ok())
140-
}
133+
assert!(result.is_ok())
141134
}
142135
Err(err) => panic!("Fail: build spec didn't parse with host_compat {value}: {err:?}"),
143136
}

crates/spk-schema/src/error.rs

-7
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ pub enum Error {
7070
#[error("{0}: {1}")]
7171
InvalidBuildChangeSetError(String, #[source] spk_schema_validators::Error),
7272

73-
#[error("'{0}' cannot be set in a variant. The host_compatibility value '{1}' will set it.")]
74-
#[diagnostic(
75-
help("Try removing that variable (var), or changing the 'host_compat' setting"),
76-
code("spk_schema::host_option_not_allowed_in_variant")
77-
)]
78-
HostOptionNotAllowedInVariantError(String, String),
79-
8073
#[error("'{0}' not a valid distro name for 'host_compat: distro' to use as a var name: {1}")]
8174
#[diagnostic(help("The distro name comes from the host's settings and contains a value spk cannot use. Please contact your Admin to address this."),
8275
code("spk_schema::host_option_not_valid_distro_name"))]

0 commit comments

Comments
 (0)