-
Notifications
You must be signed in to change notification settings - Fork 621
Add SCCACHE_BASEDIRS support
#2521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dc30acc
ace9c0e
dc589c0
9eb3241
d2e6edd
903bcba
6f47f36
cf0b871
99dde65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,19 @@ | |
| # If specified, wait this long for the server to start up. | ||
| server_startup_timeout_ms = 10000 | ||
|
|
||
| # Base directory (or directories) to strip from paths for cache key computation. | ||
| # Similar to ccache's CCACHE_BASEDIR. This enables cache hits across | ||
| # different absolute paths when compiling the same source code. | ||
| # Can be an array of paths. When multiple paths are provided, | ||
| # the longest matching prefix is used. | ||
| # Path matching is case-insensitive on Windows and case-sensitive on other OSes. | ||
| # For example, if basedir is "/home/user/project", then paths like | ||
| # "/home/user/project/src/main.c" will be normalized to "./src/main.c" | ||
| # for caching purposes. | ||
| basedirs = ["/home/user/project"] | ||
| # Or multiple directories: | ||
| # basedirs = ["/home/user/project", "/home/user/workspace"] | ||
|
|
||
| [dist] | ||
| # where to find the scheduler | ||
| scheduler_url = "http://1.2.3.4:10600" | ||
|
|
@@ -134,6 +147,7 @@ Note that some env variables may need sccache server restart to take effect. | |
|
|
||
| * `SCCACHE_ALLOW_CORE_DUMPS` to enable core dumps by the server | ||
| * `SCCACHE_CONF` configuration file path | ||
| * `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. Path matching is **case-insensitive** on Windows and **case-sensitive** on other operating systems. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will be ignored with a warning. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually when you provide multiple directories or file paths in environment variables (such as
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Linux way is to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, yes. Of course I mixed it up with CMake, which generally uses
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chosen The colon doesn't look like an option to me because of the I am open for suggestions. Maybe, |
||
| * `SCCACHE_CACHED_CONF` | ||
| * `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 | ||
| * `SCCACHE_STARTUP_NOTIFY` specify a path to a socket which will be used for server completion notification | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,6 +381,10 @@ pub trait Storage: Send + Sync { | |
| // Enable by default, only in local mode | ||
| PreprocessorCacheModeConfig::default() | ||
| } | ||
| /// Return the base directories for path normalization if configured | ||
| fn basedirs(&self) -> &[PathBuf] { | ||
| &[] | ||
| } | ||
| /// Return the preprocessor cache entry for a given preprocessor key, | ||
| /// if it exists. | ||
| /// Only applicable when using preprocessor cache mode. | ||
|
|
@@ -736,12 +740,35 @@ pub fn storage_from_config( | |
| let preprocessor_cache_mode_config = config.fallback_cache.preprocessor_cache_mode; | ||
| let rw_mode = config.fallback_cache.rw_mode.into(); | ||
| debug!("Init disk cache with dir {:?}, size {}", dir, size); | ||
|
|
||
| // Validate that all basedirs are absolute paths | ||
| let basedirs: Vec<PathBuf> = config | ||
| .basedirs | ||
| .iter() | ||
| .filter_map(|p| { | ||
| if p.is_absolute() { | ||
| Some(p.clone()) | ||
| } else { | ||
| warn!( | ||
| "Ignoring relative basedir path: {:?}. Only absolute paths are supported.", | ||
| p | ||
| ); | ||
|
Comment on lines
+752
to
+755
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a relative basedir is an invalid configuration, wouldn't it make more sense to error here and get the dev/server admin to fix their config?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By "error," you mean "fail to start"? It could be an option as well, I didn't think of it as a misconfiguration. Looks OK to me to hard fail here. |
||
| None | ||
| } | ||
| }) | ||
| .collect(); | ||
|
|
||
| if !basedirs.is_empty() { | ||
| debug!("Using basedirs for path normalization: {:?}", basedirs); | ||
| } | ||
|
|
||
| Ok(Arc::new(DiskCache::new( | ||
| dir, | ||
| size, | ||
| pool, | ||
| preprocessor_cache_mode_config, | ||
| rw_mode, | ||
| basedirs, | ||
| ))) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit of a rephrasing suggestion:
I'd not say "can be an array of paths" if the "one path" example already is an array. What happens if you do
basedirs = "/home/foo/bar"? (I hope it's not the dreaded Python-like behaviour that it starts chewing away an array of characters one by one…)