Skip to content

Conversation

@Felixoid
Copy link
Contributor

@Felixoid Felixoid commented Dec 18, 2025

This is an attempt to fix #35.

The ENV variable SCCACHE_BASEDIRS and configuration parameter basedirs are added.

As well as new tests to validate the behavior.

@codecov-commenter
Copy link

codecov-commenter commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 97.50865% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.31%. Comparing base (951e247) to head (31f9f6b).

Files with missing lines Patch % Lines
src/cache/cache.rs 76.00% 18 Missing ⚠️
src/util.rs 96.13% 10 Missing ⚠️
src/compiler/preprocessor_cache.rs 97.47% 3 Missing ⚠️
src/server.rs 78.57% 3 Missing ⚠️
tests/oauth.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2521      +/-   ##
==========================================
+ Coverage   71.17%   72.31%   +1.13%     
==========================================
  Files          64       64              
  Lines       35592    36995    +1403     
==========================================
+ Hits        25334    26752    +1418     
+ Misses      10258    10243      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Felixoid Felixoid force-pushed the add-basedir-configuration branch from bfba6ec to 9eb3241 Compare December 18, 2025 23:45
@Felixoid Felixoid force-pushed the add-basedir-configuration branch from e818064 to d2e6edd Compare December 22, 2025 10:47
@Felixoid
Copy link
Contributor Author

I got an idea, that basedirs should be added to the stats command as well

@Felixoid Felixoid force-pushed the add-basedir-configuration branch from ca0a0db to 6f47f36 Compare December 23, 2025 13:57
@Felixoid Felixoid changed the title Add SCCACHE_BASEDIR support Add SCCACHE_BASEDIRS support Dec 23, 2025
@Felixoid Felixoid force-pushed the add-basedir-configuration branch from b5a7d22 to cf0b871 Compare December 23, 2025 23:03
@AJIOB
Copy link
Contributor

AJIOB commented Dec 24, 2025

I got an idea, that basedirs should be added to the stats command as well

I think we can also provide the stat about base dir usage translation:

  • Number of base dir applied requests
  • Number of base dir skipped requests

In this case we can see, do we need to provide more/better base dirs or not

@Felixoid
Copy link
Contributor Author

  • Number of base dir applied requests
  • Number of base dir skipped requests

It's a tricky one. After taking a look, the number of successful substitutions is relatively easy to implement, although the counter should be threaded to the ServerStats.

But how to count the number of skipped directories? What is it? If a base_directory didn't match any of the output at all?

@AJIOB
Copy link
Contributor

AJIOB commented Dec 24, 2025

  • Number of base dir applied requests
  • Number of base dir skipped requests

It's a tricky one. After taking a look, the number of successful substitutions is relatively easy to implement, although the counter should be threaded to the ServerStats.

But how to count the number of skipped directories? What is it? If a base_directory didn't match any of the output at all?

No, just to check what number of cache requests has been converted using any of base dirs and what number was kept as an absolute one

@AJIOB
Copy link
Contributor

AJIOB commented Dec 24, 2025

About paths: we can try to normalize paths via https://docs.rs/normpath/latest/normpath/ or something similar instead of doing one more implementation.

@Felixoid
Copy link
Contributor Author

About paths: we can try to normalize paths via https://docs.rs/normpath/latest/normpath/ or something similar instead of doing one more implementation.

It looks like https://doc.rust-lang.org/stable/std/path/fn.absolute.html is what I should use for both cases. It normalizes slashes, but keeps the cases as is.

Although see my comment regarding the preprocessor_output. normalize_path is used not only to needles from basedirs, but to a haystack as well. Both https://doc.rust-lang.org/stable/std/path/fn.absolute.html and https://docs.rs/normpath/latest/normpath/trait.PathExt.html#tymethod.normalize_virtually work on Path-like objects. They don't fit the purpose of the plaintext normalization, as far as I can tell.

@Felixoid Felixoid force-pushed the add-basedir-configuration branch 2 times, most recently from a97218c to bccc8f4 Compare December 29, 2025 23:13
@Felixoid
Copy link
Contributor Author

No, just to check what number of cache requests has been converted using any of base dirs and what number was kept as an absolute one

I am afraid it causes changes in too many places, including the signatures of hash_key and other significant components. I want to cut this task from the PR, if you don't mind; it's already quite huge.

@Felixoid Felixoid force-pushed the add-basedir-configuration branch 2 times, most recently from 0887cea to e42a1f6 Compare December 30, 2025 12:12
src/util.rs Outdated
for basedir_path in basedirs.iter() {
let basedir_str = basedir_path.to_string_lossy();
let basedir = basedir_str
.trim_end_matches(|c| c == '/' || c == '\\')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\ should not be trimmed on non-Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2521 (comment)

so, stripping \|/ on windows, / on other OSes, and then adding the trailing /

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use https://docs.rs/typed-path/latest/typed_path/ here.

Then, the trailing / will be added explicitly and completely stripped from the preprocessor_output instead of being replaced by ..

The last question is whether ./ should be treated as a special case. Because ./test.c and test.c won't match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 87151ba, I implemented this logic. The basedir is stripped completely to match /dir/test.c and test.c in the cache.

The ./test.c is still not covered by the code.

@Felixoid Felixoid force-pushed the add-basedir-configuration branch 2 times, most recently from 6529696 to fae67f8 Compare December 30, 2025 21:50
Felixoid and others added 27 commits January 11, 2026 21:08
@Felixoid Felixoid force-pushed the add-basedir-configuration branch from 1d0156e to 31f9f6b Compare January 11, 2026 20:08
@Felixoid
Copy link
Contributor Author

Felixoid commented Jan 11, 2026

Rebased it on top of the current master

Copy link
Contributor

@mathstuf mathstuf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just one nit and a possible followup.

Thanks!

/// If `basedirs` are provided, paths in the preprocessor output will be normalized by
/// stripping the longest matching basedir prefix. This enables cache hits across different
/// absolute paths (similar to ccache's CCACHE_BASEDIR).
#[allow(clippy::too_many_arguments)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something for a new PR, but a Builder pattern to deal with these arguments looks like a nice enhancement. The (test) call sites being a zoo of &[] and unlabeled bool literals isn't that nice IMO.

* Multiple developers working with different username paths
* Working with multiple project checkouts simultaneously

**Note:** Only absolute paths are supported. Relative paths will prevent server from start.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Note:** Only absolute paths are supported. Relative paths will prevent server from start.
**Note:** Only absolute paths are supported. Relative paths will prevent server from starting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement an equivalent to CCACHE_BASEDIR

6 participants