Skip to content

Commit

Permalink
soong_package: switch from string to vec of string for licenses (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjodinchr authored Dec 23, 2024
1 parent 0e9feba commit 184b3b3
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/ninja_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub trait NinjaTarget: std::fmt::Debug {
order_only_deps: Vec<PathBuf>,
variables: HashMap<String, String>,
) -> 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<String, String>) {}
fn set_rule(&mut self, _rules: &NinjaRulesMap) {}
Expand Down
6 changes: 3 additions & 3 deletions src/project/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/project/clspv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Expand Down
12 changes: 6 additions & 6 deletions src/project/clvk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Clvk {
src_path: PathBuf,
build_path: PathBuf,
ndk_path: PathBuf,
generated_libraries: Vec<PathBuf>,
gen_libs: Vec<PathBuf>,
}

impl Project for Clvk {
Expand Down Expand Up @@ -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)
}

Expand All @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions src/project/llvm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
6 changes: 3 additions & 3 deletions src/project/mesa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
6 changes: 3 additions & 3 deletions src/project/spirv_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/project/spirv_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Expand Down
44 changes: 25 additions & 19 deletions src/soong_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,64 @@ use crate::utils::*;
pub struct SoongPackage<'a> {
modules: Vec<SoongModule>,
gen_deps: HashSet<PathBuf>,
generated_libraries: HashSet<PathBuf>,
gen_libs: HashSet<PathBuf>,
src_path: &'a Path,
ndk_path: &'a Path,
build_path: &'a Path,
target_prefix: &'a Path,
}

impl<'a> SoongPackage<'a> {
pub fn new(
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",
SoongProp::VecStr(vec![String::from(default_visibility)]),
);
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);

Expand Down Expand Up @@ -124,8 +130,8 @@ impl<'a> SoongPackage<'a> {
Vec::from_iter(self.gen_deps.to_owned())
}

pub fn get_generated_libraries(&self) -> Vec<PathBuf> {
Vec::from_iter(self.generated_libraries.to_owned())
pub fn get_gen_libs(&self) -> Vec<PathBuf> {
Vec::from_iter(self.gen_libs.to_owned())
}

fn get_defines(&self, defines: Vec<String>, project: &dyn Project) -> Vec<String> {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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();
Expand Down Expand Up @@ -254,7 +260,7 @@ impl<'a> SoongPackage<'a> {
targets_map
.get(&header)
.unwrap()
.get_name(self.target_prefix)
.get_name(project.get_name())
})
.collect::<HashSet<String>>();

Expand Down Expand Up @@ -446,7 +452,7 @@ impl<'a> SoongPackage<'a> {
.collect::<HashSet<String>>();

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)));
Expand Down
4 changes: 2 additions & 2 deletions tests/llvm-project/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 2 additions & 2 deletions tests/mesa/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 184b3b3

Please sign in to comment.