Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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 | package com.google.devtools.build.lib.pkgcache; |
| 16 | |
dbabkin | c885e28 | 2018-08-29 02:12:12 -0700 | [diff] [blame] | 17 | |
Lukacs Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 18 | import com.google.common.base.Splitter; |
| 19 | import com.google.common.base.Strings; |
| 20 | import com.google.common.collect.ImmutableList; |
Brian Silverman | d7d6d62 | 2016-03-17 09:53:39 +0000 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
jmmv | fd6f833 | 2020-03-30 13:35:18 -0700 | [diff] [blame] | 22 | import com.google.devtools.build.lib.actions.LocalHostCapacity; |
Lukacs Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 23 | import com.google.devtools.build.lib.cmdline.LabelSyntaxException; |
Kristina Chodorow | 73fa203 | 2015-08-28 17:57:46 +0000 | [diff] [blame] | 24 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 25 | import com.google.devtools.build.lib.packages.ConstantRuleVisibility; |
| 26 | import com.google.devtools.build.lib.packages.RuleVisibility; |
jmmv | fd6f833 | 2020-03-30 13:35:18 -0700 | [diff] [blame] | 27 | import com.google.devtools.build.lib.util.ResourceConverter; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | import com.google.devtools.common.options.Converter; |
| 29 | import com.google.devtools.common.options.Converters; |
| 30 | import com.google.devtools.common.options.Option; |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 31 | import com.google.devtools.common.options.OptionDocumentationCategory; |
ccalvarin | c82a197 | 2017-07-17 21:13:39 +0200 | [diff] [blame] | 32 | import com.google.devtools.common.options.OptionEffectTag; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 33 | import com.google.devtools.common.options.OptionsBase; |
| 34 | import com.google.devtools.common.options.OptionsParsingException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 35 | import java.util.List; |
| 36 | |
ajurkowski | d74b0ec | 2020-04-13 10:58:21 -0700 | [diff] [blame] | 37 | /** Options for configuring Packages -- loading and default behaviors. */ |
| 38 | public class PackageOptions extends OptionsBase { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Converter for the {@code --default_visibility} option. |
| 42 | */ |
| 43 | public static class DefaultVisibilityConverter implements Converter<RuleVisibility> { |
| 44 | @Override |
| 45 | public RuleVisibility convert(String input) throws OptionsParsingException { |
| 46 | if (input.equals("public")) { |
| 47 | return ConstantRuleVisibility.PUBLIC; |
| 48 | } else if (input.equals("private")) { |
| 49 | return ConstantRuleVisibility.PRIVATE; |
| 50 | } else { |
| 51 | throw new OptionsParsingException("Not a valid default visibility: '" + input |
| 52 | + "' (should be 'public' or 'private'"); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public String getTypeDescription() { |
| 58 | return "default visibility"; |
| 59 | } |
| 60 | } |
| 61 | |
jmmv | fd6f833 | 2020-03-30 13:35:18 -0700 | [diff] [blame] | 62 | /** Converter for globbing threads. */ |
| 63 | public static class ParallelismConverter extends ResourceConverter { |
| 64 | public ParallelismConverter() throws OptionsParsingException { |
| 65 | super( |
| 66 | /* autoSupplier= */ () -> |
| 67 | (int) Math.ceil(LocalHostCapacity.getLocalHostCapacity().getCpuUsage()), |
| 68 | /* minValue= */ 1, |
| 69 | /* maxValue= */ Integer.MAX_VALUE); |
| 70 | } |
| 71 | } |
| 72 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 73 | @Option( |
Dan Fabulich | 1d35ca0 | 2018-07-05 16:08:06 -0700 | [diff] [blame] | 74 | name = "package_path", |
| 75 | defaultValue = "%workspace%", |
| 76 | converter = Converters.ColonSeparatedOptionListConverter.class, |
| 77 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 78 | effectTags = {OptionEffectTag.UNKNOWN}, |
| 79 | help = |
| 80 | "A colon-separated list of where to look for packages. " |
| 81 | + "Elements beginning with '%workspace%' are relative to the enclosing " |
| 82 | + "workspace. If omitted or empty, the default is the output of " |
| 83 | + "'bazel info default-package-path'.") |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 84 | public List<String> packagePath; |
| 85 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 86 | @Option( |
Dan Fabulich | 1d35ca0 | 2018-07-05 16:08:06 -0700 | [diff] [blame] | 87 | name = "show_loading_progress", |
| 88 | defaultValue = "true", |
| 89 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 90 | effectTags = {OptionEffectTag.UNKNOWN}, |
| 91 | help = "If enabled, causes Bazel to print \"Loading package:\" messages.") |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 92 | public boolean showLoadingProgress; |
| 93 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 94 | @Option( |
| 95 | name = "deleted_packages", |
| 96 | defaultValue = "", |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 97 | converter = CommaSeparatedPackageNameListConverter.class, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 98 | documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, |
| 99 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 100 | help = |
| 101 | "A comma-separated list of names of packages which the " |
| 102 | + "build system will consider non-existent, even if they are " |
| 103 | + "visible somewhere on the package path.\n" |
| 104 | + "Use this option when deleting a subpackage 'x/y' of an " |
| 105 | + "existing package 'x'. For example, after deleting x/y/BUILD " |
| 106 | + "in your client, the build system may complain if it " |
| 107 | + "encounters a label '//x:y/z' if that is still provided by another " |
| 108 | + "package_path entry. Specifying --deleted_packages x/y avoids this " |
| 109 | + "problem." |
| 110 | ) |
Lukacs Berki | 33aa1e1 | 2015-07-08 08:11:30 +0000 | [diff] [blame] | 111 | public List<PackageIdentifier> deletedPackages; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 112 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 113 | @Option( |
| 114 | name = "default_visibility", |
| 115 | defaultValue = "private", |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 116 | converter = DefaultVisibilityConverter.class, |
ccalvarin | 456adb2 | 2017-07-11 14:23:46 +0200 | [diff] [blame] | 117 | documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 118 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 119 | help = |
| 120 | "Default visibility for packages that don't set it explicitly ('public' or " + "'private')." |
| 121 | ) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 122 | public RuleVisibility defaultVisibility; |
| 123 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 124 | @Option( |
jmmv | fd6f833 | 2020-03-30 13:35:18 -0700 | [diff] [blame] | 125 | name = "legacy_globbing_threads", |
| 126 | defaultValue = "100", |
| 127 | converter = ParallelismConverter.class, |
| 128 | documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, |
| 129 | effectTags = {OptionEffectTag.UNKNOWN}, |
| 130 | help = |
| 131 | "Number of threads to use for glob evaluation. Takes " |
| 132 | + ResourceConverter.FLAG_SYNTAX |
| 133 | + ". \"auto\" means to use a reasonable value derived from the machine's hardware" |
| 134 | + " profile (e.g. the number of processors).") |
Eric Fellheimer | e6566da | 2015-05-21 23:42:17 +0000 | [diff] [blame] | 135 | public int globbingThreads; |
| 136 | |
Janak Ramakrishnan | 930e89c | 2016-10-04 20:51:42 +0000 | [diff] [blame] | 137 | @Option( |
| 138 | name = "experimental_max_directories_to_eagerly_visit_in_globbing", |
| 139 | defaultValue = "-1", |
ccalvarin | 456adb2 | 2017-07-11 14:23:46 +0200 | [diff] [blame] | 140 | documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 141 | effectTags = {OptionEffectTag.UNKNOWN}, |
Janak Ramakrishnan | 930e89c | 2016-10-04 20:51:42 +0000 | [diff] [blame] | 142 | help = |
| 143 | "If non-negative, the first time a glob is evaluated in a package, the subdirectories of " |
| 144 | + "the package will be traversed in order to warm filesystem caches and compensate for " |
| 145 | + "lack of parallelism in globbing. At most this many directories will be visited." |
| 146 | ) |
| 147 | public int maxDirectoriesToEagerlyVisitInGlobbing; |
| 148 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 149 | @Option( |
| 150 | name = "fetch", |
| 151 | defaultValue = "true", |
ccalvarin | 456adb2 | 2017-07-11 14:23:46 +0200 | [diff] [blame] | 152 | documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 153 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 154 | help = "Allows the command to fetch external dependencies" |
| 155 | ) |
Kristina Chodorow | 6cad14e | 2015-05-14 18:18:35 +0000 | [diff] [blame] | 156 | public boolean fetch; |
Lukacs Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 157 | |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 158 | @Option( |
| 159 | name = "experimental_check_output_files", |
| 160 | defaultValue = "true", |
ccalvarin | 456adb2 | 2017-07-11 14:23:46 +0200 | [diff] [blame] | 161 | documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, |
ccalvarin | 3bc1547 | 2017-06-27 17:58:35 +0200 | [diff] [blame] | 162 | effectTags = {OptionEffectTag.UNKNOWN}, |
ccalvarin | 2eaa02e | 2017-04-17 23:37:46 +0200 | [diff] [blame] | 163 | help = |
| 164 | "Check for modifications made to the output files of a build. Consider setting " |
| 165 | + "this flag to false to see the effect on incremental build times." |
| 166 | ) |
Nathan Harmata | 6010883 | 2016-03-25 08:02:42 +0000 | [diff] [blame] | 167 | public boolean checkOutputFiles; |
| 168 | |
Lukacs Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 169 | /** |
| 170 | * A converter from strings containing comma-separated names of packages to lists of strings. |
| 171 | */ |
| 172 | public static class CommaSeparatedPackageNameListConverter |
| 173 | implements Converter<List<PackageIdentifier>> { |
| 174 | |
| 175 | private static final Splitter COMMA_SPLITTER = Splitter.on(','); |
| 176 | |
| 177 | @Override |
| 178 | public List<PackageIdentifier> convert(String input) throws OptionsParsingException { |
| 179 | if (Strings.isNullOrEmpty(input)) { |
| 180 | return ImmutableList.of(); |
| 181 | } |
| 182 | ImmutableList.Builder<PackageIdentifier> list = ImmutableList.builder(); |
| 183 | for (String s : COMMA_SPLITTER.split(input)) { |
| 184 | try { |
| 185 | list.add(PackageIdentifier.parse(s)); |
| 186 | } catch (LabelSyntaxException e) { |
| 187 | throw new OptionsParsingException(e.getMessage()); |
| 188 | } |
| 189 | } |
| 190 | return list.build(); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public String getTypeDescription() { |
| 195 | return "comma-separated list of package names"; |
| 196 | } |
| 197 | |
| 198 | } |
Brian Silverman | d7d6d62 | 2016-03-17 09:53:39 +0000 | [diff] [blame] | 199 | |
| 200 | public ImmutableSet<PackageIdentifier> getDeletedPackages() { |
Janak Ramakrishnan | 464f118 | 2016-11-14 23:12:12 +0000 | [diff] [blame] | 201 | if (deletedPackages == null || deletedPackages.isEmpty()) { |
Brian Silverman | d7d6d62 | 2016-03-17 09:53:39 +0000 | [diff] [blame] | 202 | return ImmutableSet.of(); |
| 203 | } |
| 204 | ImmutableSet.Builder<PackageIdentifier> newDeletedPackages = ImmutableSet.builder(); |
| 205 | for (PackageIdentifier pkg : deletedPackages) { |
| 206 | newDeletedPackages.add(pkg.makeAbsolute()); |
| 207 | } |
| 208 | return newDeletedPackages.build(); |
| 209 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 210 | } |