Skip to content

Commit

Permalink
Merge pull request #138 from grab/revert-lint-split-cli
Browse files Browse the repository at this point in the history
Revert lint split cli
  • Loading branch information
mohammadkahelghi-grabtaxi authored Jan 15, 2024
2 parents 3f16c52 + d55b8f2 commit e675751
Show file tree
Hide file tree
Showing 37 changed files with 401 additions and 837 deletions.
47 changes: 7 additions & 40 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,16 @@
build --disk_cache=bazel-cache

build --verbose_failures
build --incompatible_strict_action_env
build --repo_env=RJE_VERBOSE=true

common --experimental_google_legacy_api

# Workers
build --experimental_worker_multiplex
# Databinding flags
build --experimental_android_databinding_v2
build --android_databinding_use_v3_4_args
build --android_databinding_use_androidx

# Java
build --java_runtime_version=remotejdk_11 # Use inbuilt Java 11 for hermeticity
build --jvmopt="-Djava.locale.providers=COMPAT,SPI" # Use Java 8 default locale provider
build --experimental_google_legacy_api
query --experimental_google_legacy_api

# Android
# Databinding flags
common --experimental_android_databinding_v2
common --android_databinding_use_v3_4_args
common --android_databinding_use_androidx
# D8 and Dexing flags
build --define=android_incremental_dexing_tool=d8_dexbuilder
build --define=android_standalone_dexing_tool=d8_compat_dx
build --define=android_dexmerger_tool=d8_dexmerger

build --persistent_multiplex_android_tools
build --strategy=DatabindingStubs=worker
build --worker_max_instances=Javac=1
build --worker_max_instances=KotlinCompile=1
build --worker_max_instances=KotlinKapt=1
build --worker_max_instances=AaptPackage=1
build --worker_max_instances=AndroidResourceParser=1
build --worker_max_instances=AndroidResourceCompiler=1
build --worker_max_instances=AndroidResourceValidator=1
build --worker_max_instances=AndroidLintAnalyze=1
build --worker_max_instances=AndroidLint=1
build --worker_max_instances=RClassGenerator=1
build --worker_max_instances=AndroidAapt2=1
build --worker_max_instances=AndroidAssetMerger=1
build --worker_max_instances=AndroidResourceMerger=1
build --worker_max_instances=AndroidCompiledResourceMerger=1
build --worker_max_instances=Aapt2Optimize=1
build --worker_max_instances=DatabindingStubs=1
build --worker_max_instances=GenerateDataBindingBaseClasses=1
build --worker_max_instances=DexBuilder=1
build --worker_max_instances=Desugar=1
common --strategy=AndroidLint=sandboxed

test --test_output=errors # Print test logs for failed tests
test --build_tests_only
Expand Down
1 change: 0 additions & 1 deletion rules/android/lint/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def lint(
lint_baseline: The baseline XML file to compare results against
"""

# Normal build target to apply lint aspect and establish AndroidLintInfo provider
_lint(
name = name + ".lint",
target = linting_target,
Expand Down
221 changes: 36 additions & 185 deletions rules/android/lint/lint.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
load("@grab_bazel_common//rules/android:utils.bzl", "utils")
load(
"@grab_bazel_common//rules/android/lint:providers.bzl",
"AndroidLintInfo",
"AndroidLintNodeInfo",
"AndroidLintSourcesInfo",
"LINT_ENABLED",
)
load("@grab_bazel_common//rules/android/lint:providers.bzl", "AndroidLintInfo", "AndroidLintNodeInfo", "AndroidLintSourcesInfo", "LINT_ENABLED")

_LINT_ASPECTS_ATTR = ["deps", "runtime_deps", "exports", "associates"] # Define attributes that aspect will propagate to

Expand All @@ -24,10 +18,8 @@ def _compile_sdk_version(sdk_target):

def _lint_sources_classpath(target, ctx):
"""
Collect the classpath for linting. Currently all transitive jars are passed since
sometimes lint complains about missing class defs. Need to revisit to prune transitive
deps for performance.
Collect the classpath for linting. Currently all transitive jars are passed since sometimes lint complains about missing
class defs. Need to revisit to prune transitive deps for performance.
Apart from dependency jars, add the current target's android resource jar as well.
"""
transitive = [
Expand Down Expand Up @@ -103,9 +95,8 @@ def _encode_dependency(dependency_info):
dependency_info.partial_results_dir.path,
)

def _lint_common_args(
def _lint_action(
ctx,
args,
android,
library,
compile_sdk_version,
Expand All @@ -114,13 +105,17 @@ def _lint_common_args(
classpath,
manifest,
merged_manifest,
baseline,
dep_lint_node_infos,
baseline,
updated_baseline,
lint_config_xml_file,
lint_result_xml_file,
partial_results_dir,
project_xml_file,
jdk_home,
verbose):
result_code,
verbose,
inputs):
args = ctx.actions.args()
args.set_param_file_format("multiline")
args.use_param_file("--flagfile=%s", use_always = True)

Expand Down Expand Up @@ -165,129 +160,28 @@ def _lint_common_args(

if baseline:
args.add("--baseline", baseline[0].path)
args.add("--updated-baseline", updated_baseline)

args.add("--output-xml", lint_result_xml_file.path)
args.add("--lint-config", lint_config_xml_file.path)
args.add("--partial-results-dir", partial_results_dir.path)
args.add("--result-code", result_code)

if verbose: #TODO(arun) Pass via build config
args.add("--verbose")

args.add("--jdk-home", jdk_home)

args.add("--project-xml", project_xml_file.path)
return

def _lint_analyze_action(
ctx,
android,
library,
compile_sdk_version,
srcs,
resources,
classpath,
manifest,
merged_manifest,
dep_lint_node_infos,
baseline,
lint_config_xml_file,
partial_results_dir,
jdk_home,
project_xml_file,
verbose,
inputs,
outputs):
args = ctx.actions.args()
args.add("ANALYZE")
_lint_common_args(
ctx = ctx,
args = args,
android = android,
library = library,
compile_sdk_version = compile_sdk_version,
srcs = srcs,
resources = resources,
classpath = classpath,
manifest = manifest,
merged_manifest = merged_manifest,
baseline = baseline,
dep_lint_node_infos = dep_lint_node_infos,
lint_config_xml_file = lint_config_xml_file,
partial_results_dir = partial_results_dir,
project_xml_file = project_xml_file,
jdk_home = jdk_home,
verbose = verbose,
)

mnemonic = "AndroidLintAnalyze"
ctx.actions.run(
mnemonic = mnemonic,
inputs = inputs,
outputs = outputs,
executable = ctx.executable._lint_cli,
arguments = [args],
progress_message = "%s %s" % (mnemonic, str(ctx.label).lstrip("@")),
execution_requirements = {
"supports-workers": "1",
"supports-multiplex-workers": "1",
"requires-worker-protocol": "json",
},
)
return

def _lint_report_action(
ctx,
android,
library,
compile_sdk_version,
srcs,
resources,
classpath,
manifest,
merged_manifest,
dep_lint_node_infos,
baseline,
updated_baseline,
lint_config_xml_file,
lint_result_xml_file,
partial_results_dir,
jdk_home,
project_xml_file,
result_code,
verbose,
inputs,
outputs):
args = ctx.actions.args()
args.add("REPORT")
_lint_common_args(
ctx = ctx,
args = args,
android = android,
library = library,
compile_sdk_version = compile_sdk_version,
srcs = srcs,
resources = resources,
classpath = classpath,
manifest = manifest,
merged_manifest = merged_manifest,
baseline = baseline,
dep_lint_node_infos = dep_lint_node_infos,
lint_config_xml_file = lint_config_xml_file,
partial_results_dir = partial_results_dir,
project_xml_file = project_xml_file,
jdk_home = jdk_home,
verbose = verbose,
)

args.add("--updated-baseline", updated_baseline)

args.add("--output-xml", lint_result_xml_file.path)
args.add("--result-code", result_code)

mnemonic = "AndroidLint"
ctx.actions.run(
mnemonic = mnemonic,
inputs = inputs,
outputs = outputs,
outputs = [
partial_results_dir,
lint_result_xml_file,
updated_baseline,
result_code,
],
executable = ctx.executable._lint_cli,
arguments = [args],
progress_message = "%s %s" % (mnemonic, str(ctx.label).lstrip("@")),
Expand All @@ -304,6 +198,11 @@ def _lint_aspect_impl(target, ctx):
# Run lint only on internal targets
return []
else:
# Output
partial_results_dir = ctx.actions.declare_directory("lint/" + target.label.name + "_partial_results_dir")
lint_result_xml_file = ctx.actions.declare_file("lint/" + target.label.name + "_lint_result.xml")
lint_result_code_file = ctx.actions.declare_file("lint/" + target.label.name + "_lint_result_code")

# Current target info
rule_kind = ctx.rule.kind
android = rule_kind == "android_library" or rule_kind == "android_binary"
Expand All @@ -319,10 +218,6 @@ def _lint_aspect_impl(target, ctx):
if enabled:
# Output
lint_updated_baseline_file = ctx.actions.declare_file("lint/" + target.label.name + "_updated_baseline.xml")
partial_results_dir = ctx.actions.declare_directory("lint/" + target.label.name + "_partial_results_dir")
lint_result_xml_file = ctx.actions.declare_file("lint/" + target.label.name + "_lint_result.xml")
lint_result_code_file = ctx.actions.declare_file("lint/" + target.label.name + "_lint_result_code")
project_xml_file = ctx.actions.declare_file("lint/" + target.label.name + "_project.xml")

sources = _collect_sources(target, ctx, library)
compile_sdk_version = _compile_sdk_version(ctx.attr._android_sdk)
Expand All @@ -337,51 +232,7 @@ def _lint_aspect_impl(target, ctx):
# Pass JDK Home
java_runtime_info = ctx.attr._javabase[java_common.JavaRuntimeInfo]

# +--------+ +---------+
# | | | |
# | Report +--------------->| Analyze |
# | | | |
# +--------+ +---------+
# -baseline -parital-results-dir
# -lint_result.xml -project-xml
# Add separate actions for reporting and analyze and then return different providers in the aspect.
# Consuming rules can decide whether to use reporting output or analysis output by using the
# correct output file

_lint_analyze_action(
ctx = ctx,
android = android,
library = library,
compile_sdk_version = compile_sdk_version,
srcs = sources.srcs,
resources = sources.resources,
classpath = sources.classpath,
manifest = sources.manifest,
merged_manifest = sources.merged_manifest,
dep_lint_node_infos = dep_lint_node_infos,
baseline = sources.baseline,
lint_config_xml_file = sources.lint_config_xml,
partial_results_dir = partial_results_dir,
jdk_home = java_runtime_info.java_home,
project_xml_file = project_xml_file,
verbose = False,
inputs = depset(
sources.srcs +
sources.resources +
sources.manifest +
sources.merged_manifest +
[sources.lint_config_xml] +
partial_results +
baseline_inputs,
transitive = [sources.classpath, java_runtime_info.files],
),
outputs = [
partial_results_dir,
project_xml_file,
],
)

_lint_report_action(
_lint_action(
ctx = ctx,
android = android,
library = library,
Expand All @@ -398,7 +249,6 @@ def _lint_aspect_impl(target, ctx):
lint_result_xml_file = lint_result_xml_file,
partial_results_dir = partial_results_dir,
jdk_home = java_runtime_info.java_home,
project_xml_file = project_xml_file,
result_code = lint_result_code_file,
verbose = False,
inputs = depset(
Expand All @@ -408,16 +258,9 @@ def _lint_aspect_impl(target, ctx):
sources.merged_manifest +
[sources.lint_config_xml] +
partial_results +
[partial_results_dir] + # Current module partial results from analyze action
[project_xml_file] + # Reuse project xml from analyze action
baseline_inputs,
transitive = [sources.classpath, java_runtime_info.files],
),
outputs = [
lint_result_xml_file,
lint_updated_baseline_file,
lint_result_code_file,
],
)

android_lint_info = AndroidLintNodeInfo(
Expand All @@ -431,14 +274,22 @@ def _lint_aspect_impl(target, ctx):
updated_baseline = lint_updated_baseline_file,
)
else:
# No linting to do, just propagate transitive data
ctx.actions.run_shell(
outputs = [partial_results_dir],
command = ("mkdir -p %s" % (partial_results_dir.path)),
)
ctx.actions.write(output = lint_result_xml_file, content = "")
ctx.actions.write(output = lint_result_code_file, content = "0")

android_lint_info = AndroidLintNodeInfo(
name = str(target.label),
android = android,
library = library,
enabled = enabled,
partial_results_dir = None,
lint_result_xml = None,
result_code = None,
lint_result_xml = lint_result_xml_file,
result_code = lint_result_code_file,
updated_baseline = None,
)
return AndroidLintInfo(
Expand Down
Loading

0 comments on commit e675751

Please sign in to comment.