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 | |
Lukacs Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 17 | import com.google.common.base.Splitter; |
| 18 | import com.google.common.base.Strings; |
| 19 | import com.google.common.collect.ImmutableList; |
Brian Silverman | d7d6d62 | 2016-03-17 09:53:39 +0000 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
Lukacs Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 21 | import com.google.devtools.build.lib.cmdline.LabelSyntaxException; |
Kristina Chodorow | 73fa203 | 2015-08-28 17:57:46 +0000 | [diff] [blame] | 22 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.devtools.build.lib.packages.ConstantRuleVisibility; |
| 24 | import com.google.devtools.build.lib.packages.RuleVisibility; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 25 | import com.google.devtools.common.options.Converter; |
| 26 | import com.google.devtools.common.options.Converters; |
| 27 | import com.google.devtools.common.options.Option; |
| 28 | import com.google.devtools.common.options.OptionsBase; |
| 29 | import com.google.devtools.common.options.OptionsParsingException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | import java.util.List; |
| 31 | |
| 32 | /** |
| 33 | * Options for configuring the PackageCache. |
| 34 | */ |
| 35 | public class PackageCacheOptions extends OptionsBase { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 36 | |
| 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 Duque | 964712c0 | 2016-03-31 11:05:31 +0000 | [diff] [blame] | 60 | defaultValue = "%workspace%", |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 61 | category = "package loading", |
Luis Fernando Pino Duque | 964712c0 | 2016-03-31 11:05:31 +0000 | [diff] [blame] | 62 | converter = Converters.ColonSeparatedOptionListConverter.class, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | 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 Berki | 33aa1e1 | 2015-07-08 08:11:30 +0000 | [diff] [blame] | 97 | public List<PackageIdentifier> deletedPackages; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 98 | |
| 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 Fellheimer | e6566da | 2015-05-21 23:42:17 +0000 | [diff] [blame] | 107 | @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 Ramakrishnan | 930e89c | 2016-10-04 20:51:42 +0000 | [diff] [blame] | 113 | @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 Chodorow | 6cad14e | 2015-05-14 18:18:35 +0000 | [diff] [blame] | 124 | @Option(name = "fetch", |
| 125 | defaultValue = "true", |
| 126 | category = "undocumented", |
| 127 | help = "Allows the command to fetch external dependencies") |
| 128 | public boolean fetch; |
Lukacs Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 129 | |
Nathan Harmata | 6010883 | 2016-03-25 08:02:42 +0000 | [diff] [blame] | 130 | @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 Berki | 50a705c | 2015-09-16 10:08:55 +0000 | [diff] [blame] | 137 | /** |
| 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 Silverman | d7d6d62 | 2016-03-17 09:53:39 +0000 | [diff] [blame] | 167 | |
| 168 | public ImmutableSet<PackageIdentifier> getDeletedPackages() { |
Janak Ramakrishnan | 464f118 | 2016-11-14 23:12:12 +0000 | [diff] [blame] | 169 | if (deletedPackages == null || deletedPackages.isEmpty()) { |
Brian Silverman | d7d6d62 | 2016-03-17 09:53:39 +0000 | [diff] [blame] | 170 | 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 178 | } |