Skip to content

Commit

Permalink
Add Blaze User Setting for FastBuild Java Binary Path (#6431)
Browse files Browse the repository at this point in the history
* Blaze Fast Build Updates

* Add Blazer User Setting for FastBuild Java Binary Path

* remove extra space from formatting

* remove extra space from formatting

* update java doc on getStandardJavaBinary method
  • Loading branch information
dtaveras authored Jun 6, 2024
1 parent 6850b2c commit 82e447d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public String toString() {
private static final String DEFAULT_BLAZE_PATH = "blaze";
private static final String DEFAULT_BAZEL_PATH = "bazel";
private static final String DEFAULT_BUILDIFIER_PATH = "buildifier";
private static final String DEFAULT_FAST_BUILD_JAVA_BINARY_PATH_IN_RUN_FILES = "";

private FocusBehavior showBlazeConsoleOnSync = FocusBehavior.ALWAYS;
private FocusBehavior showBlazeProblemsViewOnSync = FocusBehavior.ALWAYS;
Expand All @@ -81,6 +82,7 @@ public String toString() {
private String blazeBinaryPath = DEFAULT_BLAZE_PATH;
private String bazelBinaryPath = DEFAULT_BAZEL_PATH;
private String buildifierBinaryPath = DEFAULT_BUILDIFIER_PATH;
private String fastBuildJavaBinaryPathInRunFiles = "";

public static BlazeUserSettings getInstance() {
return ServiceManager.getService(BlazeUserSettings.class);
Expand Down Expand Up @@ -170,6 +172,16 @@ public boolean isDefaultBlazePath() {
|| OLD_DEFAULT_BLAZE_PATH.equals(getBlazeBinaryPath());
}

public String getFastBuildJavaBinaryPathInRunFiles() {
return StringUtil.defaultIfEmpty(fastBuildJavaBinaryPathInRunFiles,
DEFAULT_FAST_BUILD_JAVA_BINARY_PATH_IN_RUN_FILES).trim();
}

public void setFastBuildJavaBinaryPathInRunFiles(String javaRunFilesBinaryPath) {
this.fastBuildJavaBinaryPathInRunFiles = StringUtil.defaultIfEmpty(javaRunFilesBinaryPath,
DEFAULT_FAST_BUILD_JAVA_BINARY_PATH_IN_RUN_FILES).trim();
}

public String getBuildifierBinaryPath() {
return StringUtil.defaultIfEmpty(buildifierBinaryPath, DEFAULT_BUILDIFIER_PATH).trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import com.google.idea.common.settings.ConfigurableSetting;
import com.google.idea.common.settings.ConfigurableSetting.ComponentFactory;
import com.google.idea.common.settings.SearchableText;
import com.google.idea.common.settings.SettingComponent;
import com.google.idea.common.settings.SettingComponent.LabeledComponent;
import com.google.idea.common.settings.SettingComponent.SimpleComponent;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.TextFieldWithStoredHistory;
import com.intellij.ui.components.JBLabel;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
Expand Down Expand Up @@ -150,6 +152,16 @@ public ImmutableCollection<SearchableText> getSearchableText() {
.componentFactory(
fileSelector(BUILDIFIER_BINARY_PATH_KEY, "Specify the buildifier binary path"));

public static final String FAST_BUILD_JAVA_BINARY_PATH_IN_RUN_FILES_KEY = "java.runfiles.binary.path";
private static final ConfigurableSetting<?, ?> FAST_BUILD_JAVA_IN_RUN_FILES_BINARY_PATH =
setting("FastBuild Java binary location in runfiles dir")
.getter(BlazeUserSettings::getFastBuildJavaBinaryPathInRunFiles)
.setter(BlazeUserSettings::setFastBuildJavaBinaryPathInRunFiles)
.componentFactory(SettingComponent.LabeledComponent.factory(
() -> new TextFieldWithStoredHistory(FAST_BUILD_JAVA_BINARY_PATH_IN_RUN_FILES_KEY),
s -> Strings.nullToEmpty(s.getText()).trim(),
TextFieldWithStoredHistory::setTextAndAddToHistory));

private static final ImmutableList<ConfigurableSetting<?, ?>> SETTINGS =
ImmutableList.of(
SHOW_CONSOLE_ON_SYNC,
Expand All @@ -163,14 +175,15 @@ public ImmutableCollection<SearchableText> getSearchableText() {
ALWAYS_SELECT_NEWEST_CHILD_TASK,
BLAZE_BINARY_PATH,
BAZEL_BINARY_PATH,
BUILDIFIER_BINARY_PATH);
BUILDIFIER_BINARY_PATH,
FAST_BUILD_JAVA_IN_RUN_FILES_BINARY_PATH);

private static ConfigurableSetting.Builder<BlazeUserSettings> setting(String label) {
return ConfigurableSetting.builder(BlazeUserSettings::getInstance).label(label);
}

private static ComponentFactory<LabeledComponent<String, FileSelectorWithStoredHistory>>
fileSelector(String historyKey, String title) {
fileSelector(String historyKey, String title) {
return LabeledComponent.factory(
() -> FileSelectorWithStoredHistory.create(historyKey, title),
s -> Strings.nullToEmpty(s.getText()).trim(),
Expand All @@ -193,7 +206,8 @@ public JComponent createComponent() {
ALWAYS_SELECT_NEWEST_CHILD_TASK,
BLAZE_BINARY_PATH,
BAZEL_BINARY_PATH,
BUILDIFIER_BINARY_PATH));
BUILDIFIER_BINARY_PATH,
FAST_BUILD_JAVA_IN_RUN_FILES_BINARY_PATH));
}

private JComponent getFocusBehaviorSettingsUi() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

import com.google.common.collect.ImmutableSet;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.settings.BlazeUserSettings;
import com.google.idea.blaze.base.settings.BuildSystemName;
import com.intellij.openapi.project.Project;
import java.io.File;
import javax.annotation.Nullable;
import java.io.File;

final class BazelFastBuildTestEnvironmentCreator extends FastBuildTestEnvironmentCreator {

Expand Down Expand Up @@ -67,6 +68,8 @@ private static boolean isDefaultLauncher(Label label) {
* <p>Bazel adds the Java launcher to the runfiles path when building a Java test target. If
* `bzlmod` is enabled, the directory name is formatted as
* 'rules_java~{RULES_JAVA_VERSION}~toolchains~local_jdk' otherwise it is `local_jdk`.
* If the user setting `java.runfiles.binary.path` is specified it will take precedence
* over `local_jdk`.
*/
private static File getStandardJavaBinary(String runfilesPath) {
for (File file :
Expand All @@ -76,6 +79,12 @@ private static File getStandardJavaBinary(String runfilesPath) {
return file.toPath().resolve("bin/java").toFile();
}
}

String javaBinaryPath = BlazeUserSettings.getInstance().getFastBuildJavaBinaryPathInRunFiles();
if (javaBinaryPath != null && !javaBinaryPath.isBlank()) {
return new File("../").toPath().resolve(javaBinaryPath).toFile();
}

return STANDARD_JAVA_BINARY;
}

Expand Down

0 comments on commit 82e447d

Please sign in to comment.