diff --git a/tools/external_crates/cargo_embargo.json b/tools/external_crates/cargo_embargo.json index b515b5f64c..32e23506e3 100644 --- a/tools/external_crates/cargo_embargo.json +++ b/tools/external_crates/cargo_embargo.json @@ -14,6 +14,9 @@ "add_toplevel_block": "google_metadata/cargo_embargo_protobuf.bp", "patch": "google_metadata/patches/Android.bp.patch" }, + "license_checker": { + "device_supported": false + }, "name_and_version": { "device_supported": false }, @@ -22,13 +25,14 @@ }, "repo_config": { "device_supported": false + }, + "test_mapping": { + "device_supported": false } }, "tests": true, "workspace": true, "workspace_excludes": [ - "crate_tool", - "license_checker", - "test_mapping" + "crate_tool" ] } diff --git a/tools/external_crates/license_checker/Android.bp b/tools/external_crates/license_checker/Android.bp new file mode 100644 index 0000000000..96a6d494ca --- /dev/null +++ b/tools/external_crates/license_checker/Android.bp @@ -0,0 +1,42 @@ +// This file is generated by cargo_embargo. +// Do not modify this file after the first "rust_*" or "genrule" module +// because the changes will be overridden on upgrade. +// Content before the first "rust_*" or "genrule" module is preserved. + +package { + default_team: "trendy_team_android_rust", + default_applicable_licenses: ["Android-Apache-2.0"], +} + +rust_library_host { + name: "liblicense_checker", + crate_name: "license_checker", + cargo_env_compat: true, + cargo_pkg_version: "0.1.0", + crate_root: "src/lib.rs", + edition: "2021", + rustlibs: [ + "libglob", + "libspdx", + "libthiserror", + ], +} + +rust_test_host { + name: "license_checker_test_src_lib", + crate_name: "license_checker", + cargo_env_compat: true, + cargo_pkg_version: "0.1.0", + crate_root: "src/lib.rs", + test_suites: ["general-tests"], + auto_gen_config: true, + test_options: { + unit_test: true, + }, + edition: "2021", + rustlibs: [ + "libglob", + "libspdx", + "libthiserror", + ], +} diff --git a/tools/external_crates/license_checker/src/lib.rs b/tools/external_crates/license_checker/src/lib.rs index e188e138b4..1e0fb2e974 100644 --- a/tools/external_crates/license_checker/src/lib.rs +++ b/tools/external_crates/license_checker/src/lib.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! A crate for finding license files in crates that satisfy their SPDX license expressions. + use std::{ collections::{BTreeMap, BTreeSet}, fs::read_to_string, @@ -26,6 +28,7 @@ mod expression_parser; mod file_name_checker; mod license_file_finder; +#[allow(missing_docs)] #[derive(Error, Debug)] pub enum LicenseCheckerError { #[error("Couldn't convert filesystem path {} (lossy) to a string for globbing.", .0.to_string_lossy())] @@ -52,12 +55,21 @@ pub enum LicenseCheckerError { Unknown, } +/// The result of license file verification, containing a set of acceptable licenses, and the +/// corresponding license files, if present. #[derive(Debug)] pub struct LicenseState { + /// Unsatisfied licenses. These are licenses that are required by evaluation of SPDX license in + /// Cargo.toml, but for which no matching license file was found. pub unsatisfied: BTreeSet, + /// Licenses for which a license file file was found, and the path to that file. pub satisfied: BTreeMap, } +/// Evaluates the license expression for a crate at a given path and returns a minimal set of +/// acceptable licenses, and whether we could find a matching license file for each one. +/// +/// Returns an error if the licensing for the crate requires us to adopt unacceptable licenses. pub fn find_licenses( crate_path: impl AsRef, crate_name: &str, diff --git a/tools/external_crates/test_mapping/Android.bp b/tools/external_crates/test_mapping/Android.bp new file mode 100644 index 0000000000..2043b0a940 --- /dev/null +++ b/tools/external_crates/test_mapping/Android.bp @@ -0,0 +1,48 @@ +// This file is generated by cargo_embargo. +// Do not modify this file after the first "rust_*" or "genrule" module +// because the changes will be overridden on upgrade. +// Content before the first "rust_*" or "genrule" module is preserved. + +package { + default_team: "trendy_team_android_rust", + default_applicable_licenses: ["Android-Apache-2.0"], +} + +rust_library_host { + name: "libtest_mapping", + crate_name: "test_mapping", + cargo_env_compat: true, + cargo_pkg_version: "0.1.0", + crate_root: "src/lib.rs", + edition: "2021", + rustlibs: [ + "libandroid_bp", + "libjson_strip_comments", + "librooted_path", + "libserde", + "libserde_json", + "libthiserror", + ], +} + +rust_test_host { + name: "test_mapping_test_src_lib", + crate_name: "test_mapping", + cargo_env_compat: true, + cargo_pkg_version: "0.1.0", + crate_root: "src/lib.rs", + test_suites: ["general-tests"], + auto_gen_config: true, + test_options: { + unit_test: true, + }, + edition: "2021", + rustlibs: [ + "libandroid_bp", + "libjson_strip_comments", + "librooted_path", + "libserde", + "libserde_json", + "libthiserror", + ], +} diff --git a/tools/external_crates/test_mapping/src/lib.rs b/tools/external_crates/test_mapping/src/lib.rs index b9a16db56a..4dc19fb159 100644 --- a/tools/external_crates/test_mapping/src/lib.rs +++ b/tools/external_crates/test_mapping/src/lib.rs @@ -33,6 +33,7 @@ use rdeps::ReverseDeps; use rooted_path::RootedPath; use thiserror::Error; +#[allow(missing_docs)] #[derive(Error, Debug)] pub enum TestMappingError { #[error("Blueprint file {0} not found")] @@ -55,10 +56,14 @@ pub enum TestMappingError { GrepParseError(String), } +/// A parsed TEST_MAPPING file #[derive(Debug)] pub struct TestMapping { + /// The path of the crate directory. path: RootedPath, + /// The contents of TEST_MAPPING json: TestMappingJson, + /// The parsed Android.bp file bp: BluePrint, }