From ec9706738f35a859f66fd0758b73381055804f63 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 3 May 2017 11:00:48 -0700 Subject: Remove EXPAND/STRINGIFY macros. They are error-prone by putting anything into a string (e.g. EXPAND(RECOVERY_API_VERSION) would become "RECOVER_API_VERSION" if we forgot to pass -DRECOVERY_API_VERSION=3). RECOVERY_API_VERSION is the only user (in bootable/recovery) that gets stringified. Assign it to a typed var and sanity check the value. Don't see other reference to the macros from device-specific recovery directories (they can still define that locally if really needed). Test: recovery_component_test Test: Sideload an OTA on angler and marlin respectively. Change-Id: I358bbdf8f0a99db5ce4c7bc2fdcafe8013501b64 --- common.h | 4 ++-- install.cpp | 2 +- recovery.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common.h b/common.h index 62fb1324b..87b84772d 100644 --- a/common.h +++ b/common.h @@ -22,8 +22,8 @@ #include -#define STRINGIFY(x) #x -#define EXPAND(x) STRINGIFY(x) +static constexpr int kRecoveryApiVersion = RECOVERY_API_VERSION; // Defined in Android.mk. +static_assert(kRecoveryApiVersion >= 3, "Invalid recovery API version."); class RecoveryUI; diff --git a/install.cpp b/install.cpp index 689f4a0c6..2cc06603b 100644 --- a/install.cpp +++ b/install.cpp @@ -287,7 +287,7 @@ int update_binary_command(const std::string& path, ZipArchiveHandle zip, int ret *cmd = { binary, - EXPAND(RECOVERY_API_VERSION), // defined in Android.mk + std::to_string(kRecoveryApiVersion), std::to_string(status_fd), path, }; diff --git a/recovery.cpp b/recovery.cpp index 944c24086..6dd985831 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1501,7 +1501,7 @@ int main(int argc, char **argv) { property_list(print_property, NULL); printf("\n"); - ui->Print("Supported API: %d\n", RECOVERY_API_VERSION); + ui->Print("Supported API: %d\n", kRecoveryApiVersion); int status = INSTALL_SUCCESS; -- cgit v1.2.3