Skip to content

Commit 13c0bae

Browse files
authored
Added configurability to the bazel query buildfiles parameter (#19)
1 parent 39af609 commit 13c0bae

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BazelQueryTargetDiscovery.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ public Collection<WorkspacePath> discoverPackages(BazelWorkspace bazelWorkspace,
4343
throws CoreException {
4444
var monitor = SubMonitor.convert(progress, 100);
4545

46+
// get buildfiles argument from projevt view
47+
var buildfile_query = bazelWorkspace.getBazelProjectView().targetDiscoverySettings().get("buildfile_query");
48+
if (buildfile_query == null || buildfile_query.isBlank()) {
49+
buildfile_query = "//...";
50+
}
51+
4652
// bazel query 'buildfiles(//...)' --output package
4753
Collection<String> labels = bazelWorkspace.getCommandExecutor()
4854
.runQueryWithoutLock(
4955
new BazelQueryForPackagesCommand(
5056
bazelWorkspace.getLocation().toPath(),
51-
"buildfiles(//...)",
57+
"buildfiles(" + buildfile_query + ")",
5258
true,
5359
"Querying for all available packages in workspace"));
5460

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/projectview/BazelProjectFileReader.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public void close() {
6666
final LinkedHashSet<Path> importingFiles = new LinkedHashSet<>();
6767
IPath bazelBinary;
6868
final LinkedHashMap<String, String> targetProvisioningSettings = new LinkedHashMap<>();
69+
final LinkedHashMap<String, String> targetDiscoverySettings = new LinkedHashMap<>();
6970
final LinkedHashMap<String, String> projectMappings = new LinkedHashMap<>();
7071
final LinkedHashSet<String> importPreferences = new LinkedHashSet<>();
7172
final LinkedHashSet<String> projectSettings = new LinkedHashSet<>();
@@ -136,6 +137,7 @@ public BazelProjectView build() throws IllegalStateException {
136137
bazelBinary,
137138
targetDiscoveryStrategy,
138139
targetProvisioningStrategy,
140+
targetDiscoverySettings,
139141
targetProvisioningSettings,
140142
projectMappings,
141143
preferencesToImport,
@@ -342,6 +344,18 @@ private void parseProjectFile(Path bazelProjectFile, BazelProjectViewBuilder bui
342344
}
343345
break;
344346
}
347+
case "target_discovery_settings": {
348+
// extension for BEF
349+
parseSectionBodyIntoList(rawSection).forEach(s -> {
350+
var separator = s.indexOf('=');
351+
if (separator != -1) {
352+
var key = s.substring(0, separator).trim();
353+
var value = s.substring(separator + 1).trim();
354+
builder.targetDiscoverySettings.put(key, value);
355+
}
356+
});
357+
break;
358+
}
345359
case "target_provisioning_settings": {
346360
// extension for BEF
347361
parseSectionBodyIntoList(rawSection).forEach(s -> {

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/projectview/BazelProjectView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public record BazelProjectView(
4040
IPath bazelBinary,
4141
String targetDiscoveryStrategy,
4242
String targetProvisioningStrategy,
43+
Map<String, String> targetDiscoverySettings,
4344
Map<String, String> targetProvisioningSettings,
4445
Map<String, String> projectMappings,
4546
Collection<WorkspacePath> importPreferences,
@@ -59,6 +60,7 @@ public record BazelProjectView(
5960
targets = unmodifiableCollection(targets);
6061
additionalLanguages = unmodifiableCollection(additionalLanguages);
6162
tsConfigRules = unmodifiableCollection(tsConfigRules);
63+
targetDiscoverySettings = Collections.unmodifiableMap(targetDiscoverySettings);
6264
targetProvisioningSettings = Collections.unmodifiableMap(targetProvisioningSettings);
6365
projectMappings = Collections.unmodifiableMap(projectMappings);
6466
importPreferences = unmodifiableCollection(importPreferences);

docs/common/projectviews.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ The syntax of each entry is `key=value`, where `key` and `value` are expected st
159159
* Providing a value greater then 0 will filter transitive dependencies and provide a partial classpath to the project model.
160160
* Note: While all required compile-time dependencies are added regardless, there may be edge cases with the Eclipse compiler which may result in compile errors.
161161

162+
### `target_discovery_settings`
163+
164+
* `buildfile_query` Specifies the Bazel query expression used to discover packages when `target_discovery_strategy` is set to `bazel-query` (default is `//...`).
165+
* This parameter is wrapped in a `buildfiles()` function during package discovery, e.g., `buildfiles(//...)`.
166+
* Example: Set to `//some/path/...` to limit package discovery to a specific directory tree.
167+
* Example: Set to `//module1/... + //module2/...` to discover packages from multiple specific paths.
168+
169+
162170
### `project_mappings`
163171

164172
A list of mappings from targets (typically from external repositories) to projects in the IDE.

0 commit comments

Comments
 (0)