Skip to content

Commit

Permalink
Merge branch 'bazelbuild:master' into release_test
Browse files Browse the repository at this point in the history
  • Loading branch information
iancha1992 authored Aug 1, 2023
2 parents 372fa1c + cf14039 commit 862cad9
Show file tree
Hide file tree
Showing 62 changed files with 1,113 additions and 1,033 deletions.
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ body:
attributes:
label: >
Description of the bug:
- type: dropdown
id: subteam
attributes:
label: >
Which category does this issue belong to?
description: >
Answering this will help us triage this issue faster and more accurately to the
relevant team(s).
multiple: true
options:
- Android
- C++ Rules
- CLI
- Configurability
- Core
- Documentation
- External Dependency
- Java Rules
- Loading API
- Local Execution
- Performance
- Python Rules
- Remote Execution
- Rules API
- Server-Side Rules
- Starlark Integration
- Starlark Interpreter
- type: textarea
id: repro
attributes:
Expand Down
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ body:
attributes:
label: >
Description of the feature request:
- type: dropdown
id: subteam
attributes:
label: >
Which category does this issue belong to?
description: >
Answering this will help us triage this issue faster and more accurately to the
relevant team(s).
multiple: true
options:
- Android
- C++ Rules
- CLI
- Configurability
- Core
- Documentation
- External Dependency
- Java Rules
- Loading API
- Local Execution
- Performance
- Python Rules
- Remote Execution
- Rules API
- Server-Side Rules
- Starlark Integration
- Starlark Interpreter
- type: textarea
id: problem
attributes:
Expand Down
89 changes: 68 additions & 21 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# To build Bazel with Bzlmod: `bazel build --enable_bzlmod //src:bazel_nojdk`.

module(
name = "bazel",
version = "7.0.0-pre",
Expand All @@ -20,15 +18,33 @@ bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "rules_java", version = "6.3.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_jvm_external", version = "5.2")
bazel_dep(name = "rules_python", version = "0.19.0")
bazel_dep(name = "rules_python", version = "0.24.0")
bazel_dep(name = "rules_testing", version = "0.0.4")

# TODO(pcloudy): Add remoteapis and googleapis as Bazel modules in the BCR.
bazel_dep(name = "remoteapis", version = "")
bazel_dep(name = "googleapis", version = "")

single_version_override(
module_name = "rules_jvm_external",
patch_strip = 1,
patches = ["//third_party:rules_jvm_external_5.2.patch"],
)

local_path_override(
module_name = "remoteapis",
path = "./third_party/remoteapis",
)

local_path_override(
module_name = "googleapis",
path = "./third_party/googleapis",
)

# =========================================
# Bazel Java dependencies
# =========================================

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
# We don't yet specify the maven coordinates in the MODULE.bazel to avoid duplicating information.
Expand All @@ -41,35 +57,66 @@ maven.install(
)
use_repo(maven, "maven")

# TODO(pcloudy): Add remoteapis and googleapis as Bazel modules in the BCR.
bazel_dep(name = "remoteapis", version = "")
bazel_dep(name = "googleapis", version = "")

local_path_override(
module_name = "remoteapis",
path = "./third_party/remoteapis",
)

local_path_override(
module_name = "googleapis",
path = "./third_party/googleapis",
)
# =========================================
# Other Bazel internal dependencies
# - embedded JDKs
# - repos for Debian build
# =========================================

bazel_internal_deps = use_extension("//:extensions.bzl", "bazel_internal_deps")
use_repo(
bazel_internal_deps,
"openjdk_linux_vanilla",
"debian_cc_deps",
"openjdk_linux_aarch64_vanilla",
"openjdk_linux_ppc64le_vanilla",
"openjdk_linux_s390x_vanilla",
"openjdk_macos_x86_64_vanilla",
"openjdk_linux_vanilla",
"openjdk_macos_aarch64_vanilla",
"openjdk_win_vanilla",
"openjdk_macos_x86_64_vanilla",
"openjdk_win_arm64_vanilla",
"openjdk_win_vanilla",
)

# =========================================
# Register platforms & toolchains
# =========================================

register_execution_platforms("//:default_host_platform")

register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain")

# Dev dependencies
register_toolchains("//src/main/res:empty_rc_toolchain")

# =========================================
# Android tools dependencies
# =========================================

maven_android = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven_android.install(
name = "maven_android",
# We don't yet specify the maven coordinates in the MODULE.bazel to avoid duplicating information.
# Always respect the maven_install.json file generated by rules_jvm_external from the WORKSPACE file.
# TODO(pcloudy): We should add maven coordinates here when we enable Bzlmod in the default build for Bazel.
lock_file = "//src/tools/android:maven_android_install.json",
repositories = [
"https://dl.google.com/android/maven2",
"https://repo1.maven.org/maven2",
],
)
use_repo(maven_android, "maven_android")

bazel_android_deps = use_extension("//:extensions.bzl", "bazel_android_deps")
use_repo(
bazel_android_deps,
"android_gmaven_r8",
"desugar_jdk_libs",
)

# =========================================
# Bazel dev dependencies
# =========================================

bazel_dep(name = "googletest", version = "1.12.1", repo_name = "com_google_googletest")

bazel_dep(name = "googletest", version = "1.12.1", repo_name = "com_google_googletest", dev_dependency = True)
bazel_dev_deps = use_extension("//:extensions.bzl", "bazel_dev_deps")
use_repo(bazel_dev_deps, "local_bazel_source_list")
52 changes: 52 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
# This file will replace the content of the WORKSPACE file when Bzlmod is enabled
# No WORKSPACE prefix or suffix are added.

bind(
name = "android/sdk",
actual = "@bazel_tools//tools/android:poison_pill_android_sdk",
)

bind(
name = "android/dx_jar_import",
actual = "@bazel_tools//tools/android:no_android_sdk_repository_error",
)

bind(
name = "android/d8_jar_import",
actual = "@bazel_tools//tools/android:no_android_sdk_repository_error",
)

bind(
name = "android/crosstool",
actual = "@bazel_tools//tools/cpp:toolchain",
)

bind(
name = "android_sdk_for_testing",
actual = "@bazel_tools//tools/android:empty",
)

bind(
name = "android_ndk_for_testing",
actual = "@bazel_tools//tools/android:empty",
)

bind(
name = "databinding_annotation_processor",
actual = "@bazel_tools//tools/android:empty",
)

# This value is overridden by android_sdk_repository function to allow targets
# to select on whether or not android_sdk_repository has run.
bind(
name = "has_androidsdk",
actual = "@bazel_tools//tools/android:always_false",
)

# To run the Android integration tests in //src/test/shell/bazel/android:all or
# build the Android sample app in //examples/android/java/bazel:hello_world
#
# 1. Install an Android SDK and NDK from https://developer.android.com
# 2. Set the $ANDROID_HOME and $ANDROID_NDK_HOME environment variables
# 3. Uncomment the two lines below
#
# android_sdk_repository(name = "androidsdk")
# android_ndk_repository(name = "androidndk")
21 changes: 21 additions & 0 deletions extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@
"""

load("//:repositories.bzl", "embedded_jdk_repositories")
load("//:distdir.bzl", "dist_http_archive", "dist_http_jar")
load("//tools/distributions/debian:deps.bzl", "debian_deps")
load("//src/test/shell/bazel:list_source_repository.bzl", "list_source_repository")

### Extra dependencies for building Bazel

def _bazel_internal_deps(_ctx):
embedded_jdk_repositories()
debian_deps()

bazel_internal_deps = module_extension(implementation = _bazel_internal_deps)

### Extra dependencies for testing Bazel

def _bazel_dev_deps(_ctx):
list_source_repository(name = "local_bazel_source_list")

bazel_dev_deps = module_extension(implementation = _bazel_dev_deps)

### Extra dependencies for Bazel Android tools

def _bazel_android_deps(_ctx):
dist_http_jar(name = "android_gmaven_r8")
dist_http_archive(name = "desugar_jdk_libs")

bazel_android_deps = module_extension(implementation = _bazel_android_deps)
16 changes: 9 additions & 7 deletions site/en/extending/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Book: /_book.yaml

# Configurations

<devsite-mathjax config="TeX-AMS-MML_SVG"></devsite-mathjax>

{% include "_buttons.html" %}

This page covers the benefits and basic usage of Starlark configurations,
Expand Down Expand Up @@ -688,7 +690,7 @@ def _rule_impl(ctx):
transitioned_dep = ctx.attr.dep[0]

# Note: Access doesn't change, other_deps was already a list
for other dep in ctx.attr.other_deps:
for other_dep in ctx.attr.other_deps:
# ...


Expand Down Expand Up @@ -755,19 +757,19 @@ might create exponential growth of your build graph.

**Figure 1.** Scalability graph showing a top level target and its dependencies.

This graph shows a top level target, //pkg:app, which depends on two targets, a
//pkg:1_0 and //pkg:1_1. Both these targets depend on two targets, //pkg:2_0 and
//pkg:2_1. Both these targets depend on two targets, //pkg:3_0 and //pkg:3_1.
This continues on until //pkg:n_0 and //pkg:n_1, which both depend on a single
target, //pkg:dep.
This graph shows a top level target, `//pkg:app`, which depends on two targets, a
`//pkg:1_0` and `//pkg:1_1`. Both these targets depend on two targets, `//pkg:2_0` and
`//pkg:2_1`. Both these targets depend on two targets, `//pkg:3_0` and `//pkg:3_1`.
This continues on until `//pkg:n_0` and `//pkg:n_1`, which both depend on a single
target, `//pkg:dep`.

Building `//pkg:app` requires \\(2n+2\\) targets:

* `//pkg:app`
* `//pkg:dep`
* `//pkg:i_0` and `//pkg:i_1` for \\(i\\) in \\([1..n]\\)

Imagine you [implement](#user-defined-build-settings)) a flag
Imagine you [implement](#user-defined-build-settings) a flag
`--//foo:owner=<STRING>` and `//pkg:i_b` applies

depConfig = myConfig + depConfig.owner="$(myConfig.owner)$(b)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static Attribute.Builder<?> createAttribute(
String name)
throws EvalException {
Attribute.Builder<?> builder = Attribute.attr(name, type).starlarkDefined();
doc.ifPresent(builder::setDoc);
doc.map(Starlark::trimDocString).ifPresent(builder::setDoc);

Object defaultValue = arguments.get(DEFAULT_ARG);
if (!Starlark.isNullOrNone(defaultValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.common.collect.ImmutableList;
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.Allowlist;
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
Expand Down Expand Up @@ -252,11 +253,15 @@ public static RuleClass getTestBaseRule(RuleDefinitionEnvironment env) {
public Object provider(Object doc, Object fields, Object init, StarlarkThread thread)
throws EvalException {
StarlarkProvider.Builder builder = StarlarkProvider.builder(thread.getCallerLocation());
Starlark.toJavaOptional(doc, String.class).ifPresent(builder::setDocumentation);
Starlark.toJavaOptional(doc, String.class)
.map(Starlark::trimDocString)
.ifPresent(builder::setDocumentation);
if (fields instanceof Sequence) {
builder.setSchema(Sequence.cast(fields, String.class, "fields"));
} else if (fields instanceof Dict) {
builder.setSchema(Dict.cast(fields, String.class, String.class, "fields"));
builder.setSchema(
Maps.transformValues(
Dict.cast(fields, String.class, String.class, "fields"), Starlark::trimDocString));
}
if (init == Starlark.NONE) {
return builder.build();
Expand Down Expand Up @@ -495,7 +500,7 @@ public static StarlarkRuleFunction createRule(
type,
attributes,
thread.getCallerLocation(),
Starlark.toJavaOptional(doc, String.class));
Starlark.toJavaOptional(doc, String.class).map(Starlark::trimDocString));
}

private static void checkAttributeName(String name) throws EvalException {
Expand Down Expand Up @@ -673,7 +678,7 @@ public StarlarkAspect aspect(

return new StarlarkDefinedAspect(
implementation,
Starlark.toJavaOptional(doc, String.class),
Starlark.toJavaOptional(doc, String.class).map(Starlark::trimDocString),
attrAspects.build(),
attributes.build(),
StarlarkAttrModule.buildProviderPredicate(requiredProvidersArg, "required_providers"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,10 @@ public static class Options extends FragmentOptions {
help = "If enabled, visibility checking also applies to toolchain implementations.")
public boolean checkVisibilityForToolchains;

@Option(
name = "incompatible_remove_exec_tools",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
help = "If enabled, use of genrule's exec_tools attribute will cause an error..")
public boolean removeExecTools;

@Override
public FragmentOptions getExec() {
Options exec = (Options) getDefault();
exec.checkVisibilityForToolchains = checkVisibilityForToolchains;
exec.removeExecTools = removeExecTools;

return exec;
}
Expand Down
Loading

0 comments on commit 862cad9

Please sign in to comment.