Skip to content

Commit

Permalink
V2024.11.19 hotfix (#7054)
Browse files Browse the repository at this point in the history
* fix issues with aspect templates not available in query sync mode (#7048)

* fix issues with aspect templates not available in query sync mode

* revise based on review

* fix: Don't require rules_java and rules_python for bazel 7 and older (#7052)

* doc: Update changelog

* Update CHANGELOG

---------

Co-authored-by: Jason Trinh <xuanson.trinh@jetbrains.com>
Co-authored-by: Mai Hussien <70515749+mai93@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent f31a104 commit 9970730
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v2024.11.19.0.2
===============
Fixes:
* Don't require rules_java and rules_python for bazel 7 and older (#7052)
* Fix issues with aspect templates not available in query sync mode (#7048)

v2024.11.19
===========
Features:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public void onSyncStart(Project project, BlazeContext context, SyncMode syncMode
prepareProjectAspect(project);
}

@Override
public void onQuerySyncStart(Project project, BlazeContext context) {
try {
prepareProjectAspect(project);
} catch (SyncFailedException e) {
throw new RuntimeException(e);
}
}

private void prepareProjectAspect(Project project) throws SyncFailedException {
var manager = BlazeProjectDataManager.getInstance(project);

Expand Down Expand Up @@ -112,7 +121,7 @@ private void writeLanguageInfos(
Path realizedAspectsPath,
File templateAspects,
Project project) throws SyncFailedException {
var templateLanguageStringMap = getLanguageStringMap(manager, project);
var templateLanguageStringMap = getLanguageStringMap(manager);
writeLanguageInfo(manager, realizedAspectsPath, templateAspects, TEMPLATE_JAVA, REALIZED_JAVA, templateLanguageStringMap);
writeLanguageInfo(manager, realizedAspectsPath, templateAspects, TEMPLATE_PYTHON, REALIZED_PYTHON, templateLanguageStringMap);
}
Expand All @@ -131,17 +140,17 @@ private void writeLanguageInfo(
}
}

private static @NotNull Map<String, String> getLanguageStringMap(BlazeProjectDataManager manager, Project project) {
var projectData = Optional.ofNullable(manager.getBlazeProjectData()); // It can be empty on intial sync. Fall back to no lauguage support
var blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
private static @NotNull Map<String, String> getLanguageStringMap(BlazeProjectDataManager manager) {
var projectData = Optional.ofNullable(manager.getBlazeProjectData()); // It can be empty on intial sync. Fall back to no language support
var activeLanguages = projectData.map(it -> it.getWorkspaceLanguageSettings().getActiveLanguages()).orElse(ImmutableSet.of());
var isJavaEnabled = activeLanguages.contains(LanguageClass.JAVA)
&& blazeProjectData != null
&& blazeProjectData.getExternalWorkspaceData().getByRepoName("rules_java") != null;
var isPythonEnabled = activeLanguages.contains(LanguageClass.PYTHON)
&& blazeProjectData != null
&& blazeProjectData.getExternalWorkspaceData().getByRepoName("rules_python") != null;
// TODO: adapt the logic to query sync
boolean isQuerySync = projectData.map(BlazeProjectData::isQuerySync).orElse(false);
var externalWorkspaceData = isQuerySync ? null : projectData.map(BlazeProjectData::getExternalWorkspaceData).orElse(null);
var isAtLeastBazel8 = projectData.map(it -> it.getBlazeVersionData().bazelIsAtLeastVersion(8, 0, 0)).orElse(false);
var isJavaEnabled = activeLanguages.contains(LanguageClass.JAVA) &&
(isQuerySync || (externalWorkspaceData != null && (!isAtLeastBazel8 || externalWorkspaceData.getByRepoName("rules_java") != null)));
var isPythonEnabled = activeLanguages.contains(LanguageClass.PYTHON) &&
(isQuerySync || (externalWorkspaceData != null && (!isAtLeastBazel8 || externalWorkspaceData.getByRepoName("rules_python") != null)));
return Map.of(
"bazel8OrAbove", isAtLeastBazel8 ? "true" : "false",
"isJavaEnabled", isJavaEnabled ? "true" : "false",
Expand Down

0 comments on commit 9970730

Please sign in to comment.