Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed May 7, 2024
1 parent 620fa22 commit 1fa0885
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gazelle_examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: (cd examples/gazelle && bazelisk --bazelrc=../../.github/workflows/ci.bazelrc run --enable_bzlmod //:gazelle && bazelisk --bazelrc=../../.github/workflows/ci.bazelrc test --enable_bzlmod //...)
run: (cd examples/gazelle && bazelisk --bazelrc=../../.github/workflows/ci.bazelrc run --enable_bzlmod //:gazelle && echo DWH && cat src/test/com/example/gazelle/BUILD.bazel && echo /DWH && bazelisk --bazelrc=../../.github/workflows/ci.bazelrc test --enable_bzlmod //...)
5 changes: 5 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ bazel_dep(
version = "0.34.0",
repo_name = "bazel_gazelle",
)
git_override(
module_name = "gazelle",
remote = "https://github.com/illicitonion/bazel-gazelle.git",
commit = "c054f6422d73309dd03dba9f7e82c4effe726dcf",
)
bazel_dep(
name = "protobuf",
version = PROTOBUF_VERSION,
Expand Down
13 changes: 13 additions & 0 deletions examples/gazelle/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ bazel_dep(
name = "bazel_skylib",
version = "1.5.0",
)

git_override(
module_name = "bazel_skylib",
remote = "https://github.com/illicitonion/bazel-skylib.git",
commit = "fbaa539e21f33fac9243df5d72f354e0985f0a68",
)

bazel_dep(
name = "rules_jvm_external",
version = "6.0",
Expand Down Expand Up @@ -43,3 +50,9 @@ bazel_dep(
name = "gazelle",
version = "0.34.0",
)

git_override(
module_name = "gazelle",
remote = "https://github.com/illicitonion/bazel-gazelle.git",
commit = "e2d30acab3ad2bf057f223b611ad9a352e6aad2c",
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
load("@contrib_rules_jvm//java:defs.bzl", "java_test_suite")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")

genquery(
name = "generated_targets",
expression = "kind(java_test, deps(//src/test/com/github/bazel_contrib/contrib_rules_jvm/examples/gazelle:gazelle))",
expression = "kind(java_test, deps(//src/test/com/example/gazelle:gazelle))",
opts = ["--output=label_kind"],
scope = ["//src/test/com/github/bazel_contrib/contrib_rules_jvm/examples/gazelle"],
scope = ["//src/test/com/example/gazelle"],
)

diff_test(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.bazel_contrib.contrib_rules_jvm.examples.gazelle;
package com.example.gazelle;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java_test rule //src/test/com/example/gazelle:ExampleTest

This file was deleted.

7 changes: 4 additions & 3 deletions java/gazelle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,18 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
}
allPackageNames.Add(mJavaPkg.Name)

mRelFilepath := filepath.FromSlash(mRel)
if !mJavaPkg.TestPackage {
addNonLocalImportsAndExports(productionJavaImports, nonLocalJavaExports, mJavaPkg.ImportedClasses, mJavaPkg.ImportedPackagesWithoutSpecificClasses, mJavaPkg.ExportedClasses, mJavaPkg.Name, javaClassNamesFromFileNames)
for _, f := range mJavaPkg.Files.SortedSlice() {
productionJavaFiles.Add(filepath.Join(mRel, f))
productionJavaFiles.Add(filepath.Join(mRelFilepath, f))
}
allMains.AddAll(mJavaPkg.Mains)
} else {
// Tests don't get to export things, as things shouldn't depend on them.
addNonLocalImportsAndExports(testJavaImports, nil, mJavaPkg.ImportedClasses, mJavaPkg.ImportedPackagesWithoutSpecificClasses, mJavaPkg.ExportedClasses, mJavaPkg.Name, javaClassNamesFromFileNames)
for _, f := range mJavaPkg.Files.SortedSlice() {
path := filepath.Join(mRel, f)
path := filepath.Join(mRelFilepath, f)
file := javaFile{
pathRelativeToBazelWorkspaceRoot: path,
pkg: mJavaPkg.Name,
Expand All @@ -163,7 +164,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
}
allMains.AddAll(javaPkg.Mains)
for _, f := range javaFilenamesRelativeToPackage {
path := filepath.Join(args.Rel, f)
path := filepath.Join(filepath.FromSlash(args.Rel), f)
if javaPkg.TestPackage {
file := javaFile{
pathRelativeToBazelWorkspaceRoot: path,
Expand Down

0 comments on commit 1fa0885

Please sign in to comment.