aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
blob: f42eb6fe8a1f50c288ed2b5820e59b044e3dfdbd (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Copyright 2014 Google Inc. 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.
package com.google.devtools.build.lib.runtime;

import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Converters;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParsingException;

import java.util.List;
import java.util.Map;
import java.util.logging.Level;

/**
 * Options common to all commands.
 */
public class CommonCommandOptions extends OptionsBase {
  /**
   * A class representing a blazerc option. blazeRc is serial number of the rc
   * file this option came from, option is the name of the option and value is
   * its value (or null if not specified).
   */
  public static class OptionOverride {
    final int blazeRc;
    final String command;
    final String option;

    public OptionOverride(int blazeRc, String command, String option) {
      this.blazeRc = blazeRc;
      this.command = command;
      this.option = option;
    }

    @Override
    public String toString() {
      return String.format("%d:%s=%s", blazeRc, command, option);
    }
  }

  /**
   * Converter for --default_override. The format is:
   * --default_override=blazerc:command=option.
   */
  public static class OptionOverrideConverter implements Converter<OptionOverride> {
    static final String ERROR_MESSAGE = "option overrides must be in form "
      + " rcfile:command=option, where rcfile is a nonzero integer";

    public OptionOverrideConverter() {}

    @Override
    public OptionOverride convert(String input) throws OptionsParsingException {
      int colonPos = input.indexOf(':');
      int assignmentPos = input.indexOf('=');

      if (colonPos < 0) {
        throw new OptionsParsingException(ERROR_MESSAGE);
      }

      if (assignmentPos <= colonPos + 1) {
        throw new OptionsParsingException(ERROR_MESSAGE);
      }

      int blazeRc;
      try {
        blazeRc = Integer.valueOf(input.substring(0, colonPos));
      } catch (NumberFormatException e) {
        throw new OptionsParsingException(ERROR_MESSAGE);
      }

      if (blazeRc < 0) {
        throw new OptionsParsingException(ERROR_MESSAGE);
      }

      String command = input.substring(colonPos + 1, assignmentPos);
      String option = input.substring(assignmentPos + 1);

      return new OptionOverride(blazeRc, command, option);
    }

    @Override
    public String getTypeDescription() {
      return "blazerc option override";
    }
  }


  @Option(name = "config",
          defaultValue = "",
          category = "misc",
          allowMultiple = true,
          help = "Selects additional config sections from the rc files; for every <command>, it "
              + "also pulls in the options from <command>:<config> if such a section exists; "
              + "if the section does not exist, this flag is ignored. "
              + "Note that it is currently only possible to provide these options on the "
              + "command line, not in the rc files. The config sections and flag combinations "
              + "they are equivalent to are located in the tools/*.blazerc config files.")
  public List<String> configs;

  @Option(name = "logging",
          defaultValue = "3", // Level.INFO
          category = "verbosity",
          converter = Converters.LogLevelConverter.class,
          help = "The logging level.")
  public Level verbosity;

  @Option(name = "client_env",
      defaultValue = "",
      category = "hidden",
      converter = Converters.AssignmentConverter.class,
      allowMultiple = true,
      help = "A system-generated parameter which specifies the client's environment")
  public List<Map.Entry<String, String>> clientEnv;

  @Option(name = "ignore_client_env",
      defaultValue = "false",
      category = "hidden",
      help = "If true, ignore the '--client_env' flag, and use the JVM environment instead")
  public boolean ignoreClientEnv;

  @Option(name = "client_cwd",
      defaultValue = "",
      category = "hidden",
      converter = OptionsUtils.PathFragmentConverter.class,
      help = "A system-generated parameter which specifies the client's working directory")
  public PathFragment clientCwd;

  @Option(name = "announce_rc",
      defaultValue = "false",
      category = "verbosity",
      help = "Whether to announce rc options.")
  public boolean announceRcOptions;

  /**
   * These are the actual default overrides.
   * Each value is a pair of (command name, value).
   *
   * For example: "--default_override=build=--cpu=piii"
   */
  @Option(name = "default_override",
      defaultValue = "",
      allowMultiple = true,
      category = "hidden",
      converter = OptionOverrideConverter.class,
      help = "")
  public List<OptionOverride> optionsOverrides;

  /**
   * This is the filename that the Blaze client parsed.
   */
  @Option(name = "rc_source",
      defaultValue = "",
      allowMultiple = true,
      category = "hidden",
      help = "")
  public List<String> rcSource;

  @Option(name = "always_profile_slow_operations",
      defaultValue = "true",
      category = "undocumented",
      help = "Whether profiling slow operations is always turned on")
  public boolean alwaysProfileSlowOperations;

  @Option(name = "profile",
      defaultValue = "null",
      category = "misc",
      converter = OptionsUtils.PathFragmentConverter.class,
      help = "If set, profile Blaze and write data to the specified "
      + "file. Use blaze analyze-profile to analyze the profile.")
  public PathFragment profilePath;

  @Option(name = "record_full_profiler_data",
      defaultValue = "false",
      category = "undocumented",
      help = "By default, Blaze profiler will record only aggregated data for fast but numerous "
          + "events (such as statting the file). If this option is enabled, profiler will record "
          + "each event - resulting in more precise profiling data but LARGE performance "
          + "hit. Option only has effect if --profile used as well.")
  public boolean recordFullProfilerData;

  @Option(name = "memory_profile",
      defaultValue = "null",
      category = "undocumented",
      converter = OptionsUtils.PathFragmentConverter.class,
      help = "If set, write memory usage data to the specified "
          + "file at phase ends.")
  public PathFragment memoryProfilePath;

  @Option(name = "gc_watchdog",
      defaultValue = "false",
      category = "undocumented",
      deprecationWarning = "Ignoring: this option is no longer supported",
      help = "Deprecated.")
  public boolean gcWatchdog;

  @Option(name = "startup_time",
      defaultValue = "0",
      category = "hidden",
      help = "The time in ms the launcher spends before sending the request to the blaze server.")
  public long startupTime;

  @Option(name = "extract_data_time",
      defaultValue = "0",
      category = "hidden",
      help = "The time spend on extracting the new blaze version.")
  public long extractDataTime;

  @Option(name = "command_wait_time",
      defaultValue = "0",
      category = "hidden",
      help = "The time in ms a command had to wait on a busy Blaze server process.")
  public long waitTime;

  @Option(name = "tool_tag",
      defaultValue = "",
      category = "misc",
      help = "A tool name to attribute this Blaze invocation to.")
  public String toolTag;

  @Option(name = "restart_reason",
      defaultValue = "no_restart",
      category = "hidden",
      help = "The reason for the server restart.")
  public String restartReason;

  @Option(name = "binary_path",
      defaultValue = "",
      category = "hidden",
      help = "The absolute path of the blaze binary.")
  public String binaryPath;

  @Option(name = "experimental_allow_project_files",
      defaultValue = "false",
      category = "hidden",
      help = "Enable processing of +<file> parameters.")
  public boolean allowProjectFiles;
}