Repository navigation
server: scope SCCACHE_BASEDIRS to compiler requests #2814
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| // Copyright 2026 Mozilla Foundation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
|
|
||
| use async_trait::async_trait; | ||
| use bytes::Bytes; | ||
|
|
||
| use crate::cache::multilevel::MultiLevelStats; | ||
| use crate::cache::{Cache, CacheMode, CacheWrite, GetPathResult, Storage}; | ||
| use crate::compiler::PreprocessorCacheEntry; | ||
| use crate::config::PreprocessorCacheModeConfig; | ||
| use crate::errors::*; | ||
|
|
||
| struct BasedirsStorage { | ||
| inner: Arc<dyn Storage>, | ||
| basedirs: Vec<Vec<u8>>, | ||
| } | ||
|
|
||
| pub(crate) fn with_basedirs(storage: Arc<dyn Storage>, basedirs: Vec<Vec<u8>>) -> Arc<dyn Storage> { | ||
| if storage.basedirs() == basedirs { | ||
| storage | ||
| } else { | ||
| Arc::new(BasedirsStorage { | ||
| inner: storage, | ||
| basedirs, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl Storage for BasedirsStorage { | ||
| async fn get(&self, key: &str) -> Result<Cache> { | ||
| self.inner.get(key).await | ||
| } | ||
|
|
||
| async fn get_with_raw(&self, key: &str) -> Result<(Cache, Option<Bytes>)> { | ||
| self.inner.get_with_raw(key).await | ||
| } | ||
|
|
||
| async fn put(&self, key: &str, entry: CacheWrite) -> Result<Duration> { | ||
| self.inner.put(key, entry).await | ||
| } | ||
|
|
||
| async fn get_raw(&self, key: &str) -> Result<Option<Bytes>> { | ||
| self.inner.get_raw(key).await | ||
| } | ||
|
|
||
| async fn put_raw(&self, key: &str, data: Bytes) -> Result<Duration> { | ||
| self.inner.put_raw(key, data).await | ||
| } | ||
|
|
||
| async fn check(&self) -> Result<CacheMode> { | ||
| self.inner.check().await | ||
| } | ||
|
|
||
| fn location(&self) -> String { | ||
| self.inner.location() | ||
| } | ||
|
|
||
| fn cache_type_name(&self) -> &'static str { | ||
| self.inner.cache_type_name() | ||
| } | ||
|
|
||
| async fn current_size(&self) -> Result<Option<u64>> { | ||
| self.inner.current_size().await | ||
| } | ||
|
|
||
| async fn max_size(&self) -> Result<Option<u64>> { | ||
| self.inner.max_size().await | ||
| } | ||
|
|
||
| fn multilevel_stats(&self) -> Option<MultiLevelStats> { | ||
| self.inner.multilevel_stats() | ||
| } | ||
|
|
||
| fn preprocessor_cache_mode_config(&self) -> PreprocessorCacheModeConfig { | ||
| self.inner.preprocessor_cache_mode_config() | ||
| } | ||
|
|
||
| fn basedirs(&self) -> &[Vec<u8>] { | ||
| &self.basedirs | ||
| } | ||
|
|
||
| async fn get_path(&self, key: &str) -> GetPathResult { | ||
| self.inner.get_path(key).await | ||
| } | ||
|
|
||
| async fn get_preprocessor_cache_entry( | ||
| &self, | ||
| key: &str, | ||
| ) -> Result<Option<Box<dyn crate::lru_disk_cache::ReadSeek>>> { | ||
| self.inner.get_preprocessor_cache_entry(key).await | ||
| } | ||
|
|
||
| async fn put_preprocessor_cache_entry( | ||
| &self, | ||
| key: &str, | ||
| entry: PreprocessorCacheEntry, | ||
| ) -> Result<()> { | ||
| self.inner.put_preprocessor_cache_entry(key, entry).await | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
| use super::*; | ||
| use crate::cache::disk::DiskCache; | ||
| use crate::cache::readonly::ReadOnlyStorage; | ||
|
|
||
| #[tokio::test] | ||
| async fn request_view_preserves_storage_capabilities() -> Result<()> { | ||
| let tempdir = tempfile::tempdir()?; | ||
|
|
||
| let fallback = vec![b"/configured/".to_vec()]; | ||
| let storage: Arc<dyn Storage> = Arc::new(DiskCache::new( | ||
| tempdir.path(), | ||
| 1024 * 1024, | ||
| &tokio::runtime::Handle::current(), | ||
| PreprocessorCacheModeConfig::default(), | ||
| CacheMode::ReadWrite, | ||
| fallback.clone(), | ||
| )); | ||
|
|
||
| let unchanged = with_basedirs(Arc::clone(&storage), fallback.clone()); | ||
| assert!(Arc::ptr_eq(&unchanged, &storage)); | ||
|
|
||
| let request_basedirs = vec![b"/request/".to_vec()]; | ||
| let view = with_basedirs(Arc::clone(&storage), request_basedirs.clone()); | ||
| let empty_view = with_basedirs(Arc::clone(&storage), vec![]); | ||
| assert!(!Arc::ptr_eq(&view, &storage)); | ||
| assert_eq!(view.basedirs(), request_basedirs); | ||
| assert!(empty_view.basedirs().is_empty()); | ||
| assert_eq!(storage.basedirs(), fallback); | ||
| assert_eq!(view.location(), storage.location()); | ||
| assert_eq!(view.cache_type_name(), storage.cache_type_name()); | ||
|
|
||
| let key = "0123456789abcdef"; | ||
| let raw: Bytes = CacheWrite::default().finish()?.into(); | ||
|
|
||
| view.put_raw(key, raw.clone()).await?; | ||
| assert_eq!(view.get_raw(key).await?.as_deref(), Some(raw.as_ref())); | ||
| let (cache, combined_raw) = view.get_with_raw(key).await?; | ||
| assert!(matches!(cache, Cache::Hit(_))); | ||
| assert_eq!(combined_raw.as_deref(), Some(raw.as_ref())); | ||
| assert!(matches!(view.get_path(key).await, GetPathResult::Found(_))); | ||
|
|
||
| let entry_key = "fedcba9876543210"; | ||
| view.put(entry_key, CacheWrite::default()).await?; | ||
| assert!(matches!(view.get(entry_key).await?, Cache::Hit(_))); | ||
|
|
||
| let preprocessor_key = "preprocessor"; | ||
| view.put_preprocessor_cache_entry(preprocessor_key, PreprocessorCacheEntry::default()) | ||
| .await?; | ||
| assert!( | ||
| view.get_preprocessor_cache_entry(preprocessor_key) | ||
| .await? | ||
| .is_some() | ||
| ); | ||
| assert_eq!( | ||
| view.preprocessor_cache_mode_config(), | ||
| storage.preprocessor_cache_mode_config() | ||
| ); | ||
| assert_eq!(view.current_size().await?, storage.current_size().await?); | ||
| assert_eq!(view.max_size().await?, storage.max_size().await?); | ||
|
|
||
| let read_only: Arc<dyn Storage> = Arc::new(ReadOnlyStorage(Arc::clone(&storage))); | ||
| let read_only_view = with_basedirs(read_only, vec![b"/read-only-request/".to_vec()]); | ||
| assert_eq!(read_only_view.check().await?, CacheMode::ReadOnly); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -719,7 +719,15 @@ where | |
| pub fn run_command(cmd: Command) -> Result<i32> { | ||
| // Config isn't required for all commands, but if it's broken then we should flag | ||
| // it early and loudly. | ||
| let config = &Config::load()?; | ||
| let config = if matches!( | ||
| &cmd, | ||
| Command::StartServer | Command::InternalStartServer | Command::ShowStats(_, _) | ||
| ) { | ||
| Config::load_with_file_basedirs()? | ||
|
Collaborator
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. hardcoding the command list here is fragile. if the daemon only uses the file value and client-side gets it from the handshake, is the env branch in config_from_env still used at all? |
||
| } else { | ||
| Config::load()? | ||
| }; | ||
| let config = &config; | ||
| let startup_timeout = config.server_startup_timeout; | ||
|
|
||
| match cmd { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
150 lines of forwarding just to carry a Vec<Vec>, and the day someone adds a method to Storage it will silently bypass this wrapper. could we pass the basedirs next to the storage into generate_hash_key instead?