Skip to content

Commit d2e6edd

Browse files
committed
Clean out basedir intermediate step, use basedirs
1 parent 9eb3241 commit d2e6edd

File tree

8 files changed

+82
-117
lines changed

8 files changed

+82
-117
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,19 @@ This is most useful when using sccache for Rust compilation, as rustc supports u
278278

279279
---
280280

281-
Normalizing Paths with `SCCACHE_BASEDIR`
281+
Normalizing Paths with `SCCACHE_BASEDIRS`
282282
-----------------------------------------
283283

284-
By default, sccache requires absolute paths to match for cache hits. To enable cache sharing across different build directories, you can set `SCCACHE_BASEDIR` to strip a base directory from paths before hashing:
284+
By default, sccache requires absolute paths to match for cache hits. To enable cache sharing across different build directories, you can set `SCCACHE_BASEDIRS` to strip a base directory from paths before hashing:
285285

286286
```bash
287-
export SCCACHE_BASEDIR=/home/user/project
287+
export SCCACHE_BASEDIRS=/home/user/project
288288
```
289289

290290
You can also specify multiple base directories by separating them with `|` (pipe character). When multiple directories are provided, the longest matching prefix is used:
291291

292292
```bash
293-
export SCCACHE_BASEDIR="/home/user/project|/home/user/workspace"
293+
export SCCACHE_BASEDIRS="/home/user/project|/home/user/workspace"
294294
```
295295

296296
This is similar to ccache's `CCACHE_BASEDIR` and helps when:
@@ -305,10 +305,10 @@ You can also configure this in the sccache config file:
305305

306306
```toml
307307
# Single directory
308-
basedir = "/home/user/project"
308+
basedirs = ["/home/user/project"]
309309

310310
# Or multiple directories
311-
basedir = ["/home/user/project", "/home/user/workspace"]
311+
basedirs = ["/home/user/project", "/home/user/workspace"]
312312
```
313313

314314
---
@@ -318,7 +318,7 @@ Known Caveats
318318

319319
### General
320320

321-
* By default, absolute paths to files must match to get a cache hit. To work around this, use `SCCACHE_BASEDIR` (see above) to normalize paths before hashing.
321+
* By default, absolute paths to files must match to get a cache hit. To work around this, use `SCCACHE_BASEDIRS` (see above) to normalize paths before hashing.
322322

323323
### Rust
324324

docs/Configuration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ server_startup_timeout_ms = 10000
99
# Base directory (or directories) to strip from paths for cache key computation.
1010
# Similar to ccache's CCACHE_BASEDIR. This enables cache hits across
1111
# different absolute paths when compiling the same source code.
12-
# Can be a single path or an array of paths. When multiple paths are provided,
12+
# Can be an array of paths. When multiple paths are provided,
1313
# the longest matching prefix is used.
1414
# For example, if basedir is "/home/user/project", then paths like
1515
# "/home/user/project/src/main.c" will be normalized to "./src/main.c"
1616
# for caching purposes.
17-
basedir = "/home/user/project"
17+
basedirs = ["/home/user/project"]
1818
# Or multiple directories:
19-
# basedir = ["/home/user/project", "/home/user/workspace"]
19+
# basedirs = ["/home/user/project", "/home/user/workspace"]
2020

2121
[dist]
2222
# where to find the scheduler
@@ -146,7 +146,7 @@ Note that some env variables may need sccache server restart to take effect.
146146

147147
* `SCCACHE_ALLOW_CORE_DUMPS` to enable core dumps by the server
148148
* `SCCACHE_CONF` configuration file path
149-
* `SCCACHE_BASEDIR` base directory (or directories) to strip from paths for cache key computation. This is similar to ccache's `CCACHE_BASEDIR` and enables cache hits across different absolute paths when compiling the same source code. Multiple directories can be separated by `|` (pipe character). When multiple directories are specified, the longest matching prefix is used. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will be ignored with a warning.
149+
* `SCCACHE_BASEDIRS` base directory (or directories) to strip from paths for cache key computation. This is similar to ccache's `CCACHE_BASEDIR` and enables cache hits across different absolute paths when compiling the same source code. Multiple directories can be separated by `|` (pipe character). When multiple directories are specified, the longest matching prefix is used. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will be ignored with a warning.
150150
* `SCCACHE_CACHED_CONF`
151151
* `SCCACHE_IDLE_TIMEOUT` how long the local daemon process waits for more client requests before exiting, in seconds. Set to `0` to run sccache permanently
152152
* `SCCACHE_STARTUP_NOTIFY` specify a path to a socket which will be used for server completion notification

src/cache/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ pub fn storage_from_config(
743743

744744
// Validate that all basedirs are absolute paths
745745
let basedirs: Vec<PathBuf> = config
746-
.basedir
746+
.basedirs
747747
.iter()
748748
.filter_map(|p| {
749749
if p.is_absolute() {

src/compiler/c.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ mod test {
18031803
}
18041804

18051805
#[test]
1806-
fn test_hash_key_basedir() {
1806+
fn test_hash_key_basedirs() {
18071807
use std::path::PathBuf;
18081808

18091809
let args = ovec!["a", "b", "c"];
@@ -1813,8 +1813,10 @@ mod test {
18131813
let preprocessed1 = b"# 1 \"/home/user1/project/src/main.c\"\nint main() { return 0; }";
18141814
let preprocessed2 = b"# 1 \"/home/user2/project/src/main.c\"\nint main() { return 0; }";
18151815

1816-
let basedir1 = PathBuf::from("/home/user1/project");
1817-
let basedir2 = PathBuf::from("/home/user2/project");
1816+
let basedirs = [
1817+
PathBuf::from("/home/user1/project"),
1818+
PathBuf::from("/home/user2/project"),
1819+
];
18181820

18191821
let h1 = hash_key(
18201822
digest,
@@ -1824,7 +1826,7 @@ mod test {
18241826
&[],
18251827
preprocessed1,
18261828
false,
1827-
std::slice::from_ref(&basedir1),
1829+
&basedirs,
18281830
);
18291831
let h2 = hash_key(
18301832
digest,
@@ -1834,7 +1836,7 @@ mod test {
18341836
&[],
18351837
preprocessed2,
18361838
false,
1837-
std::slice::from_ref(&basedir2),
1839+
&basedirs,
18381840
);
18391841

18401842
assert_eq!(h1, h2);
@@ -1877,7 +1879,7 @@ mod test {
18771879
&[],
18781880
preprocessed_cpp1,
18791881
true,
1880-
std::slice::from_ref(&basedir1),
1882+
&basedirs,
18811883
);
18821884
let h_cpp2 = hash_key(
18831885
digest,
@@ -1887,7 +1889,7 @@ mod test {
18871889
&[],
18881890
preprocessed_cpp2,
18891891
true,
1890-
std::slice::from_ref(&basedir2),
1892+
&basedirs,
18911893
);
18921894

18931895
assert_eq!(h_cpp1, h_cpp2);

0 commit comments

Comments
 (0)