Skip to content

Commit

Permalink
[Skymeld] Skip checking for external repos when it's clear that we do…
Browse files Browse the repository at this point in the history
…n't expect any.

This check is expensive as we have to cycle through all the Packages within the build. In some cases it's completely unnecessary since we don't expect any external repos.

PiperOrigin-RevId: 518820411
Change-Id: I1aa84e3561ccce10e886904d2da3df34b3475ce2
  • Loading branch information
joeleba authored and copybara-github committed Mar 23, 2023
1 parent a151696 commit cb55c5b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ public void prepareForExecution(UUID buildId)
singleSourceRoot,
env.getEventBus(),
env.getDirectories().getProductName() + "-",
request.getOptions(BuildLanguageOptions.class).experimentalSiblingRepositoryLayout);
request.getOptions(BuildLanguageOptions.class).experimentalSiblingRepositoryLayout,
runtime.getWorkspace().doesAllowExternalRepositories());
incrementalPackageRoots.eagerlyPlantSymlinksToSingleSourceRoot();

// We don't plant the symlinks via the subscribers of this ExecRootPreparedEvent, but rather
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public final class BlazeWorkspace {

private final String outputBaseFilesystemTypeName;

private final boolean allowExternalRepositories;

public BlazeWorkspace(
BlazeRuntime runtime,
BlazeDirectories directories,
Expand All @@ -85,7 +87,8 @@ public BlazeWorkspace(
WorkspaceStatusAction.Factory workspaceStatusActionFactory,
BinTools binTools,
@Nullable AllocationTracker allocationTracker,
SyscallCache syscallCache) {
SyscallCache syscallCache,
boolean allowExternalRepositories) {
this.runtime = runtime;
this.eventBusExceptionHandler = Preconditions.checkNotNull(eventBusExceptionHandler);
this.workspaceStatusActionFactory = workspaceStatusActionFactory;
Expand All @@ -96,6 +99,7 @@ public BlazeWorkspace(
this.skyframeExecutor = skyframeExecutor;
this.syscallCache = syscallCache;
this.quiescingExecutors = QuiescingExecutorsImpl.createDefault();
this.allowExternalRepositories = allowExternalRepositories;

if (directories.inWorkspace()) {
writeOutputBaseReadmeFile();
Expand Down Expand Up @@ -331,5 +335,9 @@ private void writeDoNotBuildHereFile() {
public AllocationTracker getAllocationTracker() {
return allocationTracker;
}

public boolean doesAllowExternalRepositories() {
return allowExternalRepositories;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public final class WorkspaceBuilder {
@Nullable private SkyframeExecutor.SkyKeyStateReceiver skyKeyStateReceiver = null;
private SyscallCache syscallCache;

private boolean allowExternalRepositories = true;

WorkspaceBuilder(BlazeDirectories directories, BinTools binTools) {
this.directories = directories;
this.binTools = binTools;
Expand Down Expand Up @@ -130,7 +132,8 @@ BlazeWorkspace build(
workspaceStatusActionFactory,
binTools,
allocationTracker,
singleFsSyscallCache);
singleFsSyscallCache,
allowExternalRepositories);
}

/**
Expand Down Expand Up @@ -212,6 +215,12 @@ public WorkspaceBuilder setSkyframeExecutorRepositoryHelpersHolder(
return this;
}

@CanIgnoreReturnValue
public WorkspaceBuilder setAllowExternalRepositories(boolean allowExternalRepositories) {
this.allowExternalRepositories = allowExternalRepositories;
return this;
}

@CanIgnoreReturnValue
public WorkspaceBuilder setSkyKeyStateReceiver(
SkyframeExecutor.SkyKeyStateReceiver skyKeyStateReceiver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,41 @@ public class IncrementalPackageRoots implements PackageRoots {
private final Root singleSourceRoot;
private final String prefix;
private final boolean useSiblingRepositoryLayout;

private final boolean allowExternalRepositories;
@Nullable private EventBus eventBus;

private IncrementalPackageRoots(
Path execroot,
Root singleSourceRoot,
EventBus eventBus,
String prefix,
boolean useSiblingRepositoryLayout) {
boolean useSiblingRepositoryLayout,
boolean allowExternalRepositories) {
this.threadSafeExternalRepoPackageRootsMap = Maps.newConcurrentMap();
this.execroot = execroot;
this.singleSourceRoot = singleSourceRoot;
this.prefix = prefix;
this.eventBus = eventBus;
this.useSiblingRepositoryLayout = useSiblingRepositoryLayout;
this.allowExternalRepositories = allowExternalRepositories;
}

public static IncrementalPackageRoots createAndRegisterToEventBus(
Path execroot,
Root singleSourceRoot,
EventBus eventBus,
String prefix,
boolean useSiblingRepositoryLayout) {
boolean useSiblingRepositoryLayout,
boolean allowExternalRepositories) {
IncrementalPackageRoots incrementalPackageRoots =
new IncrementalPackageRoots(
execroot, singleSourceRoot, eventBus, prefix, useSiblingRepositoryLayout);
execroot,
singleSourceRoot,
eventBus,
prefix,
useSiblingRepositoryLayout,
allowExternalRepositories);
eventBus.register(incrementalPackageRoots);
return incrementalPackageRoots;
}
Expand Down Expand Up @@ -120,7 +130,9 @@ public PackageRootLookup getPackageRootLookup() {
@Subscribe
public void topLevelTargetReadyForSymlinkPlanting(TopLevelTargetReadyForSymlinkPlanting event)
throws AbruptExitException {
registerAndPlantSymlinksForExternalPackages(event.transitivePackagesForSymlinkPlanting());
if (allowExternalRepositories) {
registerAndPlantSymlinksForExternalPackages(event.transitivePackagesForSymlinkPlanting());
}
}

@Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,13 @@ private void setupEnvironment(String rootDir) throws IOException, AbruptExitExce
new BlazeWorkspace(
blazeRuntime,
blazeDirectories,
null,
/* skyframeExecutor= */ null,
new RecordingExceptionHandler(),
null,
/* workspaceStatusActionFactory= */ null,
BinTools.forUnitTesting(blazeDirectories, ImmutableList.of()),
null,
null);
/* allocationTracker= */ null,
/* syscallCache= */ null,
/* allowExternalRepositories= */ true);
when(env.getBlazeWorkspace()).thenReturn(blazeWorkspace);
when(env.getDirectories()).thenReturn(blazeDirectories);
EventBus eventBus = new EventBus();
Expand Down

0 comments on commit cb55c5b

Please sign in to comment.