Skip to content

Commit

Permalink
chore: Aspect templating - 2/n (bazelbuild#6815)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Pasternak authored Sep 30, 2024
1 parent e874bd1 commit fb3abba
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public abstract ListenableFuture<ExternalWorkspaceData> dumpRepoMapping(
BuildSystemName buildSystemName,
List<String> flags);

public abstract ListenableFuture<String> getDeps(
Project project,
BuildInvoker invoker,
BlazeContext context,
BuildSystemName buildSystemName,
List<String> flags);

/**
* @param args The arguments passed into `blaze mod ...`
* @param flags The blaze flags that will be passed to {@code blaze ...}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public class BlazeModRunnerImpl extends BlazeModRunner {

private static final String DUMP_REPO_MAPPING = "dump_repo_mapping";
private static final String DEPS = "deps";
private static final String ROOT_WORKSPACE = "";

/**
Expand Down Expand Up @@ -82,6 +83,26 @@ public ListenableFuture<ExternalWorkspaceData> dumpRepoMapping(
BlazeExecutor.getInstance().getExecutor());
}

@Override
public ListenableFuture<String> getDeps(
Project project,
BuildSystem.BuildInvoker invoker,
BlazeContext context,
BuildSystemName buildSystemName,
List<String> flags) {

// TODO: when 8.0.0 is released add this only if it's disabled explicitly for the repo
flags.add("--noenable_workspace");

return Futures.transform(
runBlazeModGetBytes(
project, invoker, context, ImmutableList.of(DEPS, ROOT_WORKSPACE, "--output=json"), flags),
bytes -> new String(bytes, StandardCharsets.UTF_8),
BlazeExecutor.getInstance().getExecutor()
);

}

@Override
protected ListenableFuture<byte[]> runBlazeModGetBytes(
Project project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ExternalWorkspaceDataProvider {
private final Project project;

private volatile ExternalWorkspaceData externalWorkspaceData;
private ListenableFuture<String> deps;

public ExternalWorkspaceDataProvider(Project project) {
this.project = project;
Expand Down Expand Up @@ -104,11 +105,13 @@ public ListenableFuture<ExternalWorkspaceData> getExternalWorkspaceData(
.getBuildSystem()
.getDefaultInvoker(project, context);

deps = BlazeModRunner.getInstance().getDeps(project, buildInvoker, context, importSettings.getBuildSystem(), blazeFlags);
externalWorkspaceData =
BlazeModRunner.getInstance()
.dumpRepoMapping(
project, buildInvoker, context, importSettings.getBuildSystem(), blazeFlags)
.get();
deps.get();
} catch (InterruptedException | ExecutionException e) {
context.handleExceptionAsWarning(
"Failed to run `blaze mod dump_repo_mapping` (completion of labels from module provided repos will be unavailable)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ public ListenableFuture<ExternalWorkspaceData> dumpRepoMapping(
return Futures.immediateFuture(ExternalWorkspaceData.EMPTY);
}

@Override
public ListenableFuture<String> getDeps(Project project, BuildInvoker invoker, BlazeContext context, BuildSystemName buildSystemName, List<String> flags) {
return Futures.immediateFuture(null);
}

@Override
protected ListenableFuture<byte[]> runBlazeModGetBytes(
Project project,
Expand Down

0 comments on commit fb3abba

Please sign in to comment.