Skip to content

Commit f58613c

Browse files
authored
Windows portability fixes (#1386)
* buildifier: auto-sorting * Use native .run action over run_shell Remove dependency on host shell since bash is not available on Windows * Add get_auth to repository_download In case the content is e.g. behind a mirror with authentication, this is necessary. Note: get_auth was introduced in 7.1.0 and would break compatibility with earlier versions * Add unsorted-dict-items to the buildifier warnigns Added fixes with: ``` bazel run //:buildifier.fix ``` * Fix buildifier deprecation When running `//:buildifier.check` this deprecation warning is issued ``` buildifier: selecting diff program with the BUILDIFIER_DIFF, BUILDIFIER_MULTIDIFF, and DISPLAY environment variables is deprecated, use flags -diff_command and -multi_diff instead ``` * Fix order of sorted flags after _TEST_OPTS got sorted Since the order of the opts changed, the order in which the flags are produced changes as well * Add the unsorted-dict-items checks to ci and pre-commit-config * Bump buildifier to same version as .bazelci version bazelci uses 8.2.0
1 parent 5711009 commit f58613c

40 files changed

+783
-778
lines changed

.bazelci/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ buildifier:
2020
version: 8.2.0
2121
# no lint warnings for the moment. They are basically a smoke alarm in hell.
2222
# keep this argument in sync with .pre-commit-config.yaml
23-
warnings: "-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable"
23+
warnings: "+unsorted-dict-items,-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable"
2424
tasks:
2525
unittests:
2626
name: "Unit Tests"

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ repos:
88
- id: buildifier
99
args: &args
1010
# Keep this argument in sync with .bazelci/config.yaml
11-
- --warnings=-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable
11+
- --warnings=+unsorted-dict-items,-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable
1212
- id: buildifier-lint
1313
args: *args

BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ buildifier(
9191
],
9292
lint_mode = "warn",
9393
lint_warnings = [
94+
"+unsorted-dict-items",
9495
"-confusing-name",
9596
"-constant-glob",
9697
"-duplicated-name",
@@ -109,7 +110,6 @@ buildifier(
109110
"-uninitialized",
110111
"-unreachable",
111112
],
112-
mode = "diff",
113113
)
114114

115115
buildifier(
@@ -118,4 +118,7 @@ buildifier(
118118
"./.git/*",
119119
],
120120
lint_mode = "fix",
121+
lint_warnings = [
122+
"+unsorted-dict-items",
123+
],
121124
)

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bazel_dep(name = "rules_android", version = "0.6.4")
1717
bazel_dep(name = "bazel_features", version = "1.25.0")
1818
bazel_dep(name = "rules_shell", version = "0.4.1")
1919

20-
bazel_dep(name = "buildifier_prebuilt", version = "8.0.3", dev_dependency = True)
20+
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2", dev_dependency = True)
2121

2222
rules_java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
2323
use_repo(rules_java_toolchains, "remote_java_tools")

examples/anvil/third_party/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ kt_compiler_plugin(
6262
compile_phase = True,
6363
id = "com.squareup.anvil.compiler",
6464
options = {
65-
"src-gen-dir": "{generatedSources}",
6665
"generate-dagger-factories": "true",
66+
"src-gen-dir": "{generatedSources}",
6767
},
6868
stubs_phase = True,
6969
target_embedded_compiler = True,

examples/ksp/third_party/BUILD.bazel

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ kt_compiler_plugin(
1414
compile_phase = True,
1515
id = "com.google.devtools.ksp.symbol-processing",
1616
options = {
17+
"allWarningsAsErrors": "false",
1718
"apclasspath": "{classpath}",
18-
# projectBaseDir shouldn't matter because incremental is disabled
19-
"projectBaseDir": "{temp}",
20-
# Disable incremental mode
21-
"incremental": "false",
19+
# Directory to write KSP caches. Shouldn't matter because incremental is disabled
20+
"cachesDir": "{temp}",
2221
# Directory where class files are written to. Files written to this directory are class
2322
# files being written directly from the annotation processor, not Kotlinc
2423
"classOutputDir": "{generatedClasses}",
24+
# Disable incremental mode
25+
"incremental": "false",
2526
# Directory where generated Java sources files are written to
2627
"javaOutputDir": "{generatedSources}",
2728
# Directory where generated Kotlin sources files are written to
2829
"kotlinOutputDir": "{generatedSources}",
30+
# TODO(bencodes) Not sure what this directory is yet.
31+
"kspOutputDir": "{temp}",
32+
# projectBaseDir shouldn't matter because incremental is disabled
33+
"projectBaseDir": "{temp}",
2934
# Directory where META-INF data is written to. This might not be the most ideal place to
3035
# write this. Maybe just directly to the classes directory?
3136
"resourceOutputDir": "{generatedSources}",
32-
# TODO(bencodes) Not sure what this directory is yet.
33-
"kspOutputDir": "{temp}",
34-
# Directory to write KSP caches. Shouldn't matter because incremental is disabled
35-
"cachesDir": "{temp}",
36-
# Include in compilation as an example. This should be processed in the stubs phase.
37-
"withCompilation": "true",
3837
# Set returnOkOnError to false because we want to fail the build if there are any errors
3938
"returnOkOnError": "false",
40-
"allWarningsAsErrors": "false",
39+
# Include in compilation as an example. This should be processed in the stubs phase.
40+
"withCompilation": "true",
4141
},
4242
visibility = ["//visibility:public"],
4343
deps = [

kotlin/internal/jvm/compile.bzl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,16 @@ def _build_resourcejar_action(ctx, extra_resources = {}):
305305
"""
306306
resources_jar_output = ctx.actions.declare_file(ctx.label.name + "-resources.jar")
307307
zipper_args = _resourcejar_args_action(ctx, extra_resources)
308-
ctx.actions.run_shell(
308+
ctx.actions.run(
309309
mnemonic = "KotlinZipResourceJar",
310+
executable = ctx.executable._zipper,
310311
inputs = ctx.files.resources + extra_resources.values() + [zipper_args],
311-
tools = [ctx.executable._zipper],
312312
outputs = [resources_jar_output],
313-
command = "{zipper} c {resources_jar_output} @{path}".format(
314-
path = zipper_args.path,
315-
resources_jar_output = resources_jar_output.path,
316-
zipper = ctx.executable._zipper.path,
317-
),
313+
arguments = [
314+
"c",
315+
resources_jar_output.path,
316+
"@" + zipper_args.path,
317+
],
318318
progress_message = "Creating intermediate resource jar %{label}",
319319
)
320320
return resources_jar_output
@@ -390,8 +390,8 @@ def _run_kapt_builder_actions(
390390
plugins = plugins,
391391
outputs = {
392392
"generated_java_srcjar": ap_generated_src_jar,
393-
"kapt_generated_stub_jar": kapt_generated_stub_jar,
394393
"kapt_generated_class_jar": kapt_generated_class_jar,
394+
"kapt_generated_stub_jar": kapt_generated_stub_jar,
395395
},
396396
build_kotlin = False,
397397
mnemonic = "KotlinKapt",
@@ -433,8 +433,8 @@ def _run_ksp_builder_actions(
433433
transitive_runtime_jars = transitive_runtime_jars,
434434
plugins = plugins,
435435
outputs = {
436-
"ksp_generated_java_srcjar": ksp_generated_java_srcjar,
437436
"ksp_generated_classes_jar": ksp_generated_classes_jar,
437+
"ksp_generated_java_srcjar": ksp_generated_java_srcjar,
438438
},
439439
build_kotlin = False,
440440
mnemonic = "KotlinKsp",
@@ -832,8 +832,8 @@ def _run_kt_java_builder_actions(
832832
if not "kt_abi_plugin_incompatible" in ctx.attr.tags and toolchains.kt.experimental_use_abi_jars == True:
833833
kt_compile_jar = ctx.actions.declare_file(ctx.label.name + "-kt.abi.jar")
834834
outputs = {
835-
"output": kt_runtime_jar,
836835
"abi_jar": kt_compile_jar,
836+
"output": kt_runtime_jar,
837837
}
838838
else:
839839
kt_compile_jar = kt_runtime_jar

kotlin/internal/jvm/impl.bzl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ def _write_launcher_action(ctx, rjars, main_class, jvm_flags):
105105
output = ctx.outputs.executable,
106106
substitutions = {
107107
"%classpath%": classpath,
108-
"%runfiles_manifest_only%": "",
109108
"%java_start_class%": "com.google.testing.coverage.JacocoCoverageRunner",
110109
"%javabin%": java_bin,
111110
"%jvm_flags%": jvm_flags,
112-
"%set_jacoco_metadata%": "export JACOCO_METADATA_JAR=\"$JAVA_RUNFILES/{}/{}\"".format(ctx.workspace_name, jacoco_metadata_file.short_path),
113-
"%set_jacoco_main_class%": """export JACOCO_MAIN_CLASS={}""".format(main_class),
111+
"%needs_runfiles%": "0" if _is_absolute(java_bin_path) else "1",
112+
"%runfiles_manifest_only%": "",
114113
"%set_jacoco_java_runfiles_root%": """export JACOCO_JAVA_RUNFILES_ROOT=$JAVA_RUNFILES/{}/""".format(ctx.workspace_name),
114+
"%set_jacoco_main_class%": """export JACOCO_MAIN_CLASS={}""".format(main_class),
115+
"%set_jacoco_metadata%": "export JACOCO_METADATA_JAR=\"$JAVA_RUNFILES/{}/{}\"".format(ctx.workspace_name, jacoco_metadata_file.short_path),
115116
"%set_java_coverage_new_implementation%": """export JAVA_COVERAGE_NEW_IMPLEMENTATION=YES""",
116-
"%workspace_prefix%": ctx.workspace_name + "/",
117117
"%test_runtime_classpath_file%": "export TEST_RUNTIME_CLASSPATH_FILE=${JAVA_RUNFILES}",
118-
"%needs_runfiles%": "0" if _is_absolute(java_bin_path) else "1",
118+
"%workspace_prefix%": ctx.workspace_name + "/",
119119
},
120120
is_executable = True,
121121
)
@@ -130,17 +130,17 @@ def _write_launcher_action(ctx, rjars, main_class, jvm_flags):
130130
output = ctx.outputs.executable,
131131
substitutions = {
132132
"%classpath%": classpath,
133-
"%runfiles_manifest_only%": "",
134133
"%java_start_class%": main_class,
135134
"%javabin%": java_bin,
136135
"%jvm_flags%": jvm_flags,
137-
"%set_jacoco_metadata%": "",
138-
"%set_jacoco_main_class%": "",
136+
"%needs_runfiles%": "0" if _is_absolute(java_bin_path) else "1",
137+
"%runfiles_manifest_only%": "",
139138
"%set_jacoco_java_runfiles_root%": "",
139+
"%set_jacoco_main_class%": "",
140+
"%set_jacoco_metadata%": "",
140141
"%set_java_coverage_new_implementation%": """export JAVA_COVERAGE_NEW_IMPLEMENTATION=NO""",
141-
"%workspace_prefix%": ctx.workspace_name + "/",
142142
"%test_runtime_classpath_file%": "export TEST_RUNTIME_CLASSPATH_FILE=${JAVA_RUNFILES}",
143-
"%needs_runfiles%": "0" if _is_absolute(java_bin_path) else "1",
143+
"%workspace_prefix%": ctx.workspace_name + "/",
144144
},
145145
is_executable = True,
146146
)
@@ -333,8 +333,8 @@ def kt_jvm_junit_test_impl(ctx):
333333

334334
_KtCompilerPluginClasspathInfo = provider(
335335
fields = {
336-
"reshaded_infos": "list reshaded JavaInfos of a compiler library",
337336
"infos": "list JavaInfos of a compiler library",
337+
"reshaded_infos": "list reshaded JavaInfos of a compiler library",
338338
},
339339
)
340340

0 commit comments

Comments
 (0)