Hi,
I'm working a Java project of about 500,000 lines of code and changing the ant build.xml to bazel BUILD file.
The build.xml has many tasks of copying files in directory trees. For example,
<target name="copy_static">
...
<copy todir="${Common_Template}/Runtime/LegoRuntime/resources/report/dataExport/exportTemplate/lib/lib" overwrite="true">
<fileset dir="${reporterProject}/WebRoot/lib">
<include name="echarts/**/*" />
<exclude name="**/*.svn" />
</fileset>
<fileset dir="${reporterProject}/WebRoot/lib/">
<include name="jquery-mousewheel/**/*" />
<exclude name="**/*.svn" />
</fileset>
<fileset dir="${reporterProject}/WebRoot/lib/">
<include name="tiny/**/*" />
<exclude name="**/*.svn" />
</fileset>
<fileset dir="${reporterProject}/WebRoot/lib/">
<include name="tiny-extra/**/*" />
<exclude name="**/*.svn" />
</fileset>
<fileset dir="${reporterProject}/WebRoot/lib">
<include name="echarts.source.js" />
<include name="require.js" />
</fileset>
</copy>
...
I know genrule() can be used to copy files. However, for copying a large number of files in some directory tree genrule() is too low level
and it is tedious to write code for such genrule() 's srcs/outs/cmd. -- think about listing hundreds and thousands of files in genrule()'s srcs/outs/cmds.
Can bazel provide a rule for such purpose? The rule may has the form as follows:
recursive_copy_dir(
name = "copy1",
srcs = glob(
["dir1/dir2/**/*.java"],
exclude = ["**/dir5/**"], # can exclude files we don't need
) +
glob(["dir3/**/*.java"]), # can have multiple directories in srcs
dst_dir = "dst_dir", # should only have one dst directory.
)
The outs of above rule should be as follows:
dst_dir/**/*.java # files from dir1/dir2 and dir3
':copy1' may be used to refer to the rule's outs; $(location :copy1) may be used to refer to the directory 'dst_dir' (so $(location :copy1)/a.java can refer to a specific file in the outs of the rule).
Thank you very much.
-Leo