Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Build license_checker and test_mapping with Soong.
Browse files Browse the repository at this point in the history
Test: treehugger
Change-Id: I8104588878f5fbe063085c26bd92ae832e6639e9
  • Loading branch information
jfgoog committed Jan 29, 2025
1 parent 5d9a297 commit 9794c55
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/external_crates/cargo_embargo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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"
]
}
42 changes: 42 additions & 0 deletions tools/external_crates/license_checker/Android.bp
Original file line number Diff line number Diff line change
@@ -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",
],
}
12 changes: 12 additions & 0 deletions tools/external_crates/license_checker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())]
Expand All @@ -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<LicenseReq>,
/// Licenses for which a license file file was found, and the path to that file.
pub satisfied: BTreeMap<LicenseReq, PathBuf>,
}

/// 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<Path>,
crate_name: &str,
Expand Down
48 changes: 48 additions & 0 deletions tools/external_crates/test_mapping/Android.bp
Original file line number Diff line number Diff line change
@@ -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",
],
}
5 changes: 5 additions & 0 deletions tools/external_crates/test_mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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,
}

Expand Down

0 comments on commit 9794c55

Please sign in to comment.