[libyuv] - Switch from gflags to absl/flags.

No-Try: True
Bug: libyuv:883
Change-Id: I11f1dbcccdc3697b73b3cfc2d423876841eb7b7a
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/2701771
Commit-Queue: Mirko Bonadei <mbonadei@chromium.org>
Reviewed-by: Frank Barchard <fbarchard@chromium.org>
This commit is contained in:
Mirko Bonadei 2021-02-17 21:32:05 +01:00 committed by Commit Bot
parent d768774299
commit 63dd43dd46
4 changed files with 98 additions and 104 deletions

View File

@ -10,8 +10,8 @@ import("//testing/test.gni")
import("libyuv.gni")
declare_args() {
# Set to false to disable building with gflags.
libyuv_use_gflags = true
# Set to false to disable building with absl flags.
libyuv_use_absl_flags = true
# When building a shared library using a target in WebRTC or
# Chromium projects that depends on libyuv, setting this flag
@ -294,9 +294,12 @@ if (libyuv_include_tests) {
]
defines = []
if (libyuv_use_gflags) {
defines += [ "LIBYUV_USE_GFLAGS" ]
deps += [ "//third_party/gflags" ]
if (libyuv_use_absl_flags) {
defines += [ "LIBYUV_USE_ABSL_FLAGS" ]
deps += [
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
]
}
configs += [ ":libyuv_unittest_warnings_config" ]

View File

@ -71,12 +71,6 @@ if(TEST)
if(NACL AND NACL_LIBC STREQUAL "newlib")
target_link_libraries(libyuv_unittest glibc-compat)
endif()
find_library(GFLAGS_LIBRARY gflags)
if(NOT GFLAGS_LIBRARY STREQUAL "GFLAGS_LIBRARY-NOTFOUND")
target_link_libraries(libyuv_unittest gflags)
add_definitions(-DLIBYUV_USE_GFLAGS)
endif()
endif()

7
DEPS
View File

@ -80,10 +80,6 @@ deps = {
Var('chromium_git') + '/infra/luci/client-py.git' + '@' + 'd46ea7635f2911208268170512cb611412488fd8',
# libyuv-only dependencies (not present in Chromium).
'src/third_party/gflags':
Var('chromium_git') + '/external/webrtc/deps/third_party/gflags' + '@' + '892576179b45861b53e04a112996a738309cf364',
'src/third_party/gflags/src':
Var('chromium_git') + '/external/github.com/gflags/gflags' + '@' + '03bebcb065c83beff83d50ae025a55a4bf94dfca',
'src/third_party/gtest-parallel':
Var('chromium_git') + '/external/webrtc/deps/third_party/gtest-parallel' + '@' + '1dad0e9f6d82ff994130b529d7d814b40eb32b0e',
@ -2945,9 +2941,6 @@ deps = {
# === ANDROID_DEPS Generated Code End ===
}
# Define rules for which include paths are allowed in our source.
include_rules = [ '+gflags' ]
pre_deps_hooks = [
{
# Remove any symlinks from before 177567c518b121731e507e9b9c4049c4dc96e4c8.

View File

@ -14,8 +14,9 @@
#include <cstring>
#ifdef LIBYUV_USE_GFLAGS
#include "gflags/gflags.h"
#ifdef LIBYUV_USE_ABSL_FLAGS
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#endif
#ifdef LIBYUV_USE_BASE_FLAGS
#include "base/commandlineflags.h"
@ -24,16 +25,16 @@
unsigned int fastrand_seed = 0xfb;
#ifdef LIBYUV_USE_GFLAGS
DEFINE_int32(libyuv_width, 0, "width of test image.");
DEFINE_int32(libyuv_height, 0, "height of test image.");
DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test.");
DEFINE_int32(libyuv_flags, 0, "cpu flags for reference code. 1 = C, -1 = SIMD");
DEFINE_int32(libyuv_cpu_info,
0,
"cpu flags for benchmark code. 1 = C, -1 = SIMD");
#ifdef LIBYUV_USE_ABSL_FLAGS
ABSL_FLAG(int32_t, libyuv_width, 0, "width of test image.");
ABSL_FLAG(int32_t, libyuv_height, 0, "height of test image.");
ABSL_FLAG(int32_t, libyuv_repeat, 0, "number of times to repeat test.");
ABSL_FLAG(int32_t, libyuv_flags, 0,
"cpu flags for reference code. 1 = C, -1 = SIMD");
ABSL_FLAG(int32_t, libyuv_cpu_info, 0,
"cpu flags for benchmark code. 1 = C, -1 = SIMD");
#else
// Disable command line parameters if gflags disabled.
// Disable command line parameters if absl/flags disabled.
static const int32_t FLAGS_libyuv_width = 0;
static const int32_t FLAGS_libyuv_height = 0;
static const int32_t FLAGS_libyuv_repeat = 0;
@ -41,6 +42,12 @@ static const int32_t FLAGS_libyuv_flags = 0;
static const int32_t FLAGS_libyuv_cpu_info = 0;
#endif
#ifdef LIBYUV_USE_ABSL_FLAGS
#define LIBYUV_GET_FLAG(f) absl::GetFlag(f)
#else
#define LIBYUV_GET_FLAG(f) f
#endif
// Test environment variable for disabling CPU features. Any non-zero value
// to disable. Zero ignored to make it easy to set the variable on/off.
#if !defined(__native_client__) && !defined(_M_ARM)
@ -148,8 +155,8 @@ LibYUVConvertTest::LibYUVConvertTest()
if (repeat) {
benchmark_iterations_ = atoi(repeat); // NOLINT
}
if (FLAGS_libyuv_repeat) {
benchmark_iterations_ = FLAGS_libyuv_repeat;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
}
if (benchmark_iterations_ > 1) {
benchmark_width_ = 1280;
@ -159,29 +166,29 @@ LibYUVConvertTest::LibYUVConvertTest()
if (width) {
benchmark_width_ = atoi(width); // NOLINT
}
if (FLAGS_libyuv_width) {
benchmark_width_ = FLAGS_libyuv_width;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
}
const char* height = getenv("LIBYUV_HEIGHT");
if (height) {
benchmark_height_ = atoi(height); // NOLINT
}
if (FLAGS_libyuv_height) {
benchmark_height_ = FLAGS_libyuv_height;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
}
const char* cpu_flags = getenv("LIBYUV_FLAGS");
if (cpu_flags) {
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_flags) {
disable_cpu_flags_ = FLAGS_libyuv_flags;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
}
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
if (cpu_info) {
benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_cpu_info) {
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
}
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
@ -204,8 +211,8 @@ LibYUVColorTest::LibYUVColorTest()
if (repeat) {
benchmark_iterations_ = atoi(repeat); // NOLINT
}
if (FLAGS_libyuv_repeat) {
benchmark_iterations_ = FLAGS_libyuv_repeat;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
}
if (benchmark_iterations_ > 1) {
benchmark_width_ = 1280;
@ -215,29 +222,29 @@ LibYUVColorTest::LibYUVColorTest()
if (width) {
benchmark_width_ = atoi(width); // NOLINT
}
if (FLAGS_libyuv_width) {
benchmark_width_ = FLAGS_libyuv_width;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
}
const char* height = getenv("LIBYUV_HEIGHT");
if (height) {
benchmark_height_ = atoi(height); // NOLINT
}
if (FLAGS_libyuv_height) {
benchmark_height_ = FLAGS_libyuv_height;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
}
const char* cpu_flags = getenv("LIBYUV_FLAGS");
if (cpu_flags) {
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_flags) {
disable_cpu_flags_ = FLAGS_libyuv_flags;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
}
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
if (cpu_info) {
benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_cpu_info) {
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
}
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
@ -260,8 +267,8 @@ LibYUVScaleTest::LibYUVScaleTest()
if (repeat) {
benchmark_iterations_ = atoi(repeat); // NOLINT
}
if (FLAGS_libyuv_repeat) {
benchmark_iterations_ = FLAGS_libyuv_repeat;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
}
if (benchmark_iterations_ > 1) {
benchmark_width_ = 1280;
@ -271,29 +278,29 @@ LibYUVScaleTest::LibYUVScaleTest()
if (width) {
benchmark_width_ = atoi(width); // NOLINT
}
if (FLAGS_libyuv_width) {
benchmark_width_ = FLAGS_libyuv_width;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
}
const char* height = getenv("LIBYUV_HEIGHT");
if (height) {
benchmark_height_ = atoi(height); // NOLINT
}
if (FLAGS_libyuv_height) {
benchmark_height_ = FLAGS_libyuv_height;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
}
const char* cpu_flags = getenv("LIBYUV_FLAGS");
if (cpu_flags) {
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_flags) {
disable_cpu_flags_ = FLAGS_libyuv_flags;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
}
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
if (cpu_info) {
benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_cpu_info) {
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
}
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
@ -316,8 +323,8 @@ LibYUVRotateTest::LibYUVRotateTest()
if (repeat) {
benchmark_iterations_ = atoi(repeat); // NOLINT
}
if (FLAGS_libyuv_repeat) {
benchmark_iterations_ = FLAGS_libyuv_repeat;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
}
if (benchmark_iterations_ > 1) {
benchmark_width_ = 1280;
@ -327,29 +334,29 @@ LibYUVRotateTest::LibYUVRotateTest()
if (width) {
benchmark_width_ = atoi(width); // NOLINT
}
if (FLAGS_libyuv_width) {
benchmark_width_ = FLAGS_libyuv_width;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
}
const char* height = getenv("LIBYUV_HEIGHT");
if (height) {
benchmark_height_ = atoi(height); // NOLINT
}
if (FLAGS_libyuv_height) {
benchmark_height_ = FLAGS_libyuv_height;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
}
const char* cpu_flags = getenv("LIBYUV_FLAGS");
if (cpu_flags) {
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_flags) {
disable_cpu_flags_ = FLAGS_libyuv_flags;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
}
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
if (cpu_info) {
benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_cpu_info) {
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
}
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
@ -372,8 +379,8 @@ LibYUVPlanarTest::LibYUVPlanarTest()
if (repeat) {
benchmark_iterations_ = atoi(repeat); // NOLINT
}
if (FLAGS_libyuv_repeat) {
benchmark_iterations_ = FLAGS_libyuv_repeat;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
}
if (benchmark_iterations_ > 1) {
benchmark_width_ = 1280;
@ -383,29 +390,29 @@ LibYUVPlanarTest::LibYUVPlanarTest()
if (width) {
benchmark_width_ = atoi(width); // NOLINT
}
if (FLAGS_libyuv_width) {
benchmark_width_ = FLAGS_libyuv_width;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
}
const char* height = getenv("LIBYUV_HEIGHT");
if (height) {
benchmark_height_ = atoi(height); // NOLINT
}
if (FLAGS_libyuv_height) {
benchmark_height_ = FLAGS_libyuv_height;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
}
const char* cpu_flags = getenv("LIBYUV_FLAGS");
if (cpu_flags) {
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_flags) {
disable_cpu_flags_ = FLAGS_libyuv_flags;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
}
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
if (cpu_info) {
benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_cpu_info) {
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
}
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
@ -428,8 +435,8 @@ LibYUVBaseTest::LibYUVBaseTest()
if (repeat) {
benchmark_iterations_ = atoi(repeat); // NOLINT
}
if (FLAGS_libyuv_repeat) {
benchmark_iterations_ = FLAGS_libyuv_repeat;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
}
if (benchmark_iterations_ > 1) {
benchmark_width_ = 1280;
@ -439,29 +446,29 @@ LibYUVBaseTest::LibYUVBaseTest()
if (width) {
benchmark_width_ = atoi(width); // NOLINT
}
if (FLAGS_libyuv_width) {
benchmark_width_ = FLAGS_libyuv_width;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
}
const char* height = getenv("LIBYUV_HEIGHT");
if (height) {
benchmark_height_ = atoi(height); // NOLINT
}
if (FLAGS_libyuv_height) {
benchmark_height_ = FLAGS_libyuv_height;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
}
const char* cpu_flags = getenv("LIBYUV_FLAGS");
if (cpu_flags) {
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_flags) {
disable_cpu_flags_ = FLAGS_libyuv_flags;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
}
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
if (cpu_info) {
benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_cpu_info) {
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
}
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
@ -484,8 +491,8 @@ LibYUVCompareTest::LibYUVCompareTest()
if (repeat) {
benchmark_iterations_ = atoi(repeat); // NOLINT
}
if (FLAGS_libyuv_repeat) {
benchmark_iterations_ = FLAGS_libyuv_repeat;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
}
if (benchmark_iterations_ > 1) {
benchmark_width_ = 1280;
@ -495,29 +502,29 @@ LibYUVCompareTest::LibYUVCompareTest()
if (width) {
benchmark_width_ = atoi(width); // NOLINT
}
if (FLAGS_libyuv_width) {
benchmark_width_ = FLAGS_libyuv_width;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
}
const char* height = getenv("LIBYUV_HEIGHT");
if (height) {
benchmark_height_ = atoi(height); // NOLINT
}
if (FLAGS_libyuv_height) {
benchmark_height_ = FLAGS_libyuv_height;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
}
const char* cpu_flags = getenv("LIBYUV_FLAGS");
if (cpu_flags) {
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_flags) {
disable_cpu_flags_ = FLAGS_libyuv_flags;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
}
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
if (cpu_info) {
benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
}
if (FLAGS_libyuv_cpu_info) {
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
}
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
@ -532,11 +539,8 @@ LibYUVCompareTest::LibYUVCompareTest()
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
#ifdef LIBYUV_USE_GFLAGS
// AllowCommandLineParsing allows us to ignore flags passed on to us by
// Chromium build bots without having to explicitly disable them.
google::AllowCommandLineReparsing();
google::ParseCommandLineFlags(&argc, &argv, true);
#ifdef LIBYUV_USE_ABSL_FLAGS
absl::ParseCommandLine(argc, argv);
#endif
return RUN_ALL_TESTS();
}