Skip to content

Commit

Permalink
revise gflags portability namespaces
Browse files Browse the repository at this point in the history
Summary: Let `folly::gflags` be an alias to the true gflags namespace if gflags is available.

Reviewed By: Gownta

Differential Revision: D65899780

fbshipit-source-id: 7e050d5268f484f92b58d179005c4ce79f3cee52
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Nov 25, 2024
1 parent 1150e5f commit 3729257
Show file tree
Hide file tree
Showing 125 changed files with 189 additions and 221 deletions.
27 changes: 0 additions & 27 deletions CMake/FollyConfigChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,3 @@ check_cxx_source_runs("
}"
HAVE_VSNPRINTF_ERRORS
)

if (FOLLY_HAVE_LIBGFLAGS)
# Older releases of gflags used the namespace "gflags"; newer releases
# use "google" but also make symbols available in the deprecated "gflags"
# namespace too. The folly code internally uses "gflags" unless we tell it
# otherwise.
list(APPEND CMAKE_REQUIRED_LIBRARIES ${FOLLY_LIBGFLAGS_LIBRARY})
list(APPEND CMAKE_REQUIRED_INCLUDES ${FOLLY_LIBGFLAGS_INCLUDE})
check_cxx_source_compiles("
#include <gflags/gflags.h>
int main() {
gflags::GetArgv();
return 0;
}
"
GFLAGS_NAMESPACE_IS_GFLAGS
)
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FOLLY_LIBGFLAGS_LIBRARY})
list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FOLLY_LIBGFLAGS_INCLUDE})
if (GFLAGS_NAMESPACE_IS_GFLAGS)
set(FOLLY_UNUSUAL_GFLAGS_NAMESPACE OFF)
set(FOLLY_GFLAGS_NAMESPACE gflags)
else()
set(FOLLY_UNUSUAL_GFLAGS_NAMESPACE ON)
set(FOLLY_GFLAGS_NAMESPACE google)
endif()
endif()
2 changes: 0 additions & 2 deletions CMake/folly-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#cmakedefine FOLLY_HAVE_PTHREAD_ATFORK 1

#cmakedefine FOLLY_HAVE_LIBGFLAGS 1
#cmakedefine FOLLY_UNUSUAL_GFLAGS_NAMESPACE 1
#cmakedefine FOLLY_GFLAGS_NAMESPACE @FOLLY_GFLAGS_NAMESPACE@

#cmakedefine FOLLY_HAVE_LIBGLOG 1

Expand Down
22 changes: 11 additions & 11 deletions folly/cli/ProgramOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace {
template <class T>
class GFlagInfo {
public:
explicit GFlagInfo(gflags::CommandLineFlagInfo info)
explicit GFlagInfo(folly::gflags::CommandLineFlagInfo info)
: info_(std::move(info)), isSet_(false) {}

void set(const T& value) {
Expand All @@ -57,8 +57,8 @@ class GFlagInfo {
}

auto strValue = folly::to<std::string>(value);
auto msg =
gflags::SetCommandLineOption(info_.name.c_str(), strValue.c_str());
auto msg = folly::gflags::SetCommandLineOption(
info_.name.c_str(), strValue.c_str());
if (msg.empty()) {
throw po::invalid_option_value(strValue);
}
Expand All @@ -67,14 +67,14 @@ class GFlagInfo {

T get() const {
std::string str;
CHECK(gflags::GetCommandLineOption(info_.name.c_str(), &str));
CHECK(folly::gflags::GetCommandLineOption(info_.name.c_str(), &str));
return folly::to<T>(str);
}

const gflags::CommandLineFlagInfo& info() const { return info_; }
const folly::gflags::CommandLineFlagInfo& info() const { return info_; }

private:
gflags::CommandLineFlagInfo info_;
folly::gflags::CommandLineFlagInfo info_;
bool isSet_;
};

Expand Down Expand Up @@ -181,7 +181,7 @@ const std::string& getName(const std::string& name) {

template <class T>
void addGFlag(
gflags::CommandLineFlagInfo&& flag,
folly::gflags::CommandLineFlagInfo&& flag,
po::options_description& desc,
ProgramOptionsStyle style) {
auto gflagInfo = std::make_shared<GFlagInfo<T>>(std::move(flag));
Expand All @@ -203,7 +203,7 @@ void addGFlag(

template <>
void addGFlag<bool>(
gflags::CommandLineFlagInfo&& flag,
folly::gflags::CommandLineFlagInfo&& flag,
po::options_description& desc,
ProgramOptionsStyle style) {
auto gflagInfo = std::make_shared<GFlagInfo<bool>>(std::move(flag));
Expand Down Expand Up @@ -233,7 +233,7 @@ void addGFlag<bool>(
}

typedef void (*FlagAdder)(
gflags::CommandLineFlagInfo&&,
folly::gflags::CommandLineFlagInfo&&,
po::options_description&,
ProgramOptionsStyle);

Expand Down Expand Up @@ -272,8 +272,8 @@ po::options_description getGFlags(ProgramOptionsStyle style) {

po::options_description desc("GFlags");

std::vector<gflags::CommandLineFlagInfo> allFlags;
gflags::GetAllFlags(&allFlags);
std::vector<folly::gflags::CommandLineFlagInfo> allFlags;
folly::gflags::GetAllFlags(&allFlags);

for (auto& f : allFlags) {
if (gSkipFlags.count(f.name)) {
Expand Down
1 change: 0 additions & 1 deletion folly/compression/elias_fano/test/BitVectorCodingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ Encode 10.88ms 91.90
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
folly::Init init(&argc, &argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);

auto ret = RUN_ALL_TESTS();
if (ret == 0 && FLAGS_benchmark) {
Expand Down
1 change: 0 additions & 1 deletion folly/compression/elias_fano/test/EliasFanoCodingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ slowDefaultNumLowerBits 10.88ns 91.90M
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
folly::Init init(&argc, &argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);

auto ret = RUN_ALL_TESTS();
if (ret == 0 && FLAGS_benchmark) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ BENCHMARK(SingleThreadedStores, n) {
}

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ BENCHMARK_RELATIVE(TLReadMostlyMainPtrDtor, n) {
}

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
gflags::SetCommandLineOptionWithMode(
"bm_min_usec", "100000", gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::SetCommandLineOptionWithMode(
"bm_min_usec", "100000", folly::gflags::SET_FLAG_IF_DEFAULT);

folly::runBenchmarks();

Expand Down
6 changes: 3 additions & 3 deletions folly/concurrency/memory/test/RefCountBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ BENCHMARK(AtomicTwentyFourThreads, n) {
} // namespace folly

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
gflags::SetCommandLineOptionWithMode(
"bm_min_usec", "100000", gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::SetCommandLineOptionWithMode(
"bm_min_usec", "100000", folly::gflags::SET_FLAG_IF_DEFAULT);

folly::runBenchmarks();

Expand Down
2 changes: 1 addition & 1 deletion folly/concurrency/test/CacheLocalityBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ BENCHMARK_NAMED_PARAM(contentionAtWidthGetcpu, 32_stripe_1000_work, 32, 1000)
BENCHMARK_NAMED_PARAM(atomicIncrBaseline, local_incr_1000_work, 1000)

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/concurrency/test/CoreCachedSharedPtrTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ BENCHMARK_MULTI(AtomicCoreCachedSharedPtrSingleThreadReset) {

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);

auto ret = RUN_ALL_TESTS();
if (ret == 0 && FLAGS_benchmark) {
Expand Down
2 changes: 1 addition & 1 deletion folly/concurrency/test/ThreadCachedSynchronizedBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ BENCHMARK(read_int_thread_cached_synchronized, iters) {
}

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/container/test/EvictingCacheMapBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ BENCHMARK_PARAM(insertCache, 1754650) // 1.75M
BENCHMARK_PARAM(insertCache, 11356334) // 11.3M

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
runBenchmarks();
}
14 changes: 7 additions & 7 deletions folly/container/test/FBVectorBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ using FBStringFBVector = fbvector<folly::fbstring>;
#undef VECTOR

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
gflags::SetCommandLineOptionWithMode(
"bm_max_iters", "1000000", gflags::SET_FLAG_IF_DEFAULT);
gflags::SetCommandLineOptionWithMode(
"bm_min_iters", "100000", gflags::SET_FLAG_IF_DEFAULT);
gflags::SetCommandLineOptionWithMode(
"bm_max_secs", "1", gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::SetCommandLineOptionWithMode(
"bm_max_iters", "1000000", folly::gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::SetCommandLineOptionWithMode(
"bm_min_iters", "100000", folly::gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::SetCommandLineOptionWithMode(
"bm_max_secs", "1", folly::gflags::SET_FLAG_IF_DEFAULT);

folly::runBenchmarks();
return 0;
Expand Down
12 changes: 6 additions & 6 deletions folly/container/test/HashMapsBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ void runAllHashMapTests() {

int main(int argc, char** argv) {
folly::Init init(&argc, &argv);
gflags::SetCommandLineOptionWithMode(
"bm_max_iters", "100000", gflags::SET_FLAG_IF_DEFAULT);
gflags::SetCommandLineOptionWithMode(
"bm_min_iters", "10000", gflags::SET_FLAG_IF_DEFAULT);
gflags::SetCommandLineOptionWithMode(
"bm_max_secs", "1", gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::SetCommandLineOptionWithMode(
"bm_max_iters", "100000", folly::gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::SetCommandLineOptionWithMode(
"bm_min_iters", "10000", folly::gflags::SET_FLAG_IF_DEFAULT);
folly::gflags::SetCommandLineOptionWithMode(
"bm_max_secs", "1", folly::gflags::SET_FLAG_IF_DEFAULT);
LOG(INFO) << "Preparing benchmark...";
runAllHashMapTests();
LOG(INFO) << "Running benchmark, which could take tens of minutes...";
Expand Down
2 changes: 1 addition & 1 deletion folly/container/test/SparseByteSetBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void setup_rand_bench() {
} // namespace

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
setup_rand_bench();
runBenchmarks();
return 0;
Expand Down
2 changes: 1 addition & 1 deletion folly/coro/test/AsyncGeneratorBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ BENCHMARK(compareToSynchronousGeneratorYieldValues, iters) {
#endif

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/coro/test/BlockingWaitBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ BENCHMARK(blockingWaitRVO, iters) {
#endif

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/coro/test/CollectAllBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ BENCHMARK(collectAllBaton100, iters) {
}

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/coro/test/CoroBenchmarkAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ BENCHMARK(recursionDepth1000, iters) {
#endif

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/coro/test/CoroBenchmarkNRVO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ BENCHMARK(NRVOTenAwaits, iters) {
}

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/coro/test/PromiseBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ BENCHMARK_COUNTERS(FuturesFutureSuspend, counters, iters) {
#endif

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/coro/test/TaskBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ BENCHMARK(NestedCallsWithCancellation10, iters) {
#endif // FOLLY_HAS_COROUTINES

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ BENCHMARK(ExceptionTracer, iters) {
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF

int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
folly::runBenchmarks();
return 0;
Expand Down
2 changes: 1 addition & 1 deletion folly/debugging/symbolizer/test/DwarfBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ BENCHMARK(DwarfFindAddressFullWithInline, n) {
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF

int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
folly::runBenchmarksOnFlag();
return 0;
Expand Down
2 changes: 1 addition & 1 deletion folly/detail/test/ThreadLocalBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BENCHMARK_NAMED_PARAM(accessAllThreads, 2000t_20000c_50s, 2000, 20000, 50)
BENCHMARK_DRAW_LINE();

int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
2 changes: 1 addition & 1 deletion folly/executors/test/EDFThreadPoolExecutorBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ BENCHMARK_RELATIVE_NAMED_PARAM(
multiThreaded, EDFEx, std::make_unique<EDFThreadPoolExecutor>(kNumThreads))

int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();

return 0;
Expand Down
2 changes: 1 addition & 1 deletion folly/executors/test/GlobalCPUExecutorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <folly/synchronization/Baton.h>

TEST(GlobalCPUExecutorTest, CPUThreadCountFlagSet) {
gflags::FlagSaver flagsaver;
folly::gflags::FlagSaver flagsaver;

FLAGS_folly_global_cpu_executor_threads = 100;
auto cpu_threadpool = dynamic_cast<folly::CPUThreadPoolExecutor*>(
Expand Down
4 changes: 2 additions & 2 deletions folly/executors/test/GlobalExecutorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ TEST(GlobalExecutorTest, GlobalIOExecutor) {
}

TEST(GlobalExecutorTest, IOThreadCountFlagUnset) {
gflags::FlagSaver flagsaver;
folly::gflags::FlagSaver flagsaver;

auto io_threadpool = dynamic_cast<folly::IOThreadPoolExecutor*>(
folly::getGlobalIOExecutor().get());
Expand All @@ -128,7 +128,7 @@ TEST(GlobalExecutorTest, IOThreadCountFlagUnset) {
}

TEST(GlobalExecutorTest, CPUThreadCountFlagUnset) {
gflags::FlagSaver flagsaver;
folly::gflags::FlagSaver flagsaver;

EXPECT_EQ(
getGlobalCPUExecutorCounters().numThreads, folly::hardware_concurrency());
Expand Down
2 changes: 1 addition & 1 deletion folly/executors/test/GlobalIOExecutorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using namespace folly;

TEST(GlobalExecutorTest, IOThreadCountFlagSet) {
gflags::FlagSaver flagsaver;
folly::gflags::FlagSaver flagsaver;

FLAGS_folly_global_io_executor_threads = 100;
auto io_threadpool = dynamic_cast<folly::IOThreadPoolExecutor*>(
Expand Down
2 changes: 1 addition & 1 deletion folly/futures/test/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ BENCHMARK_RELATIVE(complexBlob4096) {
}

int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::gflags::ParseCommandLineFlags(&argc, &argv, true);
folly::runBenchmarks();
return 0;
}
Loading

0 comments on commit 3729257

Please sign in to comment.