diff options
author | 花蛄 <15226118+TiceCosmos@users.noreply.github.com> | 2020-12-19 21:17:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 14:17:34 +0100 |
commit | 4f51ef8db1cbdeda7a70eb7df2cbd55bd7d538b3 (patch) | |
tree | 6346908a9c70840375d4cec865e910a305d50549 /src | |
parent | f17556d3898363655feb8735bb21de9fa4f28528 (diff) |
feat(package): Meson package support (#2001)
* Add package version support for Meson meson.build.
* Update docs with Meson package version support.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/package.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/modules/package.rs b/src/modules/package.rs index 9b3dad294..0df57c652 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -162,6 +162,16 @@ fn extract_maven_version(file_contents: &str) -> Option<String> { None } +fn extract_meson_version(file_contents: &str) -> Option<String> { + let file_contents = file_contents.split_ascii_whitespace().collect::<String>(); + + let re = Regex::new(r#"project\([^())]*version:'(?P<version>[^']+)'[^())]*\)"#).unwrap(); + let caps = re.captures(&file_contents)?; + + let formatted_version = format_version(&caps["version"]); + Some(formatted_version) +} + fn get_package_version(base_dir: &PathBuf, config: &PackageConfig) -> Option<String> { if let Ok(cargo_toml) = utils::read_file(base_dir.join("Cargo.toml")) { extract_cargo_version(&cargo_toml) @@ -181,6 +191,8 @@ fn get_package_version(base_dir: &PathBuf, config: &PackageConfig) -> Option<Str extract_helm_package_version(&chart_file) } else if let Ok(pom_file) = utils::read_file(base_dir.join("pom.xml")) { extract_maven_version(&pom_file) + } else if let Ok(meson_build) = utils::read_file(base_dir.join("meson.build")) { + extract_meson_version(&meson_build) } else { None } @@ -722,6 +734,28 @@ end"; project_dir.close() } + #[test] + fn test_extract_meson_version() -> io::Result<()> { + let config_name = "meson.build"; + let config_content = "project('starship', 'rust', version: '0.1.0')".to_string(); + + let project_dir = create_project_dir()?; + fill_config(&project_dir, config_name, Some(&config_content))?; + expect_output(&project_dir, Some("v0.1.0"), None)?; + project_dir.close() + } + + #[test] + fn test_extract_meson_version_without_version() -> io::Result<()> { + let config_name = "meson.build"; + let config_content = "project('starship', 'rust')".to_string(); + + let project_dir = create_project_dir()?; + fill_config(&project_dir, config_name, Some(&config_content))?; + expect_output(&project_dir, None, None)?; + project_dir.close() + } + fn create_project_dir() -> io::Result<TempDir> { Ok(tempfile::tempdir()?) } |