Skip to content

Use cfg_aliases to reduce boilerplate - #2644

Merged
sylvestre merged 2 commits into
mozilla:mainfrom
Felixoid:cfg-aliases
Oct 13, 2026
Merged

sylvestre merged 2 commits into
mozilla:mainfrom
Felixoid:cfg-aliases

Conversation

@Felixoid

Copy link
Copy Markdown
Contributor

cfg_aliases allows to define a long any(feature = "",....) only once and then reuse it.

@codecov-commenter

codecov-commenter commented Mar 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.93%. Comparing base (027e5ea) to head (1bb4f3a).

Files with missing lines Patch % Lines
src/config.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2644      +/-   ##
==========================================
- Coverage   78.24%   77.93%   -0.31%     
==========================================
  Files          72       73       +1     
  Lines       42123    43073     +950     
==========================================
+ Hits        32959    33571     +612     
- Misses       9164     9502     +338     

☔ View full report in Codecov by Harness.
📢 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

Copy link
Copy Markdown
Contributor Author

#2581 has 4 more places that would benefit from this patch.

@Felixoid
Felixoid force-pushed the cfg-aliases branch 3 times, most recently from 41782cd to 8275713 Compare April 23, 2026 10:36
@Felixoid

Copy link
Copy Markdown
Contributor Author

The codecov issue is related to codecov/codecov-action#1940

@Felixoid
Felixoid force-pushed the cfg-aliases branch 5 times, most recently from 640ece9 to 671ccc0 Compare April 23, 2026 14:35
@codspeed

codspeed Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing Felixoid:cfg-aliases (1bb4f3a) with main (027e5ea)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread src/config.rs
"oss" => self.oss.clone().map(CacheType::OSS).ok_or_else(|| {
anyhow!("OSS cache not configured but specified in levels")
})?,
"disk" => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This block didn't have cos case.

Having a single point of global features gate and cache type addresses it

@Felixoid

Felixoid commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Hey dear @sylvestre

Do you think it's worth merging? I feel it would improve the codebase by consolidating all feature-related stuff in a dedicated place.

Comment thread src/cache/multilevel.rs Outdated
} else {
return Err(anyhow!(
let level_lower = level_name.to_lowercase();
let (_display_name, cache_type) =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

display_name is only used in one place.
do we need to return a tuple?

Comment thread src/config.rs Outdated
/// Look up a remote cache type by name (e.g. "s3", "gha").
/// Returns `Ok((display_name, Some(..)))` if the name is known and configured,
/// `Ok((display_name, None))` if known but not configured, `Err` if unknown.
pub fn cache_type_by_name(&self, name: &str) -> Result<(&'static str, Option<CacheType>)> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this refactor isn't about cfg_aliases.
Please split it into another PR, thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair, I left only alias-related changes here and will create a new PR with cache_type_by_name refactoring. I'll address your points there.

Comment thread src/config.rs Outdated
#[cfg(feature = "cos")]
"cos" => Ok(("COS", self.cos.clone().map(CacheType::COS))),
_ => bail!(
"Unknown cache level: '{}' (may require a feature flag, e.g. --features {})",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

with unknown_cache this suggests --features unknown_cache, which doesn't exist.
and when the feature is missing, the old "requires the 's3' feature" message was clearer, no?

Comment thread src/config.rs Outdated
}
_ => bail!("Unknown cache level: {}", level_name),
};
if level_name == "disk" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

cos is now accepted in the chain, please add a test for it

Comment thread src/config.rs Outdated
.unwrap_err()
.to_string()
.contains("S3 cache not configured")
err.contains("S3 cache not configured") || err.contains("Unknown cache level"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the || makes this test pass for either error.
could you please split it with #[cfg(feature = "s3")] / #[cfg(not(feature = "s3"))]?

@sylvestre
sylvestre merged commit ff86bbd into mozilla:main Oct 13, 2026
51 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

@Felixoid

Copy link
Copy Markdown
Contributor Author

A follow-up PR #2905

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.

3 participants