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

Error when using AutoBazelRepository annotation processor #1095

Open
SanjayVas opened this issue Dec 19, 2023 · 1 comment
Open

Error when using AutoBazelRepository annotation processor #1095

SanjayVas opened this issue Dec 19, 2023 · 1 comment
Assignees

Comments

@SanjayVas
Copy link

My assumption is that kt_jvm_library does not pass -Abazel.repository the way that java_library does. See bazelbuild/bazel#16549

error: The bazel.repository annotation processor option is not set. To use this annotation processor, provide the canonical repository name of the current target as the value of the -Abazel.repository flag.
@ydynnikov
Copy link

+1, had to use dirty workaround

genrule(
    name = "generate_env",
    outs = ["resources_root.env"],
    cmd = "echo $(rlocationpath //path/to/test/resources:test_files_root) > \"$@\"",
    tools = ["//path/to/test/resources:test_files_root"],
)

kt_jvm_test(
    name = "kt-idea-plugins-shared-library-test",
    srcs = ["kotlin/JsonAssemblerTest.kt"],
    resources = [
        # resources_root.env
        ":generate_env"
    ],
    test_class = "some.package.shared.JsonAssemblerTest",
    data = [
        ":generate_env",
        "//path/to/test/resources:test_files" # this is filegroup
    ],
    deps = [
        "//:kotlin_serialization",
        # some more deps
    ],
    env = {
        "REPOSITORY_ROOT_ENVFILE": "path/to/test/resources_root.env"
    }


)

and then in kotlin:

    fun getRepositoryRootPath(): Path {
        // there is file resources_root.env in this jar
        val classLoader = this.javaClass.classLoader
// env file name is in env variable REPOSITORY_ROOT_ENVFILE
        val resourcesRootEnv = classLoader.getResource(
            System.getenv("REPOSITORY_ROOT_ENVFILE")
        ) ?: throw Exception("resources_root.env not found")
        // read it, there is one string that consists repository root path
        val repositoryRootPath = resourcesRootEnv.readText()

        val runfiles = Runfiles.preload()
        val repositoryRootRLocation = runfiles.unmapped().rlocation(repositoryRootPath)

        // the path we have is to file `.test_resources_root` in test resources directory,
        // so we need to get parent of it
        return Path(repositoryRootRLocation).parent
    }

Maybe there is better workaround, but at least this one works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants