Add post_update.sh am: 0e4ce3895a am: b6bfe838c5
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/protobuf-codegen/+/1443104
Change-Id: I9ae9e4f389437e8d848061e4ae8e9a16071d6b71
diff --git a/post_update.sh b/post_update.sh
new file mode 100755
index 0000000..39f2fdd
--- /dev/null
+++ b/post_update.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# $1 Path to the new version.
+# $2 Path to the old version.
+
+set -x
+set -e
+
+# replace CARGO_PKG_VERSION with version string from METADATA
+SRCFILE=src/lib.rs
+VERSION=`grep version: METADATA | sed -e 's/^.*version: *//'`
+OLDSTR='env!("CARGO_PKG_VERSION"));'
+NEWSTR="$VERSION); // ANDROID ported version"
+sed -i -e "s:$OLDSTR:$NEWSTR:" $SRCFILE
+# Make sure that sed replaced $OLDSTR with $NEWSTR
+grep "$NEWSTR" $SRCFILE > /dev/null
diff --git a/src/lib.rs b/src/lib.rs
index 4fc3ee9..cff1da2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -186,9 +186,7 @@
{
let mut w = CodeWriter::new(&mut v);
- // ANDROID: hard code version number here because Android.bp
- // rust modules cannot pass it though env variable yet.
- w.write_generated_by("rust-protobuf", "2.17.0");
+ w.write_generated_by("rust-protobuf", "2.17.0"); // ANDROID ported version
w.write_line(&format!("//! Generated file from `{}`", file.get_name()));
if customize.inside_protobuf != Some(true) {
w.write_line("");