-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new abstraction for build output groups.
Use an enum with values for each output group that the `build_dependencies.bzl` aspect can produce. Use the enum values both when requesting output groups in the build invocation, and when handing them after the fact. Add a new `OutputGroupArtifacts` class to do this.i Derive the set of output groups required from the language classes of the build targets we're building in `DependencyTracker`. This makes adding new output groups easier, whcih will help when adding C++ support as that will require more than one new output group from the build. PiperOrigin-RevId: 569116586
- Loading branch information
1 parent
85e1a12
commit 3fd5d6e
Showing
11 changed files
with
205 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
base/src/com/google/idea/blaze/base/qsync/OutputGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.base.qsync; | ||
|
||
/** Represents an output group produced by the {@code build_dependencies.bzl} aspect. */ | ||
public enum OutputGroup { | ||
JARS("qsync_jars"), | ||
AARS("qsync_aars"), | ||
GENSRCS("qsync_gensrcs"), | ||
ARTIFACT_INFO_FILE("artifact_info_file"); | ||
|
||
private final String name; | ||
|
||
OutputGroup(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String outputGroupName() { | ||
return name; | ||
} | ||
|
||
public String asBuildFlag() { | ||
return "--output_groups=" + outputGroupName(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
base/src/com/google/idea/blaze/base/qsync/OutputGroupArtifacts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2023 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.base.qsync; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableListMultimap; | ||
import com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact; | ||
import com.google.idea.blaze.base.command.buildresult.OutputArtifact; | ||
import com.google.idea.blaze.base.command.buildresult.RemoteOutputArtifact; | ||
import com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs; | ||
import java.io.File; | ||
import java.util.Set; | ||
|
||
/** Output artifacts from the build per {@link OutputGroup}. */ | ||
public class OutputGroupArtifacts { | ||
|
||
public static final OutputGroupArtifacts EMPTY = new OutputGroupArtifacts(); | ||
|
||
private final ImmutableListMultimap<OutputGroup, OutputArtifact> outputArtifacts; | ||
|
||
private OutputGroupArtifacts() { | ||
outputArtifacts = ImmutableListMultimap.of(); | ||
} | ||
|
||
@VisibleForTesting | ||
public OutputGroupArtifacts(ImmutableListMultimap<OutputGroup, OutputArtifact> map) { | ||
this.outputArtifacts = map; | ||
} | ||
|
||
public OutputGroupArtifacts(BlazeBuildOutputs buildOutputs, Set<OutputGroup> outputGroups) { | ||
ImmutableListMultimap.Builder<OutputGroup, OutputArtifact> builder = | ||
ImmutableListMultimap.builder(); | ||
for (OutputGroup group : outputGroups) { | ||
ImmutableList<OutputArtifact> artifacts = | ||
translateOutputArtifacts( | ||
buildOutputs.getOutputGroupArtifacts(group.outputGroupName()::equals)); | ||
builder.putAll(group, artifacts); | ||
} | ||
outputArtifacts = builder.build(); | ||
} | ||
|
||
public ImmutableList<OutputArtifact> get(OutputGroup group) { | ||
return outputArtifacts.get(group); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return outputArtifacts.isEmpty(); | ||
} | ||
|
||
private static ImmutableList<OutputArtifact> translateOutputArtifacts( | ||
ImmutableList<OutputArtifact> artifacts) { | ||
return artifacts.stream() | ||
.map(OutputGroupArtifacts::translateOutputArtifact) | ||
.collect(ImmutableList.toImmutableList()); | ||
} | ||
|
||
private static OutputArtifact translateOutputArtifact(OutputArtifact it) { | ||
if (!(it instanceof RemoteOutputArtifact)) { | ||
return it; | ||
} | ||
RemoteOutputArtifact remoteOutputArtifact = (RemoteOutputArtifact) it; | ||
String hashId = remoteOutputArtifact.getHashId(); | ||
if (!(hashId.startsWith("/google_src") || hashId.startsWith("/google/src"))) { | ||
return it; | ||
} | ||
File srcfsArtifact = new File(hashId.replaceFirst("/google_src", "/google/src")); | ||
return new LocalFileOutputArtifact( | ||
srcfsArtifact, it.getRelativePath(), it.getConfigurationMnemonic(), it.getDigest()); | ||
} | ||
} |
Oops, something went wrong.