1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_COMPILER_XLA_PARSE_FLAGS_FROM_ENV_H_ 17 #define TENSORFLOW_COMPILER_XLA_PARSE_FLAGS_FROM_ENV_H_ 18 19 // This module exports ParseFlagsFromEnvAndDieIfUnknown(), which allows other 20 // modules to parse flags from an environtment variable, or (if the first 21 // non-whitespace in the variable value is not '-'), a file named by that 22 // environment variable. 23 // 24 // The accepted syntax is that flags arguments are of the form --flag=value or 25 // (for boolean flags) --flag, and are whitespace separated. The <value> may be 26 // one of: 27 // 28 // - <non-whitespace, non-nul not starting with single-quote or double-quote> 29 // in which case the effective value is the string itself 30 // - <single-quote><characters string not containing nul or 31 // single-quote><single_quote> in which case the effective value is the 32 // string with the single-quotes removed 33 // - <double-quote><character string not containing nul or unesecaped 34 // double-quote><double_quote> in which case the effective value if the 35 // string with the double-quotes removed, and escaped sequences of 36 // <backslash><char> replaced by <char>. 37 // 38 // Flags values inconsistent with the type of the flag will be rejected by the 39 // flag parser. 40 // 41 // Examples: 42 // 43 // - TF_XLA_FLAGS="--foo=bar --wombat='value with a space'" 44 // - TF_XLA_FLAGS=/tmp/flagfile 45 // 46 // where /tmp/flagfile might contain 47 // 48 // --some_flag="This is a string containing a \" and a '." 49 // --another_flag=wombats 50 51 #include <vector> 52 53 #include "absl/strings/string_view.h" 54 #include "tensorflow/compiler/xla/types.h" 55 #include "tensorflow/core/platform/types.h" 56 #include "tensorflow/core/util/command_line_flags.h" 57 58 namespace xla { 59 60 // Calls tensorflow::Flags::Parse(argc, argv, flag_list) against any as yet 61 // unrecognized flags passed in the environment variable `envvar`, and returns 62 // its return value. 63 // 64 // Raises a fatal error if any flags in `envvar` were not recognized. 65 bool ParseFlagsFromEnvAndDieIfUnknown( 66 absl::string_view envvar, const std::vector<tensorflow::Flag>& flag_list); 67 68 // Used only for testing. Not to be used by clients. 69 void ResetFlagsFromEnvForTesting(absl::string_view envvar, int** pargc, 70 std::vector<char*>** pargv); 71 72 } // namespace xla 73 74 #endif // TENSORFLOW_COMPILER_XLA_PARSE_FLAGS_FROM_ENV_H_ 75