Snap for 11869550 from 11bf8db5eba0adf6eeee821c2e442ca84f41b18e to 24Q3-release
Change-Id: I493ee880849440b6cbb428e83c6745f5d6f0d608
diff --git a/patches/mod_path.patch b/patches/mod_path.patch
new file mode 100644
index 0000000..39eb133
--- /dev/null
+++ b/patches/mod_path.patch
@@ -0,0 +1,28 @@
+diff --git a/src/util.rs b/src/util.rs
+index 3019c40..49a9651 100644
+--- a/src/util.rs
++++ b/src/util.rs
+@@ -18,7 +18,13 @@ pub fn manifest_path() -> Result<PathBuf, String> {
+ Ok(StdPath::new(&manifest_dir).join("Cargo.toml"))
+ }
+
+-#[cfg(not(feature = "nightly"))]
++#[cfg(soong)]
++pub fn mod_path() -> syn::Result<String> {
++ Ok(std::env::var("CARGO_CRATE_NAME")
++ .expect("`CARGO_CRATE_NAME` should be set when building with Soong"))
++}
++
++#[cfg(all(not(soong), not(feature = "nightly")))]
+ pub fn mod_path() -> syn::Result<String> {
+ // Without the nightly feature and TokenStream::expand_expr, just return the crate name
+
+@@ -64,7 +70,7 @@ pub fn mod_path() -> syn::Result<String> {
+ .map_err(|e| syn::Error::new(Span::call_site(), e))
+ }
+
+-#[cfg(feature = "nightly")]
++#[cfg(all(not(soong), feature = "nightly"))]
+ pub fn mod_path() -> syn::Result<String> {
+ use proc_macro::TokenStream;
+
diff --git a/src/util.rs b/src/util.rs
index 3019c40..49a9651 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -18,7 +18,13 @@
Ok(StdPath::new(&manifest_dir).join("Cargo.toml"))
}
-#[cfg(not(feature = "nightly"))]
+#[cfg(soong)]
+pub fn mod_path() -> syn::Result<String> {
+ Ok(std::env::var("CARGO_CRATE_NAME")
+ .expect("`CARGO_CRATE_NAME` should be set when building with Soong"))
+}
+
+#[cfg(all(not(soong), not(feature = "nightly")))]
pub fn mod_path() -> syn::Result<String> {
// Without the nightly feature and TokenStream::expand_expr, just return the crate name
@@ -64,7 +70,7 @@
.map_err(|e| syn::Error::new(Span::call_site(), e))
}
-#[cfg(feature = "nightly")]
+#[cfg(all(not(soong), feature = "nightly"))]
pub fn mod_path() -> syn::Result<String> {
use proc_macro::TokenStream;