-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup flags.h, write options to some channel, stdout in cmdline
Summary: fixes #61 fixes #62 in fb services will call printOptions(LOG(INFO)); {need fb side work/will break there/this is a start/proposal} Closes #63 Reviewed By: @uddipta Differential Revision: D2397161 Pulled By: @ldemailly
- Loading branch information
Showing
8 changed files
with
115 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,72 @@ | ||
/// override-include-guard | ||
|
||
// If you make any changes to this - use g++ -E to check the generated code | ||
|
||
/// Which options object to use (we can reuse those macros for fbonly options) | ||
#ifndef OPTIONS | ||
#define OPTIONS WdtOptions | ||
#endif | ||
|
||
// Short symbol A is a field inside the Options struct | ||
// The flag name is either the short one DEFINE_type(A,...) or | ||
// prefixed by wdt_ so we play nice with others when making a | ||
// library (long flag) | ||
#define WDT_READ_OPT(A) facebook::wdt::OPTIONS::get().A | ||
#define WDT_WRITE_OPT(A) facebook::wdt::OPTIONS::getMutable().A | ||
|
||
// Generic macros to concat and stringify: | ||
// Turns wdt_ and foo into wdt_foo | ||
#define WDT_CONCAT1(a, b) a##b | ||
#define WDT_CONCAT(a, b) WDT_CONCAT1(a, b) | ||
// Turns a symbol into a string literal ie foo to "foo" | ||
// Needs two steps so WDT_TOSTR(WDT_CONCAT(wdt_,foo)) gives "wdt_foo" | ||
// and not "WDT_CONCAT(wdt_,foo)" | ||
#define WDT_TOSTR1(x) #x | ||
#define WDT_TOSTR(x) WDT_TOSTR1(x) | ||
|
||
#define WDT_LONG_PREFIX wdt_ | ||
|
||
#ifndef STANDALONE_APP | ||
#define PREFIX(argument) wdt_##argument | ||
#define WDT_PREFIX(argument) WDT_CONCAT(WDT_LONG_PREFIX, argument) | ||
#else | ||
#define PREFIX(argument) argument | ||
#define WDT_PREFIX(argument) argument | ||
#endif | ||
#define VALUE(A) facebook::wdt::OPTIONS::get().A | ||
|
||
#define VALUE_X(argument) FLAGS_##argument | ||
#define CAT(argument) VALUE_X(argument) | ||
#define FLAG_VALUE(argument) CAT(PREFIX(argument)) | ||
// Symbol. eg wdt_foo | ||
#define WDT_FLAG_SYM(A) WDT_PREFIX(A) | ||
// String version eg "wdt_foo" | ||
#define WDT_FLAG_STR(A) WDT_TOSTR(WDT_FLAG_SYM(A)) | ||
// Flag variable eg FLAGS_wdt_foo | ||
#define WDT_FLAG_VAR(A) WDT_CONCAT(FLAGS_, WDT_FLAG_SYM(A)) | ||
|
||
#ifdef WDT_OPT | ||
#undef WDT_OPT | ||
#endif | ||
|
||
/// Setup variants to replace WDT_OPT by the right code depending | ||
/// on the mode/context. Trailing semi colon is expected to be in the .inc | ||
#ifdef ASSIGN_OPT | ||
// Assign option from flags | ||
#define WDT_OPT(argument, type, description) \ | ||
facebook::wdt::OPTIONS::getMutable().argument = FLAG_VALUE(argument); | ||
#define WDT_OPT(A, type, description) WDT_WRITE_OPT(A) = WDT_FLAG_VAR(A) | ||
#else | ||
#ifdef PRINT_OPT | ||
// print options | ||
#define WDT_OPT(argument, type, description) \ | ||
LOG(INFO) << #argument << " " << facebook::wdt::OPTIONS::get().argument; | ||
#define WDT_OPT(A, type, description) \ | ||
out << WDT_TOSTR(A) << " " << WDT_READ_OPT(A) << std::endl | ||
#else | ||
|
||
#define FLAG_DECLARATION(type, argument) DECLARE_##type(argument); | ||
#define FLAG_DEFINITION(type, argument, value, description) \ | ||
// google flag define or declare: | ||
#define WDT_FLAG_DECLARATION(type, argument) DECLARE_##type(argument); | ||
#define WDT_FLAG_DEFINITION(type, argument, value, description) \ | ||
DEFINE_##type(argument, value, description); | ||
|
||
#ifdef DECLARE_ONLY | ||
// declare flags | ||
#define WDT_OPT(argument, type, description) \ | ||
FLAG_DECLARATION(type, PREFIX(argument)) | ||
#define WDT_OPT(A, type, description) \ | ||
WDT_FLAG_DECLARATION(type, WDT_FLAG_SYM(A)) | ||
#else | ||
// define flags | ||
#define WDT_OPT(argument, type, description) \ | ||
FLAG_DEFINITION(type, PREFIX(argument), VALUE(argument), description) | ||
#define WDT_OPT(A, type, description) \ | ||
WDT_FLAG_DEFINITION(type, WDT_FLAG_SYM(A), WDT_READ_OPT(A), description) | ||
#endif | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters