diff options
author | 2016-07-05 10:08:54 +0000 | |
---|---|---|
committer | 2016-07-05 10:27:50 +0000 | |
commit | 50681c1b6cca1856f5f7b401ee5c757f22aa2e54 (patch) | |
tree | fb9211bd4f1a7961f023ad0b885a25ff2b499455 /src/main/java/com/google/devtools/build | |
parent | c3112c2dea86cc64c6f68f4b7c9c620e014e620e (diff) |
Add allow_single_file in attr.label, deprecate single_file.
--
MOS_MIGRATED_REVID=126620866
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/Attribute.java | 3 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java | 75 |
2 files changed, 58 insertions, 20 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 5d4fe22386..c605964870 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -171,7 +171,8 @@ public final class Attribute implements Comparable<Attribute> { doc = "Declares how the configuration should change when following a dependency. " + "It can be either <a href=\"globals.html#DATA_CFG\">DATA_CFG</a> or " - + "<a href=\"globals.html#HOST_CFG\">HOST_CFG</a>.") + + "<a href=\"globals.html#HOST_CFG\">HOST_CFG</a>. " + + "This type is deprecated, use string \"host\" or \"data\" instead.") public enum ConfigurationTransition implements Transition { /** No transition, i.e., the same configuration as the current. */ NONE, diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java index b1e627de80..b966515082 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java @@ -115,6 +115,7 @@ public final class SkylarkAttr { + "automatically converted to a list containing one list of providers."; private static final String SINGLE_FILE_ARG = "single_file"; + private static final String ALLOW_SINGLE_FILE_ARG = "allow_single_file"; private static final String VALUES_ARG = "values"; private static final String VALUES_DOC = @@ -125,6 +126,27 @@ public final class SkylarkAttr { return arguments.containsKey(key) && arguments.get(key) != Runtime.NONE; } + private static void setAllowedFileTypes( + String attr, Object fileTypesObj, FuncallExpression ast, Attribute.Builder<?> builder) + throws EvalException { + if (fileTypesObj == Boolean.TRUE) { + builder.allowedFileTypes(FileTypeSet.ANY_FILE); + } else if (fileTypesObj == Boolean.FALSE) { + builder.allowedFileTypes(FileTypeSet.NO_FILE); + } else if (fileTypesObj instanceof SkylarkFileType) { + // TODO(laurentlb): deprecated, to be removed + builder.allowedFileTypes(((SkylarkFileType) fileTypesObj).getFileTypeSet()); + } else if (fileTypesObj instanceof SkylarkList) { + List<String> arg = + SkylarkList.castSkylarkListOrNoneToList( + fileTypesObj, String.class, "allow_files argument"); + builder.allowedFileTypes(FileType.of(arg)); + } else { + throw new EvalException( + ast.getLocation(), attr + " should be a boolean or a string list"); + } + } + private static Attribute.Builder<?> createAttribute( Type<?> type, SkylarkDict<String, Object> arguments, FuncallExpression ast, Environment env) throws EvalException, ConversionException { @@ -161,29 +183,30 @@ public final class SkylarkAttr { builder.setPropertyFlag("EXECUTABLE"); } + // TODO(laurentlb): Deprecated, remove in August 2016 (use allow_single_file). if (containsNonNoneKey(arguments, SINGLE_FILE_ARG) && (Boolean) arguments.get(SINGLE_FILE_ARG)) { + if (containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { + throw new EvalException( + ast.getLocation(), + "Cannot specify both single_file (deprecated) and allow_single_file"); + } builder.setPropertyFlag("SINGLE_ARTIFACT"); } + if (containsNonNoneKey(arguments, ALLOW_FILES_ARG) + && containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { + throw new EvalException( + ast.getLocation(), "Cannot specify both allow_files and allow_single_file"); + } + if (containsNonNoneKey(arguments, ALLOW_FILES_ARG)) { Object fileTypesObj = arguments.get(ALLOW_FILES_ARG); - if (fileTypesObj == Boolean.TRUE) { - builder.allowedFileTypes(FileTypeSet.ANY_FILE); - } else if (fileTypesObj == Boolean.FALSE) { - builder.allowedFileTypes(FileTypeSet.NO_FILE); - } else if (fileTypesObj instanceof SkylarkFileType) { - // TODO(laurentlb): deprecated, to be removed - builder.allowedFileTypes(((SkylarkFileType) fileTypesObj).getFileTypeSet()); - } else if (fileTypesObj instanceof SkylarkList) { - List<String> arg = - SkylarkList.castSkylarkListOrNoneToList( - fileTypesObj, String.class, "allow_files argument"); - builder.allowedFileTypes(FileType.of(arg)); - } else { - throw new EvalException( - ast.getLocation(), "allow_files should be a boolean or a string list"); - } + setAllowedFileTypes(ALLOW_FILES_ARG, fileTypesObj, ast, builder); + } else if (containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { + Object fileTypesObj = arguments.get(ALLOW_SINGLE_FILE_ARG); + setAllowedFileTypes(ALLOW_SINGLE_FILE_ARG, fileTypesObj, ast, builder); + builder.setPropertyFlag("SINGLE_ARTIFACT"); } else if (type.equals(BuildType.LABEL) || type.equals(BuildType.LABEL_LIST)) { builder.allowedFileTypes(FileTypeSet.NO_FILE); } @@ -441,12 +464,22 @@ public final class SkylarkAttr { ), @Param( name = ALLOW_FILES_ARG, - defaultValue = "False", + defaultValue = "None", named = true, positional = false, doc = ALLOW_FILES_DOC ), @Param( + name = ALLOW_SINGLE_FILE_ARG, + defaultValue = "None", + named = true, + positional = false, + doc = + "This is similar to <code>allow_files</code>, with the restriction that the label must " + + "correspond to a single <a href=\"file.html\">File</a>. " + + "Access it through <code>ctx.file.<attribute_name></code>." + ), + @Param( name = MANDATORY_ARG, type = Boolean.class, defaultValue = "False", @@ -479,7 +512,8 @@ public final class SkylarkAttr { named = true, positional = false, doc = - "if True, the label must correspond to a single <a href=\"file.html\">File</a>. " + "Deprecated: Use <code>allow_single_file</code> instead. " + + "If True, the label must correspond to a single <a href=\"file.html\">File</a>. " + "Access it through <code>ctx.file.<attribute_name></code>." ), @Param( @@ -501,6 +535,7 @@ public final class SkylarkAttr { Object defaultO, Boolean executable, Object allowFiles, + Object allowSingleFile, Boolean mandatory, SkylarkList<?> providers, Object allowRules, @@ -519,6 +554,8 @@ public final class SkylarkAttr { executable, ALLOW_FILES_ARG, allowFiles, + ALLOW_SINGLE_FILE_ARG, + allowSingleFile, MANDATORY_ARG, mandatory, PROVIDERS_ARG, @@ -653,7 +690,7 @@ public final class SkylarkAttr { ), @Param( name = ALLOW_FILES_ARG, // bool or FileType filter - defaultValue = "False", + defaultValue = "None", named = true, positional = false, doc = ALLOW_FILES_DOC |