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.analysis; |
| 16 | |
| 17 | import com.google.devtools.build.lib.actions.AbstractAction; |
| 18 | import com.google.devtools.build.lib.actions.ActionExecutionContext; |
| 19 | import com.google.devtools.build.lib.actions.ActionExecutionException; |
| 20 | import com.google.devtools.build.lib.actions.ActionOwner; |
| 21 | import com.google.devtools.build.lib.actions.Artifact; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | import com.google.devtools.build.lib.actions.extra.ExtraActionInfo; |
Laszlo Csomor | 91e3a14 | 2015-06-09 08:48:50 +0000 | [diff] [blame] | 23 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | import com.google.devtools.build.lib.util.Fingerprint; |
| 25 | import com.google.protobuf.GeneratedMessage.GeneratedExtension; |
| 26 | import com.google.protobuf.MessageLite; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 27 | import java.util.Collection; |
| 28 | import java.util.UUID; |
| 29 | |
| 30 | /** |
| 31 | * An action that is inserted into the build graph only to provide info |
| 32 | * about rules to extra_actions. |
| 33 | */ |
| 34 | public class PseudoAction<InfoType extends MessageLite> extends AbstractAction { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 35 | private final UUID uuid; |
| 36 | private final String mnemonic; |
| 37 | private final GeneratedExtension<ExtraActionInfo, InfoType> infoExtension; |
| 38 | private final InfoType info; |
| 39 | |
| 40 | public PseudoAction(UUID uuid, ActionOwner owner, |
Laszlo Csomor | 91e3a14 | 2015-06-09 08:48:50 +0000 | [diff] [blame] | 41 | NestedSet<Artifact> inputs, Collection<Artifact> outputs, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 42 | String mnemonic, |
| 43 | GeneratedExtension<ExtraActionInfo, InfoType> infoExtension, InfoType info) { |
| 44 | super(owner, inputs, outputs); |
| 45 | this.uuid = uuid; |
| 46 | this.mnemonic = mnemonic; |
| 47 | this.infoExtension = infoExtension; |
| 48 | this.info = info; |
| 49 | } |
| 50 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 51 | @Override |
| 52 | public void execute(ActionExecutionContext actionExecutionContext) |
| 53 | throws ActionExecutionException { |
| 54 | throw new ActionExecutionException( |
| 55 | mnemonic + "ExtraAction should not be executed.", this, false); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public String getMnemonic() { |
| 60 | return mnemonic; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | protected String computeKey() { |
| 65 | return new Fingerprint() |
| 66 | .addUUID(uuid) |
| 67 | .addBytes(info.toByteArray()) |
| 68 | .hexDigestAndReset(); |
| 69 | } |
| 70 | |
| 71 | @Override |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 72 | public ExtraActionInfo.Builder getExtraActionInfo() { |
| 73 | return super.getExtraActionInfo().setExtension(infoExtension, info); |
| 74 | } |
| 75 | |
| 76 | public static Artifact getDummyOutput(RuleContext ruleContext) { |
Lukacs Berki | 4a89a9b | 2015-07-29 06:54:07 +0000 | [diff] [blame] | 77 | return ruleContext.getPackageRelativeArtifact( |
| 78 | ruleContext.getLabel().getName() + ".extra_action_dummy", |
Kristina Chodorow | f8a1ae6 | 2016-08-11 14:44:40 +0000 | [diff] [blame] | 79 | ruleContext.getConfiguration().getGenfilesDirectory( |
| 80 | ruleContext.getRule().getRepository())); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 81 | } |
| 82 | } |