Skip to content

Commit

Permalink
automatic_edits: Use dotted notation within packages
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlattimore committed Sep 19, 2023
1 parent ff4aab2 commit a034079
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
20 changes: 10 additions & 10 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ If for some reason you don't want to sandbox a particular build script, you can
just for that build script.

```toml
[pkg.foo.build]
sandbox.kind = "Disabled"
[pkg.foo]
build.sandbox.kind = "Disabled"
```

If a build script needs network access, you can relax the sandbox to allow it as follows:

```toml
[pkg.foo.build]
sandbox.allow_network = true
[pkg.foo]
build.sandbox.allow_network = true
```

Tests can also be run in a sandbox using the `cargo` subcommand, for example:
Expand All @@ -132,16 +132,16 @@ tests, with a sandbox if one is configured.
The sandbox used for tests is configured under `pkg.{pkg-name}.test`. e.g.:

```toml
[pkg.foo.test]
sandbox.kind = "Disabled"
[pkg.foo]
test.sandbox.kind = "Disabled"
```

Tests and build scripts already have write access to a temporary directory, however, if for some
reason they need to write to some directory in your source folder, this can be permitted as follows:

```toml
[pkg.foo.test]
sandbox.bind_writable = [
[pkg.foo]
test.sandbox.bind_writable = [
"test_outputs",
]
```
Expand All @@ -153,8 +153,8 @@ If you'd like to automatically create a writable directory if it doesn't already
`make_writable` behaves the same, but will create the directory before starting the sandbox.

```toml
[pkg.foo.test]
sandbox.make_writable = [
[pkg.foo]
test.sandbox.make_writable = [
"test_outputs",
]
```
Expand Down
25 changes: 20 additions & 5 deletions src/config_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,16 @@ impl ConfigEditor {
}

fn pkg_table(&mut self, perm_sel: &PermSel) -> Result<&mut toml_edit::Table> {
self.table(pkg_path(perm_sel))
let path = pkg_path(perm_sel);
let mut table = self.table(path.clone().take(2))?;
for part in path.skip(2) {
table = table
.entry(part)
.or_insert_with(create_dotted_table)
.as_table_mut()
.ok_or_else(|| anyhow!("[pkg.{perm_sel}] should be a table"))?;
}
Ok(table)
}

fn opt_pkg_table(&mut self, perm_sel: &PermSel) -> Result<Option<&mut toml_edit::Table>> {
Expand Down Expand Up @@ -394,6 +403,12 @@ fn create_implicit_table() -> Item {
Item::Table(table)
}

fn create_dotted_table() -> Item {
let mut table = toml_edit::Table::new();
table.set_dotted(true);
Item::Table(table)
}

struct CreateCustomConfig;

impl Edit for CreateCustomConfig {
Expand Down Expand Up @@ -1110,8 +1125,8 @@ mod tests {
&disallowed_api(pkg_id("crab1"), PermissionScope::Build, "fs"),
0,
indoc! {r#"
[pkg.crab1.build]
allow_apis = [
[pkg.crab1]
build.allow_apis = [
"fs",
]
"#,
Expand Down Expand Up @@ -1160,8 +1175,8 @@ mod tests {
&problem,
1,
indoc! {r#"
[pkg.crab1.build]
allow_build_instructions = [
[pkg.crab1]
build.allow_build_instructions = [
"cargo:rustc-env=SOME_VAR=*",
]
"#,
Expand Down

0 comments on commit a034079

Please sign in to comment.