blob: 490db8aead01933ad9a3b2a39fa15c2660ad3616 [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.packages;
16
Lukacs Berki6e91eb92015-09-21 09:12:37 +000017import com.google.devtools.build.lib.cmdline.Label;
adonovanf5262c52020-04-02 09:25:14 -070018import com.google.devtools.build.lib.syntax.Location;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010019
20/**
21 * A generated file that is the output of a rule.
22 */
23public final class OutputFile extends FileTarget {
24
Dmitry Lomov5b1ce4d2018-05-30 04:34:08 -070025 /**
26 * A kind of output file.
27 *
28 * The FILESET kind is only supported for a non-open-sourced {@code fileset} rule.
29 */
30 public enum Kind {
31 FILE,
32 FILESET
33 }
34
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010035 private final Rule generatingRule;
Dmitry Lomov5b1ce4d2018-05-30 04:34:08 -070036 private final Kind kind;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010037
38 /**
39 * Constructs an output file with the given label, which must be in the given
40 * package.
41 */
Dmitry Lomov5b1ce4d2018-05-30 04:34:08 -070042 OutputFile(Package pkg, Label label,
43 Kind kind, Rule generatingRule) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010044 super(pkg, label);
Dmitry Lomov5b1ce4d2018-05-30 04:34:08 -070045 this.kind = kind;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010046 this.generatingRule = generatingRule;
47 }
48
49 @Override
50 public RuleVisibility getVisibility() {
51 return generatingRule.getVisibility();
52 }
53
Greg Estrena6c88962015-09-28 19:35:18 +000054 @Override
55 public boolean isConfigurable() {
56 return true;
57 }
58
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010059 /**
60 * Returns the rule which generates this output file.
61 */
62 public Rule getGeneratingRule() {
63 return generatingRule;
64 }
65
Dmitry Lomov5b1ce4d2018-05-30 04:34:08 -070066 /**
67 * Returns the kind of this output file.
68 */
69 public Kind getKind() {
70 return kind;
71 }
72
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010073 @Override
74 public String getTargetKind() {
Googlerb448eef2017-05-02 21:50:24 +020075 return targetKind();
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010076 }
77
78 @Override
79 public Rule getAssociatedRule() {
80 return getGeneratingRule();
81 }
82
83 @Override
84 public Location getLocation() {
85 return generatingRule.getLocation();
86 }
Googlerb448eef2017-05-02 21:50:24 +020087
88 /** Returns the target kind for all output files. */
89 public static String targetKind() {
90 return "generated file";
91 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010092}