def copy_to_workspace(name, srcs, dstdir = ""): if dstdir.startswith("/") or dstdir.startswith("\\"): fail("Subdirectory must be a relative path: " + dstdir) src_locations = " ".join(["$(locations %s)" % (src,) for src in srcs]) native.genrule( name = name, srcs = srcs, outs = [name + ".out"], # Keep this Bash script equivalent to the batch script below (or take out the batch script) cmd = r""" mkdir -p -- {dstdir} for f in {locations}; do rm -f -- {dstdir}$${{f##*/}} cp -f -- "$$f" {dstdir} done date > $@ """.format( locations = src_locations, dstdir = "." + ("/" + dstdir.replace("\\", "/")).rstrip("/") + "/", ), # Keep this batch script equivalent to the Bash script above (or take out the batch script) cmd_bat = """ ( if not exist {dstdir} mkdir {dstdir} ) && ( for %f in ({locations}) do @( (if exist {dstdir}%~nxf del /f /q {dstdir}%~nxf) && copy /B /Y %f {dstdir} >NUL ) ) && >$@ echo %TIME% """.replace("\r", "").replace("\n", " ").format( locations = src_locations, dstdir = "." + ("\\" + dstdir.replace("/", "\\")).rstrip("\\") + "\\", ), local = 1, )