Add support for product_available and vendor_available flags.

Bug: 293289578
Test: Ran on external/rust/crates/either
Change-Id: Iaf357dc2a9e036689c07005f2f9ca3879e3e71ee
diff --git a/tools/cargo_embargo/src/cargo_out.rs b/tools/cargo_embargo/src/cargo_out.rs
index fcf467f..a47f1f7 100644
--- a/tools/cargo_embargo/src/cargo_out.rs
+++ b/tools/cargo_embargo/src/cargo_out.rs
@@ -23,7 +23,7 @@
 use std::path::PathBuf;
 
 /// Combined representation of --crate-type and --test flags.
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
 pub enum CrateType {
     // --crate-type types
     Bin,
@@ -39,6 +39,13 @@
     TestNoHarness,
 }
 
+impl CrateType {
+    /// Returns whether the crate type is a kind of library.
+    pub fn is_library(self) -> bool {
+        matches!(self, Self::Lib | Self::RLib | Self::DyLib | Self::CDyLib | Self::StaticLib)
+    }
+}
+
 /// Info extracted from `CargoOut` for a crate.
 ///
 /// Note that there is a 1-to-many relationship between a Cargo.toml file and these `Crate`
diff --git a/tools/cargo_embargo/src/main.rs b/tools/cargo_embargo/src/main.rs
index 83ee896..67ebd59 100644
--- a/tools/cargo_embargo/src/main.rs
+++ b/tools/cargo_embargo/src/main.rs
@@ -70,6 +70,10 @@
     vec!["//apex_available:platform".to_string(), "//apex_available:anyapex".to_string()]
 }
 
+fn default_true() -> bool {
+    true
+}
+
 /// Options that apply to everything.
 #[derive(serde::Deserialize)]
 #[serde(deny_unknown_fields)]
@@ -90,6 +94,12 @@
     /// Value to use for every generated library module's "apex_available" field.
     #[serde(default = "default_apex_available")]
     apex_available: Vec<String>,
+    /// Value to use for every generated library module's `product_available` field.
+    #[serde(default = "default_true")]
+    product_available: bool,
+    /// Value to use for every generated library module's `vendor_available` field.
+    #[serde(default = "default_true")]
+    vendor_available: bool,
     /// Map of renames for modules. For example, if a "libfoo" would be generated and there is an
     /// entry ("libfoo", "libbar"), the generated module will be called "libbar" instead.
     ///
@@ -583,17 +593,16 @@
             m.props.set("shared_libs", process_lib_deps(crate_.shared_libs.clone()));
         }
 
-        if !cfg.apex_available.is_empty()
-            && [
-                CrateType::Lib,
-                CrateType::RLib,
-                CrateType::DyLib,
-                CrateType::CDyLib,
-                CrateType::StaticLib,
-            ]
-            .contains(crate_type)
-        {
-            m.props.set("apex_available", cfg.apex_available.clone());
+        if crate_type.is_library() {
+            if !cfg.apex_available.is_empty() {
+                m.props.set("apex_available", cfg.apex_available.clone());
+            }
+            if cfg.product_available {
+                m.props.set("product_available", true);
+            }
+            if cfg.vendor_available {
+                m.props.set("vendor_available", true);
+            }
         }
 
         if let Some(visibility) = cfg.module_visibility.get(module_name) {