Skip to content

Conversation

hanneskaeufler
Copy link
Contributor

@hanneskaeufler hanneskaeufler commented Jun 24, 2022

This enables windows linting support with the ktlint_test rule.
Previously this rule would fail such as:

cd examples/trivial && bazel test //... --enable_runfiles -s --test_output=all
ERROR(tools/test/windows/tw.cc:1294) ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\xxxx\s7xd2g5q\execroot\__main__\bazel-out\x64_windows-fastbuild\bin\app\lint_test.runfiles\__main__\app\lint_test"): %1 ist keine zulssige Win32-Anwendung.
 (error: 193)
ERROR(tools/test/windows/tw.cc:1451) Failed to start test process (arg: C:\users\xxxx\_bazel_xxxx\s7xd2g5q\execroot\__main__\bazel-out\x64_windows-fastbuild\bin\app\lint_test.runfiles\__main__\app\lint_test)

Now it runs successfully. However, the actual files being linted there fail the linter due to wrong indentation.
I'll probably also submit a PR that fixes indentation so we can run test //... on CI for the trivial examples.
Included in this PR now is also the CI changes to proof that it works.

This helper is an exact copy of the file
from
https://github.com/aspect-build/bazel-lib/blob/df04df7cd2b9a481787de1cb43a6fe05f67c9511/lib/windows_utils.bzl
Which in turn I believe borrows heavily from
rules_nodejs and bazel internal helpers.
Unfortunately, the existing shell script
is not launchable by the default windows
CreateProcess command.
See https://bazel.build/rules/windows_tips#actions
for recommendations on how to handle this.
I opted to deal with it in the same way
as rules_nodejs does.
@hanneskaeufler hanneskaeufler changed the title Hk lint windows support ktlint_test windows support Jun 24, 2022
Taking https://bazel.build/rules/depsets and
https://bazel.build/rules/performance into account,
it is better not to call `to_list()` on a depset.
@hanneskaeufler hanneskaeufler marked this pull request as ready for review June 24, 2022 11:54
@Bencodes
Copy link
Collaborator

Bencodes commented Jun 24, 2022

@hanneskaeufler can you include this in the windows CI PR so that we can validate if this works?

This also ensures both the build as well as
the test are run for windows and linux.

Previously, the tests, and thus the lint
target, was not run. Hence it was not
apparent that the target failed, because
the sample app is formatted incorrectly.
This makes the tests in this
example pass for both windows
and linux
So no need to specify options for all
of them.
As mentioned in the rule docs.
@hanneskaeufler
Copy link
Contributor Author

hanneskaeufler commented Jun 24, 2022

@hanneskaeufler can you include this in the windows CI PR so that we can validate if this works?

Yeah sure @Bencodes, I was contemplating how to do this since actually the linux example stage did not test the linter at all as well, and as mentioned in the description the file was not formatted to pass the linter. But I assume now that this was not intentional and thus enabled the tests in the example stage for both windows and linux by reformatting the file.

Enabled now in this PR and passing 🍒


data class Foo(val name: String, val age: Int)

class Query {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hanneskaeufler Did you mean to pull in these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, file needed to be reformatted to pass the linter

@Bencodes Bencodes merged commit 501cd62 into bazelbuild:master Jun 25, 2022
@jesseschalken
Copy link
Contributor

Could the same code be used to enable Windows support for kt_jvm_binary and kt_jvm_test?

@hanneskaeufler
Copy link
Contributor Author

hanneskaeufler commented Jun 25, 2022

Probably something along those lines should work, I will be looking into that over the coming week(s). I just started with the linter because that was easiest to get familiar with the codebase 😂

@hanneskaeufler hanneskaeufler deleted the hk-lint-windows-support branch June 25, 2022 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants