-1

essentially all I want is cp -r src/ dist/, but for some reason I simply cannot get this to work.

Currently I am trying:

filegroup(
    name = "src_files",
    srcs = glob([
        "src/**",
    ]),
)
filegroup(
    name = "dist_files",
    srcs = glob([
        "dist/**"
    ]),
)
genrule(
    name = "copy",
    srcs = ["//packages/variables:src_files"],
    outs = ["//packages/variables:dist_files"],
    cmd = "cp -R $(locations //packages/variables:src_files) $(locations //packages/variables:dist_files)"
)

I've gone through at least 4 pages of google and the docs, but it seems unless I create a genrule and manually specify all 100 files in the rule it won't work?

Jon L
  • 27
  • 4
  • 3
    What are you aiming to achieve with the copy? Is there a particular downstream rule that you want to provide these as input to? Generally you shouldn't need to copy the files within a rule on its own; if this for some kind of output then you might want to look at `rules_pkg` and generate a tar ball which you then extract in another step to the correct directory location. – James Sharpe Sep 14 '20 at 18:29
  • @JamesSharpe this is exactly what I needed! thanks, updating the post with solution – Jon L Sep 14 '20 at 22:32

1 Answers1

1

@JamesSharpe had what I was missing, updated the BUILD file to:

filegroup(
    name = "src_files",
    srcs = glob([
        "src/**",
    ]),
)
pkg_tar(
    name = "pack_srcs",
    extension = "tar.gz",
    srcs = [":src_files"],
)
genrule(
    name = "unpack_to_dist",
    srcs = [":pack_srcs"],
    outs = ["dist"],
    cmd = "mkdir $(RULEDIR)/dist && tar -C $(RULEDIR)/dist -zxvf $(SRCS)"
)

And was able to successfully pass this on to the downstream rule.

Jon L
  • 27
  • 4