aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/legacy_flags/parse_flags_from_env.h
blob: b54482ad2ba2224c781861341a80ceb878ffd343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef TENSORFLOW_COMPILER_XLA_LEGACY_FLAGS_PARSE_FLAGS_FROM_ENV_H_
#define TENSORFLOW_COMPILER_XLA_LEGACY_FLAGS_PARSE_FLAGS_FROM_ENV_H_

// This module exports ParseFlagsFromEnv(), which allows other modules to parse
// flags from the environtment variable TF_XLA_FLAGS, or (if the first
// non-whitespace in the variable value is not '-'), a file named by that
// environment variable.  The accepted syntax is that flags arguments are of
// the form --flag=value or (for boolean flags) --flag, and are whitespace
// separated.  The <value> may be one of:
// - <non-whitespace, non-nul not starting with single-quote or double-quote>
//   in which case the effective value is the string itself
// - <single-quote><characters string not containing nul or
//   single-quote><single_quote> in which case the effective value is the
//   string with the single-quotes removed
// - <double-quote><character string not containing nul or unesecaped
//   double-quote><double_quote> in which case the effective value if the
//   string with the double-quotes removed, and escaped sequences of
//   <backslash><char> replaced by <char>.
//
// Flags values inconsistent with the type of the flag will be rejected by the
// flag parser.
//
// Examples:
//    TF_XLA_FLAGS="--foo=bar  --wombat='value with a space'"
//
//    TF_XLA_FLAGS=/tmp/flagfile
// where /tmp/flagfile might contain
//    --some_flag="This is a string containing a \" and a '."
//    --another_flag=wombats

#include <vector>

#include "tensorflow/compiler/xla/types.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/util/command_line_flags.h"

namespace xla {
namespace legacy_flags {

// Call tensorflow::Flags::Parse(argc, argv, flag_list) against any as yet
// unrecognized flags passed in from the environment, and return its
// return value.
bool ParseFlagsFromEnv(const std::vector<tensorflow::Flag>& flag_list);

// Used only for testing.  Not to be used by clients.
void ResetFlagsFromEnvForTesting(int** pargc, std::vector<char*>** pargv);

}  // namespace legacy_flags
}  // namespace xla

#endif  // TENSORFLOW_COMPILER_XLA_LEGACY_FLAGS_PARSE_FLAGS_FROM_ENV_H_