-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ignoring directories based on wildcards. (#24203)
This is accomplished by a new directive in REPO.bazel, "ignore_directories()". It takes a single argument, a list of directories to ignore and it allows the same wildcards as glob(). This is done separately from .bazelignore to provide a migration path off of that weird single-purpose configuration file. Implementing this requires splitting RepoFileFunction into two: a part that parses the repository file and one that creates a PackageArgs instance. This was necessary to avoid a Skyframe dependency cycle: when a WORKSPACE file is present and it loads a .bzl file from a repository with a REPO.bazel file, the repo mapping for the main repository depends on the WORKSPACE file, which depends on the .bzl file, which depends on the IgnoredPackagePrefixesValue of its repository, which then depends on the repo mapping of the main repository and the one the .bzl file is in, which then depend on the WORKSPACE file. Fixes #7093. RELNOTES[NEW]: REPO.bazel now allows another directive, "ignore_directories()". It takes a list of directories to ignore just like .bazelignore does, but with glob semantics. Closes #24032. PiperOrigin-RevId: 693227896 Change-Id: Ia3e02a2bfe9caf999fc641f75261b528b19c1d03
- Loading branch information
Showing
32 changed files
with
784 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
src/main/java/com/google/devtools/build/lib/packages/RepoCallable.java
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
src/main/java/com/google/devtools/build/lib/packages/RepoFileGlobals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2023 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.devtools.build.lib.packages; | ||
|
||
import java.util.Map; | ||
import net.starlark.java.annot.Param; | ||
import net.starlark.java.annot.ParamType; | ||
import net.starlark.java.annot.StarlarkMethod; | ||
import net.starlark.java.eval.EvalException; | ||
import net.starlark.java.eval.Sequence; | ||
import net.starlark.java.eval.Starlark; | ||
import net.starlark.java.eval.StarlarkThread; | ||
|
||
/** Definition of the {@code repo()} function used in REPO.bazel files. */ | ||
public final class RepoFileGlobals { | ||
private RepoFileGlobals() {} | ||
|
||
public static final RepoFileGlobals INSTANCE = new RepoFileGlobals(); | ||
|
||
@StarlarkMethod( | ||
name = "ignore_directories", | ||
doc = | ||
"The list of directories to ignore in this repository. <p>This function takes a list" | ||
+ " of strings and a directory is ignored if any of the given strings matches its" | ||
+ " repository-relative path according to the semantics of the <code>glob()</code>" | ||
+ " function. This function can be used to ignore directories that are implementation" | ||
+ " details of source control systems, output files of other build systems, etc.", | ||
useStarlarkThread = true, | ||
parameters = { | ||
@Param( | ||
name = "dirs", | ||
allowedTypes = { | ||
@ParamType(type = Sequence.class, generic1 = String.class), | ||
}) | ||
}) | ||
public void ignoreDirectories(Iterable<?> dirsUnchecked, StarlarkThread thread) | ||
throws EvalException { | ||
Sequence<String> dirs = Sequence.cast(dirsUnchecked, String.class, "dirs"); | ||
RepoThreadContext context = RepoThreadContext.fromOrFail(thread, "repo()"); | ||
|
||
if (context.isIgnoredDirectoriesSet()) { | ||
throw new EvalException("'ignored_directories()' can only be called once"); | ||
} | ||
|
||
context.setIgnoredDirectories(dirs); | ||
} | ||
|
||
@StarlarkMethod( | ||
name = "repo", | ||
documented = false, // documented separately | ||
extraKeywords = @Param(name = "kwargs"), | ||
useStarlarkThread = true) | ||
public void repoCallable(Map<String, Object> kwargs, StarlarkThread thread) throws EvalException { | ||
RepoThreadContext context = RepoThreadContext.fromOrFail(thread, "repo()"); | ||
if (context.isRepoFunctionCalled()) { | ||
throw Starlark.errorf("'repo' can only be called once in the REPO.bazel file"); | ||
} | ||
|
||
if (context.isIgnoredDirectoriesSet()) { | ||
throw Starlark.errorf("if repo() is called, it must be called before any other functions"); | ||
} | ||
|
||
if (kwargs.isEmpty()) { | ||
throw Starlark.errorf("at least one argument must be given to the 'repo' function"); | ||
} | ||
|
||
context.setPackageArgsMap(kwargs); | ||
} | ||
} |
Oops, something went wrong.