Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34039b26 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

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
parent 48869353
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ cc_defaults {
        "libbase",
        "libprotobuf-cpp-lite",
        "libz",
        "libbuildversion",
    ],
    stl: "libc++_static",
    group_static_libs: true,
+1 −8
Original line number Diff line number Diff line
@@ -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;
  }
+9 −0
Original line number Diff line number Diff line
@@ -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].
+3 −0
Original line number Diff line number Diff line
@@ -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) {
+21 −1
Original line number Diff line number Diff line
@@ -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++) {
Loading