Klaus Aehlig | c27b4da | 2017-09-01 10:33:22 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Bazel Authors. 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 | package com.google.devtools.build.lib.analysis; |
| 15 | |
| 16 | import com.google.common.collect.ImmutableList; |
| 17 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
| 18 | import com.google.devtools.build.lib.buildeventstream.BuildEvent; |
| 19 | import com.google.devtools.build.lib.buildeventstream.BuildEventConverters; |
| 20 | import com.google.devtools.build.lib.buildeventstream.BuildEventId; |
| 21 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; |
| 22 | import com.google.devtools.build.lib.buildeventstream.BuildEventWithConfiguration; |
| 23 | import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; |
| 24 | import com.google.devtools.build.lib.buildeventstream.NullConfiguration; |
| 25 | import com.google.devtools.build.lib.cmdline.Label; |
| 26 | import java.util.Collection; |
| 27 | |
| 28 | /** Event reporting about the configurations associated with a given apect for a target */ |
| 29 | public class AspectConfiguredEvent implements BuildEventWithConfiguration { |
| 30 | private final Label target; |
| 31 | private final String aspect; |
| 32 | private final Collection<BuildConfiguration> configurations; |
| 33 | |
| 34 | AspectConfiguredEvent( |
| 35 | Label target, String aspect, Collection<BuildConfiguration> configurations) { |
| 36 | this.configurations = configurations; |
| 37 | this.target = target; |
| 38 | this.aspect = aspect; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public Collection<BuildEvent> getConfigurations() { |
| 43 | ImmutableList.Builder<BuildEvent> builder = new ImmutableList.Builder<>(); |
| 44 | for (BuildConfiguration config : configurations) { |
| 45 | if (config != null) { |
| 46 | builder.add(config); |
| 47 | } else { |
| 48 | builder.add(new NullConfiguration()); |
| 49 | } |
| 50 | } |
| 51 | return builder.build(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public BuildEventId getEventId() { |
| 56 | return BuildEventId.aspectConfigured(target, aspect); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public Collection<BuildEventId> getChildrenEvents() { |
| 61 | ImmutableList.Builder childrenBuilder = ImmutableList.builder(); |
| 62 | for (BuildConfiguration config : configurations) { |
| 63 | if (config != null) { |
| 64 | childrenBuilder.add(BuildEventId.targetCompleted(target, config.getEventId())); |
| 65 | } else { |
| 66 | childrenBuilder.add( |
| 67 | BuildEventId.targetCompleted(target, BuildEventId.nullConfigurationId())); |
| 68 | } |
| 69 | } |
| 70 | return childrenBuilder.build(); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) { |
| 75 | BuildEventStreamProtos.TargetConfigured.Builder builder = |
| 76 | BuildEventStreamProtos.TargetConfigured.newBuilder(); |
| 77 | return GenericBuildEvent.protoChaining(this).setConfigured(builder.build()).build(); |
| 78 | } |
| 79 | } |