Blub
Blub

Reputation: 13614

bazel not finding generated headers

I keep getting the error "No such file or directory myheader.h" when trying to build. Am I doing something conceptually wrong here? I dont get why it wont find the headers, I really dont think that I'm supposed to add a -Ibazel-out/k8-fastbuild/genfiles/mylibrary copts because that path changes depending on command line parameters.

# BUILD file
load(":size.bzl", "size")
size(
    name = "blubhdrs",

    infiles =   [
        "myheader.h", # generates new file with the same name in genfiles
    ]
)

cc_library(
     name = "mylibrary",
     hdrs = [
            ":blubhdrs"
     ],
     srcs = [ "bla.cpp" ] # depends on generated header from :blubhdrs
)


# size.bzl
def _impl(ctx):

    outputfiles = []
    for input in ctx.files.infiles:
        name = input.basename
        myoutputfile = ctx.actions.declare_file(name)
        outputfiles.append(myoutputfile)
        # huge command, not important so I commented it out: 
        # ctx.actions.run_shell(...) 

    return DefaultInfo(files = depset(items = outputfiles))

size = rule(
    implementation = _impl,
    attrs = {
        "infiles": attr.label_list(allow_files = True),
    },
    output_to_genfiles = True
)

Upvotes: 1

Views: 592

Answers (1)

Blub
Blub

Reputation: 13614

Okay, seems like the canonical way is to really do: copts = ["-I$(GENDIR)/myprojectdir"]

Upvotes: 3

Related Questions