Skip to content

Commit

Permalink
Merge branch 'master' into intern-entries
Browse files Browse the repository at this point in the history
  • Loading branch information
iancha1992 authored Aug 18, 2023
2 parents c77d944 + 77a2954 commit 8d69f2c
Show file tree
Hide file tree
Showing 98 changed files with 1,944 additions and 864 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cherry-picker-on-close.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: cherry-picker-on-close

on:
pull_request:
pull_request_target:
types: [closed]

env:
Expand Down
26 changes: 26 additions & 0 deletions scripts/bash_completion_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,30 @@ test_info() {
'info --show_make_env '
}

test_workspace_boundary() {
# "Test that workspace boundary files are recognized"
# this test only works for Bazel
if [[ ! " ${COMMAND_ALIASES[*]} " =~ " bazel " ]]; then return; fi

mkdir -p sub_repo/some/pkg
touch sub_repo/some/pkg/BUILD
cd sub_repo 2>/dev/null

touch WORKSPACE.bazel
assert_expansion 'build //s' \
'build //some/'

mv WORKSPACE.bazel MODULE.bazel
assert_expansion 'build //s' \
'build //some/'

mv MODULE.bazel REPO.bazel
assert_expansion 'build //s' \
'build //some/'

rm REPO.bazel
assert_expansion 'build //s' \
'build //sub_repo/'
}

run_suite "Tests of bash completion of 'blaze' command."
10 changes: 7 additions & 3 deletions scripts/bazel-complete-template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ _bazel__get_rule_match_pattern() {
}

# Compute workspace directory. Search for the innermost
# enclosing directory with a WORKSPACE file.
# enclosing directory with a boundary file (see
# src/main/cpp/workspace_layout.cc).
_bazel__get_workspace_path() {
local workspace=$PWD
while true; do
if [ -f "${workspace}/WORKSPACE" ]; then
if [ -f "${workspace}/WORKSPACE" ] || \
[ -f "${workspace}/WORKSPACE.bazel" ] || \
[ -f "${workspace}/MODULE.bazel" ] || \
[ -f "${workspace}/REPO.bazel" ]; then
break
elif [ -z "$workspace" -o "$workspace" = "/" ]; then
elif [ -z "$workspace" ] || [ "$workspace" = "/" ]; then
workspace=$PWD
break;
fi
Expand Down
2 changes: 1 addition & 1 deletion site/en/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Here is a selection of recommended rules:

* [Android](/docs/bazel-and-android)
* [C / C++](/docs/bazel-and-cpp)
* [Docker](https://github.com/bazelbuild/rules_docker){: .external}
* [Docker/OCI](https://github.com/bazel-contrib/rules_oci){: .external}
* [Go](https://github.com/bazelbuild/rules_go){: .external}
* [Haskell](https://github.com/tweag/rules_haskell){: .external}
* [Java](/docs/bazel-and-java)
Expand Down
3 changes: 3 additions & 0 deletions src/MODULE.tools
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ use_repo(remote_coverage_tools_extension, "remote_coverage_tools")

remote_android_extensions = use_extension("//tools/android:android_extensions.bzl", "remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")

# Platforms used by transitions in builtins
bazel_dep(name = "apple_support", version = "1.5.0", repo_name = "build_bazel_apple_support")
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ java_library(
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins:processing",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/statistics",
"//src/main/java/com/google/devtools/build/lib/worker:work_request_handlers",
"//third_party:error_prone",
"//third_party:error_prone_annotations",
"//third_party:guava",
"//third_party:jsr305",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public JavaLibraryBuildRequest parse(List<String> args)
throws IOException, InvalidCommandLineException {
OptionsParser optionsParser =
new OptionsParser(args, JavacOptions.createWithWarningsAsErrorsDefault(ImmutableList.of()));
ImmutableList<BlazeJavaCompilerPlugin> plugins = ImmutableList.of(new ErrorPronePlugin());
ImmutableList<BlazeJavaCompilerPlugin> plugins =
ImmutableList.of(new ErrorPronePlugin(BazelScannerSuppliers.bazelChecks()));
return new JavaLibraryBuildRequest(optionsParser, plugins, new DependencyModule.Builder());
}
}

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/main/java/com/google/devtools/build/lib/actions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,12 @@ java_library(
srcs = ["RunfilesSupplier.java"],
deps = [
":artifacts",
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_configuration",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/net/starlark/java/eval",
"//third_party:guava",
"//third_party:jsr305",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Collection;
import java.util.Map;
import javax.annotation.Nullable;

/** A {@link RunfilesSupplier} implementation for composing multiple instances. */
public final class CompositeRunfilesSupplier implements RunfilesSupplier {
Expand Down Expand Up @@ -101,19 +103,21 @@ public ImmutableList<Artifact> getManifests() {
}

@Override
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
@Nullable
public RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir) {
for (RunfilesSupplier supplier : suppliers) {
if (supplier.isBuildRunfileLinks(runfilesDir)) {
return true;
RunfileSymlinksMode mode = supplier.getRunfileSymlinksMode(runfilesDir);
if (mode != null) {
return mode;
}
}
return false;
return null;
}

@Override
public boolean isRunfileLinksEnabled(PathFragment runfilesDir) {
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
for (RunfilesSupplier supplier : suppliers) {
if (supplier.isRunfileLinksEnabled(runfilesDir)) {
if (supplier.isBuildRunfileLinks(runfilesDir)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Map;
import javax.annotation.Nullable;

/** Empty implementation of RunfilesSupplier */
public final class EmptyRunfilesSupplier implements RunfilesSupplier {
Expand Down Expand Up @@ -53,12 +55,13 @@ public ImmutableList<Artifact> getManifests() {
}

@Override
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
return false;
@Nullable
public RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir) {
return null;
}

@Override
public boolean isRunfileLinksEnabled(PathFragment runfilesDir) {
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Map;
import javax.annotation.Nullable;
import net.starlark.java.eval.StarlarkValue;

/** Convenience wrapper around runfiles allowing lazy expansion. */
Expand All @@ -30,37 +32,35 @@
// they are exposed through ctx.resolve_tools[2], for example.
public interface RunfilesSupplier extends StarlarkValue {

/** @return the contained artifacts */
/** Returns the contained artifacts. */
NestedSet<Artifact> getArtifacts();

/** @return the runfiles' root directories. */
/** Returns the runfiles' root directories. */
ImmutableSet<PathFragment> getRunfilesDirs();

/**
* Returns mappings from runfiles directories to artifact mappings in that directory.
*
* @return runfiles' mappings
*/
/** Returns mappings from runfiles directories to artifact mappings in that directory. */
ImmutableMap<PathFragment, Map<PathFragment, Artifact>> getMappings();

/** @return the runfiles manifest artifacts, if any. */
/** Returns the runfiles manifest artifacts, if any. */
ImmutableList<Artifact> getManifests();

/**
* Returns whether for a given {@code runfilesDir} the runfile symlinks are materialized during
* build. Also returns {@code false} if the runfiles supplier doesn't know about the directory.
* Returns the {@link RunfileSymlinksMode} for the given {@code runfilesDir}, or {@code null} if
* the {@link RunfilesSupplier} doesn't know about the directory.
*
* @param runfilesDir runfiles directory relative to the exec root
*/
boolean isBuildRunfileLinks(PathFragment runfilesDir);
@Nullable
RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir);

/**
* Returns whether it's allowed to create runfile symlinks in the {@code runfilesDir}. Also
* returns {@code false} if the runfiles supplier doesn't know about the directory.
* Returns whether the runfile symlinks should be materialized during the build for the given
* {@code runfilesDir}, or {@code false} if the {@link RunfilesSupplier} doesn't know about the
* directory.
*
* @param runfilesDir runfiles directory relative to the exec root
*/
boolean isRunfileLinksEnabled(PathFragment runfilesDir);
boolean isBuildRunfileLinks(PathFragment runfilesDir);

/**
* Returns a {@link RunfilesSupplier} identical to this one, but with the given runfiles
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/java/com/google/devtools/common/options",
"//src/main/java/net/starlark/java/annot",
"//src/main/java/net/starlark/java/eval",
"//src/main/protobuf:failure_details_java_proto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.analysis.actions.ActionConstructionContext;
import com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
import com.google.devtools.build.lib.analysis.config.RunUnder;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
Expand Down Expand Up @@ -87,8 +88,8 @@ public final class RunfilesSupport implements RunfilesSupplier {
private final Artifact repoMappingManifest;
private final Artifact runfilesMiddleman;
private final Artifact owningExecutable;
private final RunfileSymlinksMode runfileSymlinksMode;
private final boolean buildRunfileLinks;
private final boolean runfilesEnabled;
private final CommandLine args;
private final ActionEnvironment actionEnvironment;

Expand All @@ -106,7 +107,9 @@ private static RunfilesSupport create(
CommandLine args,
ActionEnvironment actionEnvironment) {
Artifact owningExecutable = Preconditions.checkNotNull(executable);
boolean createManifest = ruleContext.getConfiguration().buildRunfilesManifests();
RunfileSymlinksMode runfileSymlinksMode =
ruleContext.getConfiguration().getRunfileSymlinksMode();
boolean buildRunfileManifests = ruleContext.getConfiguration().buildRunfileManifests();
boolean buildRunfileLinks = ruleContext.getConfiguration().buildRunfileLinks();

// Adding run_under target to the runfiles manifest so it would become part
Expand All @@ -131,7 +134,7 @@ private static RunfilesSupport create(

Artifact runfilesInputManifest;
Artifact runfilesManifest;
if (createManifest) {
if (buildRunfileManifests) {
runfilesInputManifest = createRunfilesInputManifestArtifact(ruleContext, owningExecutable);
runfilesManifest =
createRunfilesAction(
Expand All @@ -144,17 +147,15 @@ private static RunfilesSupport create(
createRunfilesMiddleman(
ruleContext, owningExecutable, runfiles, runfilesManifest, repoMappingManifest);

boolean runfilesEnabled = ruleContext.getConfiguration().runfilesEnabled();

return new RunfilesSupport(
runfiles,
runfilesInputManifest,
runfilesManifest,
repoMappingManifest,
runfilesMiddleman,
owningExecutable,
runfileSymlinksMode,
buildRunfileLinks,
runfilesEnabled,
args,
actionEnvironment);
}
Expand All @@ -166,8 +167,8 @@ private RunfilesSupport(
Artifact repoMappingManifest,
Artifact runfilesMiddleman,
Artifact owningExecutable,
RunfileSymlinksMode runfileSymlinksMode,
boolean buildRunfileLinks,
boolean runfilesEnabled,
CommandLine args,
ActionEnvironment actionEnvironment) {
this.runfiles = runfiles;
Expand All @@ -176,8 +177,8 @@ private RunfilesSupport(
this.repoMappingManifest = repoMappingManifest;
this.runfilesMiddleman = runfilesMiddleman;
this.owningExecutable = owningExecutable;
this.runfileSymlinksMode = runfileSymlinksMode;
this.buildRunfileLinks = buildRunfileLinks;
this.runfilesEnabled = runfilesEnabled;
this.args = args;
this.actionEnvironment = actionEnvironment;
}
Expand All @@ -194,27 +195,33 @@ public PathFragment getRunfilesDirectoryExecPath() {
}

/**
* Returns {@code true} if runfile symlinks should be materialized when building an executable.
*
* <p>Also see {@link #isRunfilesEnabled()}.
* Same as {@link #getRunfileSymlinksMode(PathFragment)} with {@link
* #getRunfilesDirectoryExecPath} as the implied argument.
*/
public boolean isBuildRunfileLinks() {
return buildRunfileLinks;
public RunfileSymlinksMode getRunfileSymlinksMode() {
return runfileSymlinksMode;
}

@Override
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
return buildRunfileLinks && runfilesDir.equals(getRunfilesDirectoryExecPath());
@Nullable
public RunfileSymlinksMode getRunfileSymlinksMode(PathFragment runfilesDir) {
if (runfilesDir.equals(getRunfilesDirectoryExecPath())) {
return runfileSymlinksMode;
}
return null;
}

/**
* Returns {@code true} if runfile symlinks are enabled.
*
* <p>This option differs from {@link #isBuildRunfileLinks()} in that if {@code false} it also
* disables runfile symlinks creation during run/test.
* Same as {@link #isBuildRunfileLinks(PathFragment)} with {@link #getRunfilesDirectoryExecPath}
* as the implied argument.
*/
public boolean isRunfilesEnabled() {
return runfilesEnabled;
public boolean isBuildRunfileLinks() {
return buildRunfileLinks;
}

@Override
public boolean isBuildRunfileLinks(PathFragment runfilesDir) {
return buildRunfileLinks && runfilesDir.equals(getRunfilesDirectoryExecPath());
}

public Runfiles getRunfiles() {
Expand Down Expand Up @@ -552,11 +559,6 @@ public ImmutableList<Artifact> getManifests() {
return ImmutableList.of();
}

@Override
public boolean isRunfileLinksEnabled(PathFragment runfilesDir) {
return runfilesEnabled && runfilesDir.equals(getRunfilesDirectoryExecPath());
}

@Override
public RunfilesSupplier withOverriddenRunfilesDir(PathFragment newRunfilesDir) {
return newRunfilesDir.equals(getRunfilesDirectoryExecPath())
Expand All @@ -566,7 +568,7 @@ public RunfilesSupplier withOverriddenRunfilesDir(PathFragment newRunfilesDir) {
runfiles,
/* manifest= */ null,
repoMappingManifest,
buildRunfileLinks,
runfilesEnabled);
runfileSymlinksMode,
buildRunfileLinks);
}
}
Loading

0 comments on commit 8d69f2c

Please sign in to comment.