Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
- script: Upgrade the templating engine from Tera 1 to Tera 2. Custom templates passed to `bender script template --template` may need updating. See the [Tera migration guide](https://github.com/Keats/tera/blob/master/MIGRATION.md) for the full list. The output of all built-in formats is unchanged.

### Added
- Add `checkout_store` config field to share git checkouts across projects, one per dependency URL and locked revision (https://github.com/pulp-platform/bender/pull/376).
- script: expose `all_headers` to templates — the fine-grained, transitive, deduplicated set of header files Slang resolved via `` `include `` for the kept trees. Populated whenever the Slang pass runs (`--top`/`--trim-incdirs`/`--broken`/`--encrypted`).

### Changed
Expand Down
6 changes: 6 additions & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Optional override for the directory that holds the bare git repositories and the

> **Note:** Bender versions before 0.32 silently ignore this field and fall back to their per-project default, so it is safe to ship in a shared configuration that mixed bender versions may read.

### `checkout_store`
Optional directory of git checkouts shared across projects. Each git dependency is checked out once per URL and locked revision, at `<checkout_store>/<name>-<hash>/<revision>/`, and every project locked to that revision uses that checkout instead of its own. Unless `db_dir` is set, the bare repositories the checkouts borrow their objects from live under `<checkout_store>/git/db/`. Treat the checkouts as read-only; use `bender clone` to modify a dependency. Projects with a [`workspace.checkout_dir`](./manifest.md) keep their own checkouts.
- **Config Key:** `checkout_store`
- **Default:** unset (checkouts follow `database`).
- **Example:** `checkout_store: /var/cache/bender_checkouts`

### `git`
The command or path used to invoke Git.
- **Config Key:** `git`
Expand Down
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ fn load_config(from: &Path, warn_config_loaded: bool) -> Result<Config> {
db_dir: std::env::var("BENDER_DB_DIR")
.ok()
.filter(|s| !s.is_empty()),
checkout_store: None,
git: Some("git".into()),
overrides: None,
plugins: None,
Expand Down
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,9 @@ pub struct Config {
/// these two specific paths; checkouts and everything else still derive
/// from `database`.
pub db_dir: Option<PathBuf>,
/// Optional directory of git checkouts shared across projects, one per
/// dependency URL and revision.
pub checkout_store: Option<PathBuf>,
/// The git command or path to the binary.
pub git: String,
/// The dependency overrides.
Expand All @@ -1641,6 +1644,8 @@ pub struct PartialConfig {
pub database: Option<String>,
/// Optional override for the bare-repo and lock directory.
pub db_dir: Option<String>,
/// Optional directory of shared git checkouts.
pub checkout_store: Option<String>,
/// The git command or path to the binary.
pub git: Option<String>,
/// The dependency overrides.
Expand All @@ -1667,6 +1672,7 @@ impl PrefixPaths for PartialConfig {
Ok(PartialConfig {
database: self.database.prefix_paths(prefix)?,
db_dir: self.db_dir.prefix_paths(prefix)?,
checkout_store: self.checkout_store.prefix_paths(prefix)?,
overrides: self.overrides.prefix_paths(prefix)?,
plugins: self.plugins.prefix_paths(prefix)?,
..self
Expand All @@ -1679,6 +1685,7 @@ impl Merge for PartialConfig {
PartialConfig {
database: self.database.or(other.database),
db_dir: self.db_dir.or(other.db_dir),
checkout_store: self.checkout_store.or(other.checkout_store),
git: self.git.or(other.git),
overrides: match (self.overrides, other.overrides) {
(Some(o), None) | (None, Some(o)) => Some(o),
Expand Down Expand Up @@ -1724,6 +1731,10 @@ impl Validate for PartialConfig {
Some(d) => Some(env_path_from_string(&d)?),
None => None,
},
checkout_store: self
.checkout_store
.map(|d| env_path_from_string(&d))
.transpose()?,
git: match self.git {
Some(git) => git,
None => bail!("Git command or path to binary not configured"),
Expand Down
16 changes: 14 additions & 2 deletions src/sess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,16 @@ impl<'ctx> Session<'ctx> {
pub fn get_package_path(&self, dep_id: DependencyRef) -> PathBuf {
let dep = self.dependency(dep_id);

// With a checkout store, a git dependency's checkout is keyed by its
// URL and locked revision, so every project on that revision shares it.
if let (Some(store), DependencySource::Git(url), Some(rev), None) = (
&self.config.checkout_store,
&dep.source,
&dep.revision,
&self.manifest.workspace.checkout_dir,
) {
return store.join(self.git_db_name(&dep.name, url)).join(rev);
}
self.get_depsource_path(&dep.name, &dep.source)
}

Expand Down Expand Up @@ -586,12 +596,14 @@ impl<'ctx> Session<'ctx> {
/// The directory under which bare git databases and lock files live.
///
/// Uses `db_dir` if configured (the recommended way to share bare repos
/// across projects without relocating checkouts), otherwise falls back to
/// `database`.
/// across projects without relocating checkouts), otherwise
/// `checkout_store`, whose checkouts borrow objects from these repos, and
/// falls back to `database`.
pub fn db_parent(&self) -> &Path {
self.config
.db_dir
.as_deref()
.or(self.config.checkout_store.as_deref())
.unwrap_or(&self.config.database)
}
}
Expand Down