2021-02-02 18:20:11 +01:00
|
|
|
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
|
|
|
|
2020-12-20 20:10:45 +01:00
|
|
|
def copy_files(ctx, files):
|
|
|
|
cmds = []
|
|
|
|
inputs = []
|
|
|
|
outputs = []
|
|
|
|
for (src, dst) in files:
|
|
|
|
inputs.append(src)
|
|
|
|
dst = ctx.actions.declare_file(dst)
|
|
|
|
outputs.append(dst)
|
|
|
|
cmds.append("cp -f {} {}".format(src.path, dst.path))
|
|
|
|
|
|
|
|
shell_fname = ctx.label.name + "-cp.sh"
|
|
|
|
shell_file = ctx.actions.declare_file(shell_fname)
|
|
|
|
ctx.actions.write(
|
|
|
|
output = shell_file,
|
|
|
|
content = "#!/bin/bash\nset -e\n" + "\n".join(cmds),
|
|
|
|
is_executable = True,
|
|
|
|
)
|
|
|
|
ctx.actions.run(
|
|
|
|
inputs = inputs,
|
|
|
|
executable = "bash",
|
|
|
|
tools = [shell_file],
|
|
|
|
arguments = [shell_file.path],
|
|
|
|
outputs = outputs,
|
|
|
|
mnemonic = "CopyFile",
|
|
|
|
use_default_shell_env = True,
|
|
|
|
)
|
|
|
|
|
|
|
|
return [DefaultInfo(files = depset(outputs))]
|
2021-01-01 13:45:25 +01:00
|
|
|
|
2021-01-01 14:39:15 +01:00
|
|
|
def remove_prefix(text, prefix):
|
|
|
|
if text.startswith(prefix):
|
|
|
|
return text[len(prefix):]
|
|
|
|
return text
|
|
|
|
|
|
|
|
def copy_select_files(ctx, files, include, exclude, base, unwanted_prefix):
|
2021-01-01 13:45:25 +01:00
|
|
|
wanted = []
|
|
|
|
for f in files.to_list():
|
2021-01-01 14:39:15 +01:00
|
|
|
path = remove_prefix(f.path, base)
|
2021-01-01 13:45:25 +01:00
|
|
|
want = True
|
|
|
|
|
|
|
|
for substr in exclude:
|
2021-01-01 14:39:15 +01:00
|
|
|
if path.startswith(substr):
|
2021-01-01 13:45:25 +01:00
|
|
|
want = False
|
|
|
|
continue
|
|
|
|
if not want:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for substr in include:
|
2021-01-01 14:39:15 +01:00
|
|
|
if path.startswith(substr):
|
|
|
|
output = remove_prefix(path, unwanted_prefix)
|
2021-01-01 13:45:25 +01:00
|
|
|
wanted.append((f, output))
|
|
|
|
|
|
|
|
return copy_files(ctx, wanted)
|
2021-02-02 18:20:11 +01:00
|
|
|
|
2021-04-20 09:33:46 +02:00
|
|
|
def copy_files_into_group(name, package, srcs, dev_srcs = []):
|
2021-02-02 18:20:11 +01:00
|
|
|
outs = []
|
2021-04-20 09:33:46 +02:00
|
|
|
for src in srcs + dev_srcs:
|
2021-02-02 18:20:11 +01:00
|
|
|
copy_file(
|
|
|
|
name = src + "_copy",
|
|
|
|
src = package + ":" + src,
|
|
|
|
out = src,
|
|
|
|
)
|
|
|
|
|
|
|
|
native.filegroup(
|
|
|
|
name = name,
|
2021-04-20 09:33:46 +02:00
|
|
|
srcs = srcs + select({
|
|
|
|
"//:release": [],
|
|
|
|
"//conditions:default": dev_srcs,
|
|
|
|
}),
|
2021-02-02 18:20:11 +01:00
|
|
|
visibility = ["//qt:__subpackages__"],
|
|
|
|
)
|