summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ryan Mitchell <rtmitchell@google.com> 2019-03-18 08:57:47 -0700
committer Ryan Mitchell <rtmitchell@google.com> 2019-04-17 10:59:38 -0700
commit34039b26f554500450dd566d5710b9b17f155d6f (patch)
treeb9f075ca850bd50852cddc5df5e09e1cde0be0ed
parent488693532998d5e08f68b58b235b7d6dcd3df1fb (diff)
Add build number to aapt2 version
This changes adds the build id to the version printed by "aapt2 version". This change also adds a field to the ResourceTable proto that specifies the fingerprints of tools used to build the table. Bug: 123663089 Test: manual Change-Id: Ifaf33c1e506b68e9f1d921fdbeddf36485e65790
-rw-r--r--tools/aapt2/Android.bp1
-rw-r--r--tools/aapt2/Main.cpp9
-rw-r--r--tools/aapt2/Resources.proto9
-rw-r--r--tools/aapt2/format/proto/ProtoSerialize.cpp3
-rw-r--r--tools/aapt2/util/Util.cpp22
-rw-r--r--tools/aapt2/util/Util.h6
6 files changed, 41 insertions, 9 deletions
diff --git a/tools/aapt2/Android.bp b/tools/aapt2/Android.bp
index aca2be1da33d..326c88d47064 100644
--- a/tools/aapt2/Android.bp
+++ b/tools/aapt2/Android.bp
@@ -57,6 +57,7 @@ cc_defaults {
"libbase",
"libprotobuf-cpp-lite",
"libz",
+ "libbuildversion",
],
stl: "libc++_static",
group_static_libs: true,
diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp
index 39eb9879f86d..213bdd2372ec 100644
--- a/tools/aapt2/Main.cpp
+++ b/tools/aapt2/Main.cpp
@@ -46,12 +46,6 @@ using ::android::base::StringPrintf;
namespace aapt {
-// DO NOT UPDATE, this is more of a marketing version.
-static const char* sMajorVersion = "2";
-
-// Update minor version whenever a feature or flag is added.
-static const char* sMinorVersion = "19";
-
/** Prints the version information of AAPT2. */
class VersionCommand : public Command {
public:
@@ -60,8 +54,7 @@ class VersionCommand : public Command {
}
int Action(const std::vector<std::string>& /* args */) override {
- std::cerr << StringPrintf("Android Asset Packaging Tool (aapt) %s:%s", sMajorVersion,
- sMinorVersion)
+ std::cerr << StringPrintf("%s %s", util::GetToolName(), util::GetToolFingerprint().c_str())
<< std::endl;
return 0;
}
diff --git a/tools/aapt2/Resources.proto b/tools/aapt2/Resources.proto
index a2fd7c664b04..ad068e3e0c46 100644
--- a/tools/aapt2/Resources.proto
+++ b/tools/aapt2/Resources.proto
@@ -41,6 +41,12 @@ message Source {
SourcePosition position = 2;
}
+// The name and version fingerprint of a build tool.
+message ToolFingerprint {
+ string tool = 1;
+ string version = 2;
+}
+
// Top level message representing a resource table.
message ResourceTable {
// The string pool containing source paths referenced throughout the resource table. This does
@@ -52,6 +58,9 @@ message ResourceTable {
// The <overlayable> declarations within the resource table.
repeated Overlayable overlayable = 3;
+
+ // The version fingerprints of the tools that built the resource table.
+ repeated ToolFingerprint tool_fingerprint = 4;
}
// A package ID in the range [0x00, 0xff].
diff --git a/tools/aapt2/format/proto/ProtoSerialize.cpp b/tools/aapt2/format/proto/ProtoSerialize.cpp
index eb2b1a2f35d3..6564e0b05641 100644
--- a/tools/aapt2/format/proto/ProtoSerialize.cpp
+++ b/tools/aapt2/format/proto/ProtoSerialize.cpp
@@ -321,6 +321,9 @@ static void SerializeOverlayableItemToPb(const OverlayableItem& overlayable_item
void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table,
IDiagnostics* diag) {
StringPool source_pool;
+ pb::ToolFingerprint* pb_fingerprint = out_table->add_tool_fingerprint();
+ pb_fingerprint->set_tool(util::GetToolName());
+ pb_fingerprint->set_version(util::GetToolFingerprint());
std::vector<Overlayable*> overlayables;
for (const std::unique_ptr<ResourceTablePackage>& package : table.packages) {
diff --git a/tools/aapt2/util/Util.cpp b/tools/aapt2/util/Util.cpp
index 59b7fff0f9e3..37ce65e4fe5b 100644
--- a/tools/aapt2/util/Util.cpp
+++ b/tools/aapt2/util/Util.cpp
@@ -21,13 +21,15 @@
#include <string>
#include <vector>
+#include "android-base/stringprintf.h"
#include "androidfw/StringPiece.h"
-#include "utils/Unicode.h"
+#include "build/version.h"
#include "text/Unicode.h"
#include "text/Utf8Iterator.h"
#include "util/BigBuffer.h"
#include "util/Maybe.h"
+#include "utils/Unicode.h"
using ::aapt::text::Utf8Iterator;
using ::android::StringPiece;
@@ -200,6 +202,24 @@ Maybe<std::string> GetFullyQualifiedClassName(const StringPiece& package,
return result;
}
+const char* GetToolName() {
+ static const char* const sToolName = "Android Asset Packaging Tool (aapt)";
+ return sToolName;
+}
+
+std::string GetToolFingerprint() {
+ // DO NOT UPDATE, this is more of a marketing version.
+ static const char* const sMajorVersion = "2";
+
+ // Update minor version whenever a feature or flag is added.
+ static const char* const sMinorVersion = "19";
+
+ // The build id of aapt2 binary.
+ static const std::string sBuildId = android::build::GetBuildNumber();
+
+ return android::base::StringPrintf("%s.%s-%s", sMajorVersion, sMinorVersion, sBuildId.c_str());
+}
+
static size_t ConsumeDigits(const char* start, const char* end) {
const char* c = start;
for (; c != end && *c >= '0' && *c <= '9'; c++) {
diff --git a/tools/aapt2/util/Util.h b/tools/aapt2/util/Util.h
index c6e8e6ef7619..a956957eace8 100644
--- a/tools/aapt2/util/Util.h
+++ b/tools/aapt2/util/Util.h
@@ -98,6 +98,12 @@ bool IsAndroidSplitName(const android::StringPiece& str);
Maybe<std::string> GetFullyQualifiedClassName(const android::StringPiece& package,
const android::StringPiece& class_name);
+// Retrieves the formatted name of aapt2.
+const char* GetToolName();
+
+// Retrieves the build fingerprint of aapt2.
+std::string GetToolFingerprint();
+
template <typename T>
typename std::enable_if<std::is_arithmetic<T>::value, int>::type compare(const T& a, const T& b) {
if (a < b) {