Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues with aspect templates not available in query sync mode #7048

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,16 +140,16 @@ 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 isJavaEnabled = activeLanguages.contains(LanguageClass.JAVA) &&
(isQuerySync || (externalWorkspaceData != null && externalWorkspaceData.getByRepoName("rules_java") != null));
var isPythonEnabled = activeLanguages.contains(LanguageClass.PYTHON) &&
(isQuerySync || (externalWorkspaceData != null && externalWorkspaceData.getByRepoName("rules_python") != null));
var isAtLeastBazel8 = projectData.map(it -> it.getBlazeVersionData().bazelIsAtLeastVersion(8, 0, 0)).orElse(false);
return Map.of(
"bazel8OrAbove", isAtLeastBazel8 ? "true" : "false",
Expand Down
Loading