Add post_update.sh
* replace CARGO_PKG_VERSION with version string from METADATA
Test: tools/external_updater/updater.sh update --refresh --keep_date rust/crates/protobuf-codegen
Change-Id: Ic2d5728a327d001b626d33907403c2ced61925ce
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("");