diff --git a/base/src/com/google/idea/blaze/base/projectview/section/sections/EnablePythonCodegenSupport.java b/base/src/com/google/idea/blaze/base/projectview/section/sections/EnablePythonCodegenSupport.java new file mode 100644 index 00000000000..e1097e0f04a --- /dev/null +++ b/base/src/com/google/idea/blaze/base/projectview/section/sections/EnablePythonCodegenSupport.java @@ -0,0 +1,32 @@ +/* + * Copyright 2024 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.base.projectview.section.sections; + +import com.google.idea.blaze.base.projectview.section.ScalarSection; +import com.google.idea.blaze.base.projectview.section.SectionKey; +import com.google.idea.blaze.base.projectview.section.SectionParser; + +public class EnablePythonCodegenSupport { + public static final SectionKey> KEY = + SectionKey.of("enable_python_codegen_support"); + public static final SectionParser PARSER = new BooleanSectionParser( + KEY, + """ + If set to true, enables Python codegen support. + More info here + """ + ); +} diff --git a/base/src/com/google/idea/blaze/base/projectview/section/sections/Sections.java b/base/src/com/google/idea/blaze/base/projectview/section/sections/Sections.java index 08a62870be6..f2822a39127 100644 --- a/base/src/com/google/idea/blaze/base/projectview/section/sections/Sections.java +++ b/base/src/com/google/idea/blaze/base/projectview/section/sections/Sections.java @@ -40,6 +40,7 @@ public class Sections { SyncFlagsSection.PARSER, TestFlagsSection.PARSER, ImportTargetOutputSection.PARSER, + EnablePythonCodegenSupport.PARSER, ExcludeTargetSection.PARSER, ExcludedSourceSection.PARSER, RunConfigurationsSection.PARSER, diff --git a/base/src/com/google/idea/blaze/base/sync/SyncProjectTargetsHelper.java b/base/src/com/google/idea/blaze/base/sync/SyncProjectTargetsHelper.java index 311a8990569..82600d55291 100644 --- a/base/src/com/google/idea/blaze/base/sync/SyncProjectTargetsHelper.java +++ b/base/src/com/google/idea/blaze/base/sync/SyncProjectTargetsHelper.java @@ -29,6 +29,7 @@ import com.google.idea.blaze.base.model.primitives.WorkspaceRoot; import com.google.idea.blaze.base.projectview.ProjectViewSet; import com.google.idea.blaze.base.projectview.section.sections.AutomaticallyDeriveTargetsSection; +import com.google.idea.blaze.base.projectview.section.sections.EnablePythonCodegenSupport; import com.google.idea.blaze.base.projectview.section.sections.SyncManualTargetsSection; import com.google.idea.blaze.base.projectview.section.sections.TargetSection; import com.google.idea.blaze.base.scope.BlazeContext; @@ -194,7 +195,7 @@ private static ImmutableList deriveTargetsFromDirectories( .filter(Objects::nonNull) .collect(Collectors.toSet()); - if (!activeLanguageCodeGeneratorTags.isEmpty()) { + if (!activeLanguageCodeGeneratorTags.isEmpty() && projectViewSet.getScalarValue(EnablePythonCodegenSupport.KEY).orElse(false)) { retainedByCodeGen = TargetTagFilter.filterCodeGen( project, context, diff --git a/base/tests/unittests/com/google/idea/blaze/base/projectview/ProjectViewSetTest.java b/base/tests/unittests/com/google/idea/blaze/base/projectview/ProjectViewSetTest.java index 6b97d9cf191..35b35beca67 100644 --- a/base/tests/unittests/com/google/idea/blaze/base/projectview/ProjectViewSetTest.java +++ b/base/tests/unittests/com/google/idea/blaze/base/projectview/ProjectViewSetTest.java @@ -38,6 +38,7 @@ import com.google.idea.blaze.base.projectview.section.sections.BuildFlagsSection; import com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry; import com.google.idea.blaze.base.projectview.section.sections.DirectorySection; +import com.google.idea.blaze.base.projectview.section.sections.EnablePythonCodegenSupport; import com.google.idea.blaze.base.projectview.section.sections.ExcludeTargetSection; import com.google.idea.blaze.base.projectview.section.sections.ExcludedSourceSection; import com.google.idea.blaze.base.projectview.section.sections.ImportSection; @@ -122,6 +123,7 @@ public void testProjectViewSetSerializable() { .set(new WorkspacePath("test"))) .add(ScalarSection.builder(UseExclusionPatternsSection.KEY).set(false)) .add(ScalarSection.builder(ViewProjectRootSection.KEY).set(false)) + .add(ScalarSection.builder(EnablePythonCodegenSupport.KEY).set(false)) .build()) .build(); diff --git a/examples/python/simple_code_generator/tools/intellij/.managed.bazelproject b/examples/python/simple_code_generator/tools/intellij/.managed.bazelproject new file mode 100644 index 00000000000..cf1bfbb1ffd --- /dev/null +++ b/examples/python/simple_code_generator/tools/intellij/.managed.bazelproject @@ -0,0 +1,9 @@ +directories: + . + +derive_targets_from_directories: true + +additional_languages: + python + +enable_python_codegen_support: true