Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang-tools-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr};
#[command(styles(CLI_HELP_STYLE))]
pub struct CliOptions {
/// The desired version of clang to install.
///
/// Takes a version requirement (eg. `18` or `=18.1.8`), `latest` for
/// the newest major version of the static binaries, or a path.
#[arg(
short,
long,
Expand Down
33 changes: 32 additions & 1 deletion clang-tools-manager/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ pub enum RequestedVersionParsingError {
NonCanonicalPath(String, std::io::Error),
}

impl RequestedVersion {
/// The value that requests the newest major version
/// in the range of the static binaries (see [`RequestedVersion::latest()`]).
pub const LATEST: &str = "latest";

/// Request the newest major version in the range of the static binaries
/// that this build knows about (any minor or patch release of it).
///
/// The range is read when this crate is built, so it does not change at run time.
pub fn latest() -> Self {
let major = *StaticDistDownloader::get_major_version_range().end();
Self::Requirement(VersionReq::parse(&major.to_string()).unwrap_or(VersionReq::STAR))
}
}

impl FromStr for RequestedVersion {
type Err = RequestedVersionParsingError;

Expand All @@ -277,6 +292,8 @@ impl FromStr for RequestedVersion {
Ok(Self::SystemDefault)
} else if input == "CPP-LINTER-VERSION" {
Ok(Self::NoValue)
} else if input.eq_ignore_ascii_case(Self::LATEST) {
Ok(Self::latest())
} else if let Ok(req) = VersionReq::parse(input) {
Ok(Self::Requirement(req))
} else {
Expand Down Expand Up @@ -312,7 +329,10 @@ mod tests {
use semver::VersionReq;
use tempfile::TempDir;

use super::{RequestedVersion, RequestedVersionParsingError, requires_exact_version};
use super::{
RequestedVersion, RequestedVersionParsingError, StaticDistDownloader,
requires_exact_version,
};
use crate::{ClangTool, utils::normalize_path};

// See also crate::tool::tests module for other `RequestedVersion::from_str()` tests.
Expand Down Expand Up @@ -409,6 +429,17 @@ mod tests {
);
}

#[test]
fn validate_version_latest() {
let major = *StaticDistDownloader::get_major_version_range().end();
let expected =
RequestedVersion::Requirement(VersionReq::parse(&format!("^{major}")).unwrap());
for input in ["latest", "LATEST", "Latest"] {
assert_eq!(RequestedVersion::from_str(input).unwrap(), expected);
}
assert_eq!(RequestedVersion::latest(), expected);
}

#[test]
fn validate_version_exact() {
let req_ver = RequestedVersion::from_str("12").unwrap();
Expand Down
4 changes: 4 additions & 0 deletions cpp-linter/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ pub struct GeneralOptions {
/// `18.1.8` accepts 18.1.8 or a newer 18.x release, and `16` accepts any 16.x release.
/// Use `=18.1.8` to require exactly that version. System package managers
/// are not used for such a version because they only install by major version.
/// - `latest` for the newest major version that cpp-linter can install
/// from its static binaries (any minor or patch release of it).
/// This version is fixed when cpp-linter is built, so it only changes
/// with a cpp-linter update.
/// - A blank string (`''`) to use the platform's default
/// installed version.
/// - A path to where the clang tools are
Expand Down
Loading