Replace uses of _format with a macro.
_format is a user-defined literal which is removed from newer
releases of libfmt.
Bug: 271622675
Test: local build, presubmit
Change-Id: I60b2d6d157cb1ad1c16b4a4f681fad7be41cecb4
Merged-In: I2f5cc706ca8f734b1cad89e7d957fb7a52f78a10
diff --git a/libartbase/base/macros.h b/libartbase/base/macros.h
index 13e87d7..5f2100f 100644
--- a/libartbase/base/macros.h
+++ b/libartbase/base/macros.h
@@ -20,6 +20,7 @@
#include <stddef.h> // for size_t
#include <unistd.h> // for TEMP_FAILURE_RETRY
+#include "android-base/format.h"
#include "android-base/macros.h"
#include "android-base/thread_annotations.h"
@@ -32,6 +33,9 @@
#define ART_FRIEND_TYPED_TEST(test_set_name, individual_test)\
template<typename T> ART_FRIEND_TEST(test_set_name, individual_test)
+// Shorthand for formatting with compile time checking of the format string
+#define ART_FORMAT(str, ...) ::fmt::format(FMT_STRING(str), __VA_ARGS__)
+
// A macro to disallow new and delete operators for a class. It goes in the private: declarations.
// NOTE: Providing placement new (and matching delete) for constructing container elements.
#define DISALLOW_ALLOCATION() \
diff --git a/odrefresh/odr_common.cc b/odrefresh/odr_common.cc
index ec18884..d76aff2 100644
--- a/odrefresh/odr_common.cc
+++ b/odrefresh/odr_common.cc
@@ -28,19 +28,16 @@
#include "android-base/logging.h"
#include "android-base/parseint.h"
#include "android-base/result.h"
-#include "fmt/format.h"
+#include "base/macros.h"
namespace art {
namespace odrefresh {
namespace {
-
using ::android::base::Result;
-
-using ::fmt::literals::operator""_format; // NOLINT
}
-std::string QuotePath(std::string_view path) { return "'{}'"_format(path); }
+std::string QuotePath(std::string_view path) { return ART_FORMAT("'{}'", path); }
Result<int> ParseSecurityPatchStr(const std::string& security_patch_str) {
std::regex security_patch_regex(R"re((\d{4})-(\d{2})-(\d{2}))re");
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 85766cc..a0b1a1c 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -81,7 +81,6 @@
#include "dex/art_dex_file_loader.h"
#include "dexoptanalyzer.h"
#include "exec_utils.h"
-#include "fmt/format.h"
#include "gc/collector/mark_compact.h"
#include "log/log.h"
#include "odr_artifacts.h"
@@ -118,8 +117,6 @@
using ::android::base::Timer;
using ::android::modules::sdklevel::IsAtLeastU;
-using ::fmt::literals::operator""_format; // NOLINT
-
// Name of cache info file in the ART Apex artifact cache.
constexpr const char* kCacheInfoFile = "cache-info.xml";
@@ -158,7 +155,7 @@
std::vector<std::unique_ptr<File>> output_files;
for (auto& file : files) {
std::string file_basename(Basename(file->GetPath()));
- std::string output_file_path = "{}/{}"_format(output_directory_path, file_basename);
+ std::string output_file_path = ART_FORMAT("{}/{}", output_directory_path, file_basename);
std::string input_file_path = file->GetPath();
output_files.emplace_back(OS::CreateEmptyFileWriteOnly(output_file_path.c_str()));
@@ -887,7 +884,7 @@
std::string basename =
GetBootImageComponentBasename(framework_bcp_jars[0], /*is_first_jar=*/false);
// Typically "/system/framework/boot-framework.art".
- return "{}/framework/{}"_format(GetAndroidRoot(), basename);
+ return ART_FORMAT("{}/framework/{}", GetAndroidRoot(), basename);
}
std::string OnDeviceRefresh::GetSystemBootImageFrameworkExtensionPath(InstructionSet isa) const {
@@ -901,10 +898,10 @@
GetBootImageComponentBasename(mainline_bcp_jars[0], /*is_first_jar=*/false);
if (on_system) {
// Typically "/system/framework/boot-framework-adservices.art".
- return "{}/framework/{}"_format(GetAndroidRoot(), basename);
+ return ART_FORMAT("{}/framework/{}", GetAndroidRoot(), basename);
} else {
// Typically "/data/misc/apexdata/com.android.art/dalvik-cache/boot-framework-adservices.art".
- return "{}/{}"_format(config_.GetArtifactDirectory(), basename);
+ return ART_FORMAT("{}/{}", config_.GetArtifactDirectory(), basename);
}
}
@@ -952,7 +949,7 @@
std::string image_name = ReplaceFileExtension(jar_name, "art");
const char* isa_str = GetInstructionSetString(config_.GetSystemServerIsa());
// Typically "/system/framework/oat/<isa>/services.art".
- return "{}/oat/{}/{}"_format(Dirname(jar_path), isa_str, image_name);
+ return ART_FORMAT("{}/oat/{}/{}", Dirname(jar_path), isa_str, image_name);
} else {
// Typically
// "/data/misc/apexdata/.../dalvik-cache/<isa>/system@framework@services.jar@classes.art".
@@ -1097,8 +1094,9 @@
if (build_enable_uffd_gc && !kernel_supports_uffd) {
// Normally, this should not happen. If this happens, the system image was probably built with a
// wrong PRODUCT_ENABLE_UFFD_GC flag.
- LOG(WARNING) << "Userfaultfd GC check failed (build-time: {}, runtime: {})."_format(
- build_enable_uffd_gc, kernel_supports_uffd);
+ LOG(WARNING) << ART_FORMAT("Userfaultfd GC check failed (build-time: {}, runtime: {}).",
+ build_enable_uffd_gc,
+ kernel_supports_uffd);
return false;
}
return true;
@@ -1140,14 +1138,18 @@
WARN_UNUSED static bool CheckModuleInfo(const art_apex::ModuleInfo& cached_info,
const apex::ApexInfo& current_info) {
if (cached_info.getVersionCode() != current_info.getVersionCode()) {
- LOG(INFO) << "APEX ({}) version code mismatch (before: {}, now: {})"_format(
- current_info.getModuleName(), cached_info.getVersionCode(), current_info.getVersionCode());
+ LOG(INFO) << ART_FORMAT("APEX ({}) version code mismatch (before: {}, now: {})",
+ current_info.getModuleName(),
+ cached_info.getVersionCode(),
+ current_info.getVersionCode());
return false;
}
if (cached_info.getVersionName() != current_info.getVersionName()) {
- LOG(INFO) << "APEX ({}) version name mismatch (before: {}, now: {})"_format(
- current_info.getModuleName(), cached_info.getVersionName(), current_info.getVersionName());
+ LOG(INFO) << ART_FORMAT("APEX ({}) version name mismatch (before: {}, now: {})",
+ current_info.getModuleName(),
+ cached_info.getVersionName(),
+ current_info.getVersionName());
return false;
}
@@ -1157,10 +1159,10 @@
const int64_t cached_last_update_millis =
cached_info.hasLastUpdateMillis() ? cached_info.getLastUpdateMillis() : -1;
if (cached_last_update_millis != current_info.getLastUpdateMillis()) {
- LOG(INFO) << "APEX ({}) last update time mismatch (before: {}, now: {})"_format(
- current_info.getModuleName(),
- cached_info.getLastUpdateMillis(),
- current_info.getLastUpdateMillis());
+ LOG(INFO) << ART_FORMAT("APEX ({}) last update time mismatch (before: {}, now: {})",
+ current_info.getModuleName(),
+ cached_info.getLastUpdateMillis(),
+ current_info.getLastUpdateMillis());
return false;
}
@@ -1344,12 +1346,12 @@
}
if (boot_images_on_system.Count() == BootImages::kMaxCount) {
- LOG(INFO) << "Boot images on /system OK ({})"_format(isa_str);
+ LOG(INFO) << ART_FORMAT("Boot images on /system OK ({})", isa_str);
// Nothing to compile.
return BootImages{.primary_boot_image = false, .boot_image_mainline_extension = false};
}
- LOG(INFO) << "Checking boot images /data ({})"_format(isa_str);
+ LOG(INFO) << ART_FORMAT("Checking boot images /data ({})", isa_str);
BootImages boot_images_on_data{.primary_boot_image = false,
.boot_image_mainline_extension = false};
@@ -1366,7 +1368,7 @@
// attempt to generate a full boot image even if the minimal one exists.
if (PrimaryBootImageExist(
/*on_system=*/false, /*minimal=*/true, isa, &error_msg, checked_artifacts)) {
- LOG(INFO) << "Found minimal primary boot image ({})"_format(isa_str);
+ LOG(INFO) << ART_FORMAT("Found minimal primary boot image ({})", isa_str);
}
}
} else {
@@ -1396,7 +1398,7 @@
};
if (boot_images_to_generate.Count() == 0) {
- LOG(INFO) << "Boot images on /data OK ({})"_format(isa_str);
+ LOG(INFO) << ART_FORMAT("Boot images on /data OK ({})", isa_str);
}
return boot_images_to_generate;
@@ -1687,7 +1689,7 @@
if (staging_file == nullptr) {
return CompilationResult::Error(
OdrMetrics::Status::kIoError,
- "Failed to create {} file '{}'"_format(kind, staging_location));
+ ART_FORMAT("Failed to create {} file '{}'", kind, staging_location));
}
// Don't check the state of the staging file. It doesn't need to be flushed because it's removed
// after the compilation regardless of success or failure.
@@ -1700,7 +1702,7 @@
if (!EnsureDirectoryExists(install_location)) {
return CompilationResult::Error(
OdrMetrics::Status::kIoError,
- "Error encountered when preparing directory '{}'"_format(install_location));
+ ART_FORMAT("Error encountered when preparing directory '{}'", install_location));
}
std::copy(extra_args.begin(), extra_args.end(), std::back_inserter(args));
@@ -1708,7 +1710,7 @@
Timer timer;
time_t timeout = GetSubprocessTimeout();
std::string cmd_line = Join(args, ' ');
- LOG(INFO) << "{}: {} [timeout {}s]"_format(debug_message, cmd_line, timeout);
+ LOG(INFO) << ART_FORMAT("{}: {} [timeout {}s]", debug_message, cmd_line, timeout);
if (config_.GetDryRun()) {
LOG(INFO) << "Compilation skipped (dry-run).";
return CompilationResult::Ok();
@@ -1721,14 +1723,15 @@
return CompilationResult::Dex2oatError(
dex2oat_result.exit_code < 0 ?
error_msg :
- "dex2oat returned an unexpected code: {}"_format(dex2oat_result.exit_code),
+ ART_FORMAT("dex2oat returned an unexpected code: {}", dex2oat_result.exit_code),
timer.duration().count(),
dex2oat_result);
}
if (!MoveOrEraseFiles(staging_files, install_location)) {
- return CompilationResult::Error(OdrMetrics::Status::kIoError,
- "Failed to commit artifacts to '{}'"_format(install_location));
+ return CompilationResult::Error(
+ OdrMetrics::Status::kIoError,
+ ART_FORMAT("Failed to commit artifacts to '{}'", install_location));
}
return CompilationResult::Dex2oatOk(timer.duration().count(), dex2oat_result);
@@ -1772,7 +1775,7 @@
args.emplace_back(StringPrintf("--dirty-image-objects-fd=%d", file->Fd()));
readonly_files_raii.push_back(std::move(file));
} else {
- LOG(WARNING) << "Missing dirty objects file: '{}'"_format(dirty_image_objects_file);
+ LOG(WARNING) << ART_FORMAT("Missing dirty objects file: '{}'", dirty_image_objects_file);
}
std::string preloaded_classes_file(GetAndroidRoot() + "/etc/preloaded-classes");
@@ -1781,7 +1784,7 @@
args.emplace_back(StringPrintf("--preloaded-classes-fds=%d", file->Fd()));
readonly_files_raii.push_back(std::move(file));
} else {
- LOG(WARNING) << "Missing preloaded classes file: '{}'"_format(preloaded_classes_file);
+ LOG(WARNING) << ART_FORMAT("Missing preloaded classes file: '{}'", preloaded_classes_file);
}
} else {
// Mainline extension.
@@ -1790,7 +1793,7 @@
return RunDex2oat(
staging_dir,
- "Compiling boot classpath ({}, {})"_format(GetInstructionSetString(isa), debug_name),
+ ART_FORMAT("Compiling boot classpath ({}, {})", GetInstructionSetString(isa), debug_name),
isa,
dex_files,
boot_classpath,
@@ -1933,7 +1936,8 @@
if (!file->IsValid()) {
return CompilationResult::Error(
OdrMetrics::Status::kIoError,
- "Failed to open classloader context '{}': {}"_format(actual_path, strerror(errno)));
+ ART_FORMAT(
+ "Failed to open classloader context '{}': {}", actual_path, strerror(errno)));
}
fds.emplace_back(file->Fd());
readonly_files_raii.emplace_back(std::move(file));
@@ -1942,7 +1946,7 @@
}
return RunDex2oat(staging_dir,
- "Compiling {}"_format(Basename(dex_file)),
+ ART_FORMAT("Compiling {}", Basename(dex_file)),
isa,
{dex_file},
boot_classpath_jars_,
@@ -1975,7 +1979,7 @@
if (current_result.IsOk()) {
on_dex2oat_success();
} else {
- LOG(ERROR) << "Compilation of {} failed: {}"_format(Basename(jar), result.error_msg);
+ LOG(ERROR) << ART_FORMAT("Compilation of {} failed: {}", Basename(jar), result.error_msg);
}
}
diff --git a/odrefresh/odrefresh_test.cc b/odrefresh/odrefresh_test.cc
index 119de6b..802c0f0 100644
--- a/odrefresh/odrefresh_test.cc
+++ b/odrefresh/odrefresh_test.cc
@@ -35,7 +35,6 @@
#include "base/file_utils.h"
#include "base/stl_util.h"
#include "exec_utils.h"
-#include "fmt/format.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "odr_artifacts.h"
@@ -57,8 +56,6 @@
using ::testing::ResultOf;
using ::testing::Return;
-using ::fmt::literals::operator""_format; // NOLINT
-
constexpr int kReplace = 1;
void CreateEmptyFile(const std::string& name) {
@@ -434,17 +431,17 @@
.WillOnce(Return(0));
EXPECT_CALL(
*mock_exec_utils_,
- DoExecAndReturnCode(
- AllOf(Contains(Flag("--dex-file=", services_jar_)),
- Contains(Flag("--class-loader-context=", "PCL[{}]"_format(location_provider_jar_))),
- Contains(Flag("--class-loader-context-fds=", FdOf(location_provider_jar_))))))
+ DoExecAndReturnCode(AllOf(
+ Contains(Flag("--dex-file=", services_jar_)),
+ Contains(Flag("--class-loader-context=", ART_FORMAT("PCL[{}]", location_provider_jar_))),
+ Contains(Flag("--class-loader-context-fds=", FdOf(location_provider_jar_))))))
.WillOnce(Return(0));
EXPECT_CALL(
*mock_exec_utils_,
DoExecAndReturnCode(AllOf(
Contains(Flag("--dex-file=", services_foo_jar_)),
Contains(Flag("--class-loader-context=",
- "PCL[];PCL[{}:{}]"_format(location_provider_jar_, services_jar_))),
+ ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))),
Contains(ListFlag("--class-loader-context-fds=",
ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))))))
.WillOnce(Return(0));
@@ -453,7 +450,7 @@
DoExecAndReturnCode(AllOf(
Contains(Flag("--dex-file=", services_bar_jar_)),
Contains(Flag("--class-loader-context=",
- "PCL[];PCL[{}:{}]"_format(location_provider_jar_, services_jar_))),
+ ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))),
Contains(ListFlag("--class-loader-context-fds=",
ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))))))
.WillOnce(Return(0));
@@ -469,17 +466,17 @@
TEST_F(OdRefreshTest, PartialSystemServerJars) {
EXPECT_CALL(
*mock_exec_utils_,
- DoExecAndReturnCode(
- AllOf(Contains(Flag("--dex-file=", services_jar_)),
- Contains(Flag("--class-loader-context=", "PCL[{}]"_format(location_provider_jar_))),
- Contains(Flag("--class-loader-context-fds=", FdOf(location_provider_jar_))))))
+ DoExecAndReturnCode(AllOf(
+ Contains(Flag("--dex-file=", services_jar_)),
+ Contains(Flag("--class-loader-context=", ART_FORMAT("PCL[{}]", location_provider_jar_))),
+ Contains(Flag("--class-loader-context-fds=", FdOf(location_provider_jar_))))))
.WillOnce(Return(0));
EXPECT_CALL(
*mock_exec_utils_,
DoExecAndReturnCode(AllOf(
Contains(Flag("--dex-file=", services_bar_jar_)),
Contains(Flag("--class-loader-context=",
- "PCL[];PCL[{}:{}]"_format(location_provider_jar_, services_jar_))),
+ ART_FORMAT("PCL[];PCL[{}:{}]", location_provider_jar_, services_jar_))),
Contains(ListFlag("--class-loader-context-fds=",
ElementsAre(FdOf(location_provider_jar_), FdOf(services_jar_)))))))
.WillOnce(Return(0));
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 13966d8..56efcab 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -51,7 +51,6 @@
#include "dex/art_dex_file_loader.h"
#include "dex/dex_file_loader.h"
#include "exec_utils.h"
-#include "fmt/format.h"
#include "gc/accounting/space_bitmap-inl.h"
#include "gc/task_processor.h"
#include "image-inl.h"
@@ -78,8 +77,6 @@
using ::android::base::StringAppendF;
using ::android::base::StringPrintf;
-using ::fmt::literals::operator""_format; // NOLINT
-
// We do not allow the boot image and extensions to take more than 1GiB. They are
// supposed to be much smaller and allocating more that this would likely fail anyway.
static constexpr size_t kMaxTotalImageReservationSize = 1 * GB;
@@ -3446,8 +3443,9 @@
if (oat_file.GetOatHeader().GetKeyValueStoreSize() != 0 &&
oat_file.GetOatHeader().IsConcurrentCopying() != gUseReadBarrier) {
*error_msg =
- "ValidateOatFile found read barrier state mismatch (oat file: {}, runtime: {})"_format(
- oat_file.GetOatHeader().IsConcurrentCopying(), gUseReadBarrier);
+ ART_FORMAT("ValidateOatFile found read barrier state mismatch (oat file: {}, runtime: {})",
+ oat_file.GetOatHeader().IsConcurrentCopying(),
+ gUseReadBarrier);
return false;
}