From 184b3b36bff963b04f6a41fd8d77881053d95661 Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Mon, 23 Dec 2024 14:13:27 +0100 Subject: [PATCH] soong_package: switch from string to vec of string for licenses (#86) --- src/ninja_target.rs | 4 ++-- src/project/angle.rs | 6 ++--- src/project/clspv.rs | 6 ++--- src/project/clvk.rs | 12 +++++----- src/project/llvm_project.rs | 6 ++--- src/project/mesa.rs | 6 ++--- src/project/spirv_headers.rs | 6 ++--- src/project/spirv_tools.rs | 6 ++--- src/soong_package.rs | 44 ++++++++++++++++++++--------------- tests/llvm-project/Android.bp | 4 ++-- tests/mesa/Android.bp | 4 ++-- 11 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/ninja_target.rs b/src/ninja_target.rs index 3d63489..cff0dd9 100644 --- a/src/ninja_target.rs +++ b/src/ninja_target.rs @@ -34,8 +34,8 @@ pub trait NinjaTarget: std::fmt::Debug { order_only_deps: Vec, variables: HashMap, ) -> Self; - fn get_name(&self, prefix: &Path) -> String { - path_to_id(prefix.join(&self.get_outputs()[0])) + fn get_name(&self, prefix: &str) -> String { + path_to_id(Path::new(prefix).join(&self.get_outputs()[0])) } fn set_globals(&mut self, _globals: HashMap) {} fn set_rule(&mut self, _rules: &NinjaRulesMap) {} diff --git a/src/project/angle.rs b/src/project/angle.rs index 359523e..4a72b77 100644 --- a/src/project/angle.rs +++ b/src/project/angle.rs @@ -76,10 +76,10 @@ impl Project for Angle { &self.src_path, &self.ndk_path, &self.build_path, - Path::new(self.get_name()), "//visibility:public", - "SPDX-license-identifier-Apache-2.0", - "LICENSE", + "angle_license", + vec!["SPDX-license-identifier-Apache-2.0"], + vec!["LICENSE"], ); let targets_to_generate = TARGETS .into_iter() diff --git a/src/project/clspv.rs b/src/project/clspv.rs index b692784..8462116 100644 --- a/src/project/clspv.rs +++ b/src/project/clspv.rs @@ -57,10 +57,10 @@ impl Project for Clspv { &self.src_path, &self.ndk_path, &self.build_path, - Path::new(self.get_name()), "//external/clvk", - "SPDX-license-identifier-Apache-2.0", - "LICENSE", + "clspv_license", + vec!["SPDX-license-identifier-Apache-2.0"], + vec!["LICENSE"], ); package.generate( projects_map.get_deps(ProjectId::Clvk, self.get_id(), GenDeps::TargetsToGen)?, diff --git a/src/project/clvk.rs b/src/project/clvk.rs index 2b246a0..769c6be 100644 --- a/src/project/clvk.rs +++ b/src/project/clvk.rs @@ -8,7 +8,7 @@ pub struct Clvk { src_path: PathBuf, build_path: PathBuf, ndk_path: PathBuf, - generated_libraries: Vec, + gen_libs: Vec, } impl Project for Clvk { @@ -55,14 +55,14 @@ impl Project for Clvk { &self.src_path, &self.ndk_path, &self.build_path, - Path::new(self.get_name()), "//visibility:public", - "SPDX-license-identifier-Apache-2.0", - "LICENSE", + "clvk_license", + vec!["SPDX-license-identifier-Apache-2.0"], + vec!["LICENSE"], ); package.generate(vec![PathBuf::from("libOpenCL.so")], targets, self)?; - self.generated_libraries = Vec::from_iter(package.get_generated_libraries()); + self.gen_libs = Vec::from_iter(package.get_gen_libs()); Ok(package) } @@ -75,7 +75,7 @@ impl Project for Clvk { ProjectId::SpirvTools => "SPIRV-Tools", _ => "", }; - for library in &self.generated_libraries { + for library in &self.gen_libs { if let Ok(lib) = self.get_lib(library).strip_prefix(prefix) { libs.push(PathBuf::from(lib)); } diff --git a/src/project/llvm_project.rs b/src/project/llvm_project.rs index 6d7afa0..80db19d 100644 --- a/src/project/llvm_project.rs +++ b/src/project/llvm_project.rs @@ -66,10 +66,10 @@ impl Project for LlvmProject { &self.src_path, &self.ndk_path, &self.build_path, - Path::new(self.get_name()), "//visibility:public", - "SPDX-license-identifier-Apache-2.0", - "LICENSE.TXT", + "llvm-project_license", + vec!["SPDX-license-identifier-Apache-2.0"], + vec!["LICENSE.TXT"], ); package.generate(targets_to_generate, targets, self)?; diff --git a/src/project/mesa.rs b/src/project/mesa.rs index 652855d..e1ef3ed 100644 --- a/src/project/mesa.rs +++ b/src/project/mesa.rs @@ -84,10 +84,10 @@ impl Project for Mesa { &self.src_path, &self.ndk_path, &self.build_path, - Path::new(self.get_name()), "//visibility:public", - "SPDX-license-identifier-Apache-2.0", - "docs/license.rst", + "mesa_licenses", + vec!["SPDX-license-identifier-Apache-2.0"], + vec!["docs/license.rst"], ); let targets_to_generate = TARGETS.iter().map(|target| PathBuf::from(target)).collect(); package.generate(targets_to_generate, targets, self)?; diff --git a/src/project/spirv_headers.rs b/src/project/spirv_headers.rs index c75f404..b902e95 100644 --- a/src/project/spirv_headers.rs +++ b/src/project/spirv_headers.rs @@ -30,10 +30,10 @@ impl Project for SpirvHeaders { &self.src_path, Path::new(""), Path::new(""), - Path::new(self.get_name()), "//visibility:public", - "SPDX-license-identifier-MIT", - "LICENSE", + "SPIRV-Headers_license", + vec!["SPDX-license-identifier-MIT"], + vec!["LICENSE"], ); package.add_module(SoongModule::new_cc_library_headers( diff --git a/src/project/spirv_tools.rs b/src/project/spirv_tools.rs index 82ace43..06e546d 100644 --- a/src/project/spirv_tools.rs +++ b/src/project/spirv_tools.rs @@ -53,10 +53,10 @@ impl Project for SpirvTools { &self.src_path, &self.ndk_path, &self.build_path, - Path::new(self.get_name()), "//visibility:public", - "SPDX-license-identifier-Apache-2.0", - "LICENSE", + "SPIRV-Tools_license", + vec!["SPDX-license-identifier-Apache-2.0"], + vec!["LICENSE"], ); package.generate( projects_map.get_deps(ProjectId::Clvk, self.get_id(), GenDeps::TargetsToGen)?, diff --git a/src/soong_package.rs b/src/soong_package.rs index 2718e1e..1590e2e 100644 --- a/src/soong_package.rs +++ b/src/soong_package.rs @@ -11,11 +11,10 @@ use crate::utils::*; pub struct SoongPackage<'a> { modules: Vec, gen_deps: HashSet, - generated_libraries: HashSet, + gen_libs: HashSet, src_path: &'a Path, ndk_path: &'a Path, build_path: &'a Path, - target_prefix: &'a Path, } impl<'a> SoongPackage<'a> { @@ -23,22 +22,19 @@ impl<'a> SoongPackage<'a> { src_path: &'a Path, ndk_path: &'a Path, build_path: &'a Path, - target_prefix: &'a Path, default_visibility: &str, - license_kinds: &str, - license_text: &str, + license_module_name: &str, + license_kinds: Vec<&str>, + license_text: Vec<&str>, ) -> Self { let mut package = Self { modules: Vec::new(), gen_deps: HashSet::new(), - generated_libraries: HashSet::new(), + gen_libs: HashSet::new(), src_path, ndk_path, build_path, - target_prefix, }; - let license_name = path_to_id(target_prefix.join(license_text.to_lowercase())); - let mut package_module = SoongModule::new("package"); package_module.add_prop( "default_visibility", @@ -46,23 +42,33 @@ impl<'a> SoongPackage<'a> { ); package_module.add_prop( "default_applicable_licenses", - SoongProp::VecStr(vec![license_name.clone()]), + SoongProp::VecStr(vec![String::from(license_module_name)]), ); package.add_module(package_module); let mut license_module = SoongModule::new("license"); - license_module.add_prop("name", SoongProp::Str(license_name.clone())); + license_module.add_prop("name", SoongProp::Str(String::from(license_module_name))); license_module.add_prop( "visibility", SoongProp::VecStr(vec![String::from(":__subpackages__")]), ); license_module.add_prop( "license_kinds", - SoongProp::VecStr(vec![String::from(license_kinds)]), + SoongProp::VecStr( + license_kinds + .into_iter() + .map(|kind| String::from(kind)) + .collect(), + ), ); license_module.add_prop( "license_text", - SoongProp::VecStr(vec![String::from(license_text)]), + SoongProp::VecStr( + license_text + .into_iter() + .map(|text| String::from(text)) + .collect(), + ), ); package.add_module(license_module); @@ -124,8 +130,8 @@ impl<'a> SoongPackage<'a> { Vec::from_iter(self.gen_deps.to_owned()) } - pub fn get_generated_libraries(&self) -> Vec { - Vec::from_iter(self.generated_libraries.to_owned()) + pub fn get_gen_libs(&self) -> Vec { + Vec::from_iter(self.gen_libs.to_owned()) } fn get_defines(&self, defines: Vec, project: &dyn Project) -> Vec { @@ -158,7 +164,7 @@ impl<'a> SoongPackage<'a> { if lib.starts_with(&self.ndk_path) { file_stem(lib) } else { - self.generated_libraries.insert(lib.clone()); + self.gen_libs.insert(lib.clone()); let lib_id = path_to_id(project.get_lib(&lib)); project.get_target_alias(&lib_id).unwrap_or(lib_id) } @@ -176,7 +182,7 @@ impl<'a> SoongPackage<'a> { where T: NinjaTarget, { - let target_name = target.get_name(self.target_prefix); + let target_name = target.get_name(project.get_name()); let mut cflags = HashSet::new(); let mut includes = HashSet::new(); let mut sources = HashSet::new(); @@ -254,7 +260,7 @@ impl<'a> SoongPackage<'a> { targets_map .get(&header) .unwrap() - .get_name(self.target_prefix) + .get_name(project.get_name()) }) .collect::>(); @@ -446,7 +452,7 @@ impl<'a> SoongPackage<'a> { .collect::>(); let mut module = SoongModule::new("cc_genrule"); - module.add_prop("name", SoongProp::Str(target.get_name(self.target_prefix))); + module.add_prop("name", SoongProp::Str(target.get_name(project.get_name()))); module.add_prop("cmd", SoongProp::Str(cmd)); module.add_prop("srcs", SoongProp::VecStr(Vec::from_iter(sources))); module.add_prop("out", SoongProp::VecStr(Vec::from_iter(outputs))); diff --git a/tests/llvm-project/Android.bp b/tests/llvm-project/Android.bp index e406c7b..23eb45c 100644 --- a/tests/llvm-project/Android.bp +++ b/tests/llvm-project/Android.bp @@ -10,11 +10,11 @@ package { default_visibility: ["//visibility:public"], - default_applicable_licenses: ["llvm-project_license_txt"], + default_applicable_licenses: ["llvm-project_license"], } license { - name: "llvm-project_license_txt", + name: "llvm-project_license", visibility: [":__subpackages__"], license_kinds: ["SPDX-license-identifier-Apache-2.0"], license_text: ["LICENSE.TXT"], diff --git a/tests/mesa/Android.bp b/tests/mesa/Android.bp index 6d42427..412a92b 100644 --- a/tests/mesa/Android.bp +++ b/tests/mesa/Android.bp @@ -10,11 +10,11 @@ package { default_visibility: ["//visibility:public"], - default_applicable_licenses: ["mesa_docs_license_rst"], + default_applicable_licenses: ["mesa_licenses"], } license { - name: "mesa_docs_license_rst", + name: "mesa_licenses", visibility: [":__subpackages__"], license_kinds: ["SPDX-license-identifier-Apache-2.0"], license_text: ["docs/license.rst"],