Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable header compilation for r-classes #42

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions tools/build_config/build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_config(
booleans = {},
ints = {},
longs = {}):
"""Generates a Jar file containing BuildConfig class just like AGP.
"""Generates a kt_jvm_library target containing build config fields just like AGP.
Usage:
Add the field variables in the relevant dicts like (strings, booleans etc) and add a dependency
Expand All @@ -68,10 +68,7 @@ def build_config(
"""

build_config = "BuildConfig"
build_config_file_path = "$(RULEDIR)/{}.kt".format(build_config)

# Uses srcjar so that the generated .kt file can be compiled to class file via kt_jvm_library
build_config_jar = name + ".srcjar"
build_config_file_path = "src/main/%s/%s.kt" % (name, build_config)

strings_statements = _build_statement(
_STRING_TYPE,
Expand All @@ -87,10 +84,9 @@ def build_config(
ints_statements = _build_statement(_INT_TYPE, ints, False)
longs_statements = _build_statement(_LONG_TYPE, longs, False)

# Cmd for genrule. Generates BuildConfig.kt and packages it to a Java jar file in the build
# directory
# Cmd for genrule. Generates BuildConfig.
cmd = """
cat << EOF > {build_config_file_path}
cat << EOF > $@
/**
* Generated file do not modify
*/
Expand All @@ -102,9 +98,7 @@ object {build_config} {{
{ints_statements}
{longs_statements}
}}
EOF
$(location @bazel_tools//tools/zip:zipper) c $@ {build_config_file_path}
""".format(
EOF""".format(
build_config = build_config,
build_config_file_path = build_config_file_path,
package_name = package_name,
Expand All @@ -115,14 +109,13 @@ $(location @bazel_tools//tools/zip:zipper) c $@ {build_config_file_path}
)

native.genrule(
name = "_" + name,
outs = [build_config_jar],
name = "_%s_gen" % name,
outs = [build_config_file_path],
cmd = cmd,
message = "Generating %s's build config class" % (native.package_name()),
tools = ["@bazel_tools//tools/zip:zipper"],
)

kt_jvm_library(
name = name,
srcs = [build_config_jar],
srcs = [build_config_file_path],
)
9 changes: 8 additions & 1 deletion tools/databinding/databinding.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load(":databinding_stubs.bzl", "databinding_stubs")
load("@grab_bazel_common//tools/java:java_library_no_header.bzl", "java_library_no_header")
# load(":databinding_aar.bzl", "databinding_aar")

# TODO(arun) Replace with configurable maven targets
Expand Down Expand Up @@ -95,6 +96,12 @@ def kt_db_android_library(
neverlink = 1, # Use the R classes only for compiling and not at runtime.
)

r_classes_no_header = name + "-r-classes-no-header"
java_library_no_header(
name = r_classes_no_header,
dep = ":" + r_classes,
)

# Create an intermediate target for compiling all Kotlin classes used in Databinding
kotlin_target = name + "-kotlin"
kotlin_targets = []
Expand All @@ -114,7 +121,7 @@ def kt_db_android_library(
name = kotlin_target,
srcs = srcs + [binding_classes_sources],
plugins = plugins,
deps = deps + _DATABINDING_DEPS + [r_classes] + [
deps = deps + _DATABINDING_DEPS + [r_classes_no_header] + [
"@grab_bazel_common//tools/binding-adapter-bridge:binding-adapter-bridge",
"@grab_bazel_common//tools/android:android_sdk",
],
Expand Down
Empty file added tools/java/BUILD.bazel
Empty file.
26 changes: 26 additions & 0 deletions tools/java/java_library_no_header.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def _java_header_compilation_transition(settings, attr):
_ignore = (settings, attr)
return {"//command_line_option:java_header_compilation": "False"}

java_header_compilation_transition = transition(
implementation = _java_header_compilation_transition,
inputs = [],
outputs = ["//command_line_option:java_header_compilation"],
)

def _java_library_without_header_compilation(ctx):
return [java_common.merge([d[JavaInfo] for d in ctx.attr.dep])]

java_library_no_header = rule(
implementation = _java_library_without_header_compilation,
attrs = {
"dep": attr.label(
providers = [JavaInfo],
mandatory = True,
cfg = java_header_compilation_transition,
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
)