Skip to content

Commit

Permalink
Rename "dep" to "from"
Browse files Browse the repository at this point in the history
"dep" was short for "dependent", but it seemed like people would
probably think it was short for "dependency" which is the oppostite
direction to what it's doing, so could have caused confusion. There's
probably no perfect name here, but "from.test.allow_apis" reads nicely
in the configuration file.
  • Loading branch information
davidlattimore committed Sep 19, 2023
1 parent a034079 commit c437be0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ from test code, we can do that as follows:

```toml
[pkg.crab1]
dep.test.allow_apis = [
from.test.allow_apis = [
"fs",
]
```
Expand All @@ -70,7 +70,7 @@ Similarly, we can allow the API to be used, but only in code that is reachable f

```toml
[pkg.crab1]
dep.build.allow_apis = [
from.build.allow_apis = [
"fs",
]
```
Expand All @@ -87,9 +87,9 @@ build.allow_apis = [
Allowed APIs inherit as follows:

* pkg.N
* pkg.N.dep.build (any build script)
* pkg.N.from.build (any build script)
* pkg.N.build (N's build script)
* pkg.N.dep.test (any test)
* pkg.N.from.test (any test)
* pkg.N.test (N's tests)

So granting an API usage to `pkg.N` means it can be used in any kind of binary.
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub(crate) struct PackageConfig {
pub(crate) test: Option<Box<PackageConfig>>,

#[serde()]
pub(crate) dep: Option<DepConfig>,
pub(crate) from: Option<FromConfig>,

#[serde()]
pub(crate) sandbox: Option<SandboxConfig>,
Expand All @@ -159,7 +159,7 @@ pub(crate) struct PackageConfig {

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default)]
#[serde(deny_unknown_fields)]
pub(crate) struct DepConfig {
pub(crate) struct FromConfig {
pub(crate) build: Option<Box<PackageConfig>>,
pub(crate) test: Option<Box<PackageConfig>>,
}
Expand Down
42 changes: 21 additions & 21 deletions src/config/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ pub(crate) enum PermissionScope {
Test,
/// Permission is granted to the package, but only when used via build scripts of other
/// packages.
DepBuild,
FromBuild,
/// Permission is granted to the package, but only when used via tests of other packages.
DepTest,
FromTest,
}

impl Permissions {
Expand Down Expand Up @@ -83,12 +83,12 @@ impl Permissions {
*sub_cfg,
);
}
if let Some(mut dep) = pkg_config.dep.take() {
if let Some(mut dep) = pkg_config.from.take() {
if let Some(sub_cfg) = dep.build.take() {
packages.insert(
PermSel {
package_name: name.clone(),
scope: PermissionScope::DepBuild,
scope: PermissionScope::FromBuild,
},
*sub_cfg,
);
Expand All @@ -97,7 +97,7 @@ impl Permissions {
packages.insert(
PermSel {
package_name: name.clone(),
scope: PermissionScope::DepTest,
scope: PermissionScope::FromTest,
},
*sub_cfg,
);
Expand Down Expand Up @@ -163,8 +163,8 @@ fn apply_inheritance(packages: &mut FxHashMap<PermSel, PackageConfig>, config: &
PermissionScope::All => all.insert(perm_sel, config),
PermissionScope::Build => local.insert(perm_sel, config),
PermissionScope::Test => local.insert(perm_sel, config),
PermissionScope::DepBuild => dep.insert(perm_sel, config),
PermissionScope::DepTest => dep.insert(perm_sel, config),
PermissionScope::FromBuild => dep.insert(perm_sel, config),
PermissionScope::FromTest => dep.insert(perm_sel, config),
};
}

Expand All @@ -179,8 +179,8 @@ fn apply_inheritance(packages: &mut FxHashMap<PermSel, PackageConfig>, config: &
}
for (perm_sel, config) in local.iter_mut() {
let parent_scope = match perm_sel.scope {
PermissionScope::Build => PermissionScope::DepBuild,
PermissionScope::Test => PermissionScope::DepTest,
PermissionScope::Build => PermissionScope::FromBuild,
PermissionScope::Test => PermissionScope::FromTest,
_ => unreachable!(),
};
if let Some(parent) = dep.get(&perm_sel.clone_with_scope(parent_scope)) {
Expand Down Expand Up @@ -282,20 +282,20 @@ impl PermSel {
pub(crate) fn parent_scope(&self) -> Option<PermissionScope> {
match self.scope {
PermissionScope::All => None,
PermissionScope::Build => Some(PermissionScope::DepBuild),
PermissionScope::Test => Some(PermissionScope::DepTest),
PermissionScope::DepBuild => Some(PermissionScope::All),
PermissionScope::DepTest => Some(PermissionScope::All),
PermissionScope::Build => Some(PermissionScope::FromBuild),
PermissionScope::Test => Some(PermissionScope::FromTest),
PermissionScope::FromBuild => Some(PermissionScope::All),
PermissionScope::FromTest => Some(PermissionScope::All),
}
}

fn child_scopes(&self) -> &'static [PermissionScope] {
match self.scope {
PermissionScope::All => &[PermissionScope::DepBuild, PermissionScope::DepTest],
PermissionScope::All => &[PermissionScope::FromBuild, PermissionScope::FromTest],
PermissionScope::Build => &[],
PermissionScope::Test => &[],
PermissionScope::DepBuild => &[PermissionScope::Build],
PermissionScope::DepTest => &[PermissionScope::Test],
PermissionScope::FromBuild => &[PermissionScope::Build],
PermissionScope::FromTest => &[PermissionScope::Test],
}
}

Expand Down Expand Up @@ -332,8 +332,8 @@ impl PermissionScope {
Self::All => None,
Self::Build => Some("build"),
Self::Test => Some("test"),
Self::DepBuild => Some("dep.build"),
Self::DepTest => Some("dep.test"),
Self::FromBuild => Some("from.build"),
Self::FromTest => Some("from.test"),
}
}

Expand All @@ -347,8 +347,8 @@ impl PermissionScope {
} else {
match bin_selector.kind {
CrateKind::Primary => PermissionScope::All,
CrateKind::BuildScript => PermissionScope::DepBuild,
CrateKind::Test => PermissionScope::DepTest,
CrateKind::BuildScript => PermissionScope::FromBuild,
CrateKind::Test => PermissionScope::FromTest,
}
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ fn test_inheritance() {
}

let bar1 = PermSel::for_primary("bar1");
let bar1_dep_test = bar1.clone_with_scope(PermissionScope::DepTest);
let bar1_dep_test = bar1.clone_with_scope(PermissionScope::FromTest);
let mut crate_index = CrateIndex::default();
crate_index
.permission_selectors
Expand Down
4 changes: 2 additions & 2 deletions src/config_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,10 @@ impl Edit for AllowApiUsage {
crate::config::permissions::PermissionScope::Test => {
format!("Allow `{pkg}` to use `{api}` in its own tests").into()
}
crate::config::permissions::PermissionScope::DepBuild => {
crate::config::permissions::PermissionScope::FromBuild => {
format!("Allow `{pkg}` to use `{api}` in any build script").into()
}
crate::config::permissions::PermissionScope::DepTest => {
crate::config::permissions::PermissionScope::FromTest => {
format!("Allow `{pkg}` to use `{api}` in any test").into()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) fn validate(config: &Config, config_path: &Path) -> Result<(), Invali
if crate_config.test.is_some() {
problems.push(Problem::InvalidPkgSelector(format!("{perm_sel}.test")));
}
if crate_config.dep.is_some() {
if crate_config.from.is_some() {
problems.push(Problem::InvalidPkgSelector(format!("{perm_sel}.dep")));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/crate_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ fn add_permission_selectors(
) {
let perm_sel = PermSel::for_primary(pkg_name);
permission_selectors.insert(perm_sel.clone());
permission_selectors.insert(perm_sel.clone_with_scope(PermissionScope::DepBuild));
permission_selectors.insert(perm_sel.clone_with_scope(PermissionScope::DepTest));
permission_selectors.insert(perm_sel.clone_with_scope(PermissionScope::FromBuild));
permission_selectors.insert(perm_sel.clone_with_scope(PermissionScope::FromTest));
if has_build_script {
permission_selectors.insert(perm_sel.clone_with_scope(PermissionScope::Build));
}
Expand Down
8 changes: 4 additions & 4 deletions src/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ impl Display for ApiUsages {
write!(f, "`{}` uses API `{}`", self.pkg_id, self.api_name)?;
match self.scope {
PermissionScope::All => {}
PermissionScope::Build => " from its build script".fmt(f)?,
PermissionScope::Test => " from its test(s)".fmt(f)?,
PermissionScope::DepBuild => " via a build script in another package".fmt(f)?,
PermissionScope::DepTest => " via a test in another package".fmt(f)?,
PermissionScope::Build => " in its build script".fmt(f)?,
PermissionScope::Test => " in its test(s)".fmt(f)?,
PermissionScope::FromBuild => " from a build script in another package".fmt(f)?,
PermissionScope::FromTest => " from a test in another package".fmt(f)?,
}
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions test_crates/cackle.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ build.allow_apis = [
"net",
]
build.sandbox.allow_network = true
dep.test.allow_apis = [
from.test.allow_apis = [
"unix_sockets",
]

Expand Down Expand Up @@ -108,7 +108,7 @@ allow_unsafe = true
[pkg.crab-5]
allow_apis = [
]
dep.build.allow_apis = [
from.build.allow_apis = [
"fs",
]

Expand Down

0 comments on commit c437be0

Please sign in to comment.