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.testutil; |
| 16 | |
| 17 | import com.google.common.collect.ImmutableList; |
| 18 | import com.google.devtools.build.lib.actions.Artifact; |
| 19 | import com.google.devtools.build.lib.actions.FailAction; |
| 20 | import com.google.devtools.build.lib.analysis.ConfiguredTarget; |
| 21 | import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; |
ulfjack | 26d0e49 | 2017-08-07 13:42:33 +0200 | [diff] [blame] | 22 | import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.devtools.build.lib.analysis.RuleContext; |
| 24 | import com.google.devtools.build.lib.analysis.Runfiles; |
| 25 | import com.google.devtools.build.lib.analysis.RunfilesProvider; |
| 26 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
| 27 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
| 28 | import com.google.devtools.build.lib.collect.nestedset.Order; |
| 29 | import com.google.devtools.build.lib.packages.Rule; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * A null implementation of ConfiguredTarget for rules we don't know how to build. |
| 33 | */ |
| 34 | public class UnknownRuleConfiguredTarget implements RuleConfiguredTargetFactory { |
| 35 | |
| 36 | @Override |
| 37 | public ConfiguredTarget create(RuleContext context) { |
| 38 | // TODO(bazel-team): (2009) why isn't this an error? It would stop the build more promptly... |
| 39 | context.ruleWarning("cannot build " + context.getRule().getRuleClass() + " rules"); |
| 40 | |
| 41 | ImmutableList<Artifact> outputArtifacts = context.getOutputArtifacts(); |
| 42 | NestedSet<Artifact> filesToBuild; |
| 43 | if (outputArtifacts.isEmpty()) { |
| 44 | // Gotta build *something*... |
| 45 | filesToBuild = NestedSetBuilder.create(Order.STABLE_ORDER, |
| 46 | context.createOutputArtifact()); |
| 47 | } else { |
| 48 | filesToBuild = NestedSetBuilder.wrap(Order.STABLE_ORDER, outputArtifacts); |
| 49 | } |
| 50 | |
| 51 | Rule rule = context.getRule(); |
| 52 | context.registerAction(new FailAction(context.getActionOwner(), |
| 53 | filesToBuild, "cannot build " + rule.getRuleClass() + " rules such as " + rule.getLabel())); |
| 54 | return new RuleConfiguredTargetBuilder(context) |
| 55 | .setFilesToBuild(filesToBuild) |
| 56 | .add(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY)) |
| 57 | .build(); |
| 58 | } |
| 59 | } |