blob: 4b3f81e876b8be55f5421aebfc9842821538b84e [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.analysis;
16
17import com.google.devtools.build.lib.actions.AbstractAction;
18import com.google.devtools.build.lib.actions.ActionExecutionContext;
19import com.google.devtools.build.lib.actions.ActionExecutionException;
20import com.google.devtools.build.lib.actions.ActionOwner;
21import com.google.devtools.build.lib.actions.Artifact;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010022import com.google.devtools.build.lib.actions.extra.ExtraActionInfo;
Laszlo Csomor91e3a142015-06-09 08:48:50 +000023import com.google.devtools.build.lib.collect.nestedset.NestedSet;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010024import com.google.devtools.build.lib.util.Fingerprint;
25import com.google.protobuf.GeneratedMessage.GeneratedExtension;
26import com.google.protobuf.MessageLite;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010027import java.util.Collection;
28import 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 */
34public class PseudoAction<InfoType extends MessageLite> extends AbstractAction {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010035 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 Csomor91e3a142015-06-09 08:48:50 +000041 NestedSet<Artifact> inputs, Collection<Artifact> outputs,
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010042 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 Nienhuysd08b27f2015-02-25 16:45:20 +010051 @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 Nienhuysd08b27f2015-02-25 16:45:20 +010072 public ExtraActionInfo.Builder getExtraActionInfo() {
73 return super.getExtraActionInfo().setExtension(infoExtension, info);
74 }
75
76 public static Artifact getDummyOutput(RuleContext ruleContext) {
Lukacs Berki4a89a9b2015-07-29 06:54:07 +000077 return ruleContext.getPackageRelativeArtifact(
78 ruleContext.getLabel().getName() + ".extra_action_dummy",
Kristina Chodorowf8a1ae62016-08-11 14:44:40 +000079 ruleContext.getConfiguration().getGenfilesDirectory(
80 ruleContext.getRule().getRepository()));
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010081 }
82}