blob: 8237e8408f4e0056aed35f97a727059c5f854b10 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
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
15package com.google.devtools.build.lib.pkgcache;
16
Lukacs Berki50a705c2015-09-16 10:08:55 +000017import com.google.common.base.Splitter;
18import com.google.common.base.Strings;
19import com.google.common.collect.ImmutableList;
Brian Silvermand7d6d622016-03-17 09:53:39 +000020import com.google.common.collect.ImmutableSet;
Lukacs Berki50a705c2015-09-16 10:08:55 +000021import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
Kristina Chodorow73fa2032015-08-28 17:57:46 +000022import com.google.devtools.build.lib.cmdline.PackageIdentifier;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010023import com.google.devtools.build.lib.packages.ConstantRuleVisibility;
24import com.google.devtools.build.lib.packages.RuleVisibility;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010025import com.google.devtools.common.options.Converter;
26import com.google.devtools.common.options.Converters;
27import com.google.devtools.common.options.Option;
28import com.google.devtools.common.options.OptionsBase;
29import com.google.devtools.common.options.OptionsParsingException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010030import java.util.List;
31
32/**
33 * Options for configuring the PackageCache.
34 */
35public class PackageCacheOptions extends OptionsBase {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010036
37 /**
38 * Converter for the {@code --default_visibility} option.
39 */
40 public static class DefaultVisibilityConverter implements Converter<RuleVisibility> {
41 @Override
42 public RuleVisibility convert(String input) throws OptionsParsingException {
43 if (input.equals("public")) {
44 return ConstantRuleVisibility.PUBLIC;
45 } else if (input.equals("private")) {
46 return ConstantRuleVisibility.PRIVATE;
47 } else {
48 throw new OptionsParsingException("Not a valid default visibility: '" + input
49 + "' (should be 'public' or 'private'");
50 }
51 }
52
53 @Override
54 public String getTypeDescription() {
55 return "default visibility";
56 }
57 }
58
59 @Option(name = "package_path",
Luis Fernando Pino Duque964712c02016-03-31 11:05:31 +000060 defaultValue = "%workspace%",
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010061 category = "package loading",
Luis Fernando Pino Duque964712c02016-03-31 11:05:31 +000062 converter = Converters.ColonSeparatedOptionListConverter.class,
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010063 help = "A colon-separated list of where to look for packages. "
64 + "Elements beginning with '%workspace%' are relative to the enclosing "
65 + "workspace. If omitted or empty, the default is the output of "
66 + "'blaze info default-package-path'.")
67 public List<String> packagePath;
68
69 @Option(name = "show_package_location",
70 defaultValue = "false",
71 category = "verbosity",
72 deprecationWarning = "This flag is no longer supported and will go away soon.",
73 help = "If enabled, causes Blaze to print the location on the --package_path "
74 + "from which each package was loaded.")
75 public boolean showPackageLocation;
76
77 @Option(name = "show_loading_progress",
78 defaultValue = "true",
79 category = "verbosity",
80 help = "If enabled, causes Blaze to print \"Loading package:\" messages.")
81 public boolean showLoadingProgress;
82
83 @Option(name = "deleted_packages",
84 defaultValue = "",
85 category = "package loading",
86 converter = CommaSeparatedPackageNameListConverter.class,
87 help = "A comma-separated list of names of packages which the "
88 + "build system will consider non-existent, even if they are "
89 + "visible somewhere on the package path."
90 + "\n"
91 + "Use this option when deleting a subpackage 'x/y' of an "
92 + "existing package 'x'. For example, after deleting x/y/BUILD "
93 + "in your client, the build system may complain if it "
94 + "encounters a label '//x:y/z' if that is still provided by another "
95 + "package_path entry. Specifying --deleted_packages x/y avoids this "
96 + "problem.")
Lukacs Berki33aa1e12015-07-08 08:11:30 +000097 public List<PackageIdentifier> deletedPackages;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010098
99 @Option(name = "default_visibility",
100 defaultValue = "private",
101 category = "undocumented",
102 converter = DefaultVisibilityConverter.class,
103 help = "Default visibility for packages that don't set it explicitly ('public' or "
104 + "'private').")
105 public RuleVisibility defaultVisibility;
106
Eric Fellheimere6566da2015-05-21 23:42:17 +0000107 @Option(name = "legacy_globbing_threads",
108 defaultValue = "100",
109 category = "undocumented",
110 help = "Number of threads to use for glob evaluation.")
111 public int globbingThreads;
112
Janak Ramakrishnan930e89c2016-10-04 20:51:42 +0000113 @Option(
114 name = "experimental_max_directories_to_eagerly_visit_in_globbing",
115 defaultValue = "-1",
116 category = "undocumented",
117 help =
118 "If non-negative, the first time a glob is evaluated in a package, the subdirectories of "
119 + "the package will be traversed in order to warm filesystem caches and compensate for "
120 + "lack of parallelism in globbing. At most this many directories will be visited."
121 )
122 public int maxDirectoriesToEagerlyVisitInGlobbing;
123
Kristina Chodorow6cad14e2015-05-14 18:18:35 +0000124 @Option(name = "fetch",
125 defaultValue = "true",
126 category = "undocumented",
127 help = "Allows the command to fetch external dependencies")
128 public boolean fetch;
Lukacs Berki50a705c2015-09-16 10:08:55 +0000129
Nathan Harmata60108832016-03-25 08:02:42 +0000130 @Option(name = "experimental_check_output_files",
131 defaultValue = "true",
132 category = "undocumented",
133 help = "Check for modifications made to the output files of a build. Consider setting "
134 + "this flag to false to see the effect on incremental build times.")
135 public boolean checkOutputFiles;
136
Lukacs Berki50a705c2015-09-16 10:08:55 +0000137 /**
138 * A converter from strings containing comma-separated names of packages to lists of strings.
139 */
140 public static class CommaSeparatedPackageNameListConverter
141 implements Converter<List<PackageIdentifier>> {
142
143 private static final Splitter COMMA_SPLITTER = Splitter.on(',');
144
145 @Override
146 public List<PackageIdentifier> convert(String input) throws OptionsParsingException {
147 if (Strings.isNullOrEmpty(input)) {
148 return ImmutableList.of();
149 }
150 ImmutableList.Builder<PackageIdentifier> list = ImmutableList.builder();
151 for (String s : COMMA_SPLITTER.split(input)) {
152 try {
153 list.add(PackageIdentifier.parse(s));
154 } catch (LabelSyntaxException e) {
155 throw new OptionsParsingException(e.getMessage());
156 }
157 }
158 return list.build();
159 }
160
161 @Override
162 public String getTypeDescription() {
163 return "comma-separated list of package names";
164 }
165
166 }
Brian Silvermand7d6d622016-03-17 09:53:39 +0000167
168 public ImmutableSet<PackageIdentifier> getDeletedPackages() {
Janak Ramakrishnan464f1182016-11-14 23:12:12 +0000169 if (deletedPackages == null || deletedPackages.isEmpty()) {
Brian Silvermand7d6d622016-03-17 09:53:39 +0000170 return ImmutableSet.of();
171 }
172 ImmutableSet.Builder<PackageIdentifier> newDeletedPackages = ImmutableSet.builder();
173 for (PackageIdentifier pkg : deletedPackages) {
174 newDeletedPackages.add(pkg.makeAbsolute());
175 }
176 return newDeletedPackages.build();
177 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100178}