Recovering an original or exec path from a repository

81 views
Skip to first unread message

Garrett Kajmowicz

unread,
Jul 8, 2021, 5:18:10 PM7/8/21
to bazel-discuss
I'm working on getting out-of-tree linux kernel modules to build. One of the challenges I face is in passing the kernel tree directory path to the Kbuild system.

In my WORKSPACE file I have:
new_local_repository(
    name = "kernel_source_host",
    path = "/storage/infra/kernel_release/linux-4.14.173-src/",
    build_file = "BUILD.generic-kernel",
)

In the BUILD.generic-kernel file I have:
    name = "whole_kernel_tree",
    srcs = glob(["**/*"],
                exclude = [".git/**"]),
)
filegroup(
    name = "config_file",
    srcs = [".config"],
)

My BUILD file then looks like this:
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")

filegroup(
    name="nfnetmap_queue_src",
    srcs = [
        "nfnetmap_queue.c",
        "nfnetmap_queue_meta.h",
        "Kbuild",
        "Makefile",
    ],
)

make(
    name = "nfnetmap_queue",
    data = [
        "@kernel_source_host//:whole_kernel_tree",
        "@kernel_source_host//:config_file",
    ],
    targets = ["default"],
    env = {
        "KERNELDIR": MYSTERY_GOES_HERE

    },
    lib_source = ":nfnetmap_queue_src",
    out_binaries = ["nfnetmap_queue.ko"],
)

I'd like the mystery text to be the execpath of my copied kernel source tree.
I've come up with several variations on a theme which fail.

The closest is "$(execpath @kernel_source_host//:config_file)" which gets me the correct execpath of the config file, but not the containing directory.

paths.dirname("$(execpath @kernel_source_host//:config_file)")
seems like it should work, but I end up with complaints of "unterminated $(execpath) expression". Attempts to quote around this haven't gotten me anywhere.

"$(execpath paths.dirname(@kernel_source_host//:config_file))"
seems even less likely to work, and it ends up with invalid target name 'paths.dirname(@kernel_source_host//:config_file': target names may not contain '//' path separators

This seems like something which should be straight-forward to do, but I haven't found any good references.

-     Garrett

Garrett Kajmowicz

unread,
Jul 16, 2021, 12:07:11 PM7/16/21
to bazel-discuss
Are there any ways to generate execpath in Starlark? I couldn't find any obvious examples. I tried searching through the Bazel Java codebase for the implementation and didn't find much that was that useful (lots of noise from parameters named execPath).

-     Garrett

Reply all
Reply to author
Forward
0 new messages