Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1 | // Copyright 2014 Google Inc. All rights reserved. |
| 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.analysis; |
| 16 | |
| 17 | import com.google.devtools.build.lib.actions.Artifact; |
| 18 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
| 19 | import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; |
| 20 | import com.google.devtools.build.lib.syntax.Label; |
| 21 | import com.google.devtools.build.lib.syntax.SkylarkCallable; |
| 22 | import com.google.devtools.build.lib.syntax.SkylarkModule; |
| 23 | |
| 24 | import javax.annotation.Nullable; |
| 25 | |
| 26 | /** |
| 27 | * A representation of the concept "this transitive info provider builds these files". |
| 28 | * |
| 29 | * <p>Every transitive info collection contains at least this provider. |
| 30 | */ |
| 31 | @Immutable |
| 32 | @SkylarkModule(name = "file_provider", doc = "An interface for rules that provide files.") |
| 33 | public final class FileProvider implements TransitiveInfoProvider { |
| 34 | |
| 35 | @Nullable private final Label label; |
| 36 | private final NestedSet<Artifact> filesToBuild; |
| 37 | |
| 38 | public FileProvider(@Nullable Label label, NestedSet<Artifact> filesToBuild) { |
| 39 | this.label = label; |
| 40 | this.filesToBuild = filesToBuild; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the label that is associated with this piece of information. |
| 45 | * |
| 46 | * <p>This is usually the label of the target that provides the information. |
| 47 | */ |
| 48 | @SkylarkCallable(name = "label", doc = "", structField = true) |
| 49 | public Label getLabel() { |
| 50 | if (label == null) { |
| 51 | throw new UnsupportedOperationException(); |
| 52 | } |
| 53 | return label; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the set of artifacts that are the "output" of this rule. |
| 58 | * |
| 59 | * <p>The term "output" is somewhat hazily defined; it is vaguely the set of files that are |
| 60 | * passed on to dependent rules that list the rule in their {@code srcs} attribute and the |
| 61 | * set of files that are built when a rule is mentioned on the command line. It does |
| 62 | * <b>not</b> include the runfiles; that is the bailiwick of {@code FilesToRunProvider}. |
| 63 | * |
| 64 | * <p>Note that the above definition is somewhat imprecise; in particular, when a rule is |
| 65 | * mentioned on the command line, some other files are also built |
| 66 | * {@code TopLevelArtifactHelper} and dependent rules are free to filter this set of artifacts |
| 67 | * e.g. based on their extension. |
| 68 | * |
| 69 | * <p>Also, some rules may generate artifacts that are not listed here by way of defining other |
| 70 | * implicit targets, for example, deploy jars. |
| 71 | */ |
| 72 | @SkylarkCallable(name = "files_to_build", doc = "", structField = true) |
| 73 | public NestedSet<Artifact> getFilesToBuild() { |
| 74 | return filesToBuild; |
| 75 | } |
| 76 | } |