Add an optional flag for listing corpus paths in lines instead of sep… (#137)

* Add an optional flag for listing corpus paths in lines instead of separated by comma. This is to support corpus paths that contain commas.

* Use the list file flag to support corpus paths with commas.
diff --git a/fuzzing/private/common.bzl b/fuzzing/private/common.bzl
index d263e5e..a72dd53 100644
--- a/fuzzing/private/common.bzl
+++ b/fuzzing/private/common.bzl
@@ -79,15 +79,19 @@
 )
 
 def _fuzzing_corpus_impl(ctx):
+    corpus_list_file_args = ctx.actions.args()
+    corpus_list_file_args.set_param_file_format("multiline")
+    corpus_list_file_args.use_param_file("--corpus_list_file=%s", use_always = True)
+    corpus_list_file_args.add_all(ctx.files.srcs)
+
     corpus_dir = ctx.actions.declare_directory(ctx.attr.name)
     cp_args = ctx.actions.args()
-    cp_args.add_joined("--corpus_list", ctx.files.srcs, join_with = ",")
     cp_args.add("--output_dir=" + corpus_dir.path)
 
     ctx.actions.run(
         inputs = ctx.files.srcs,
         outputs = [corpus_dir],
-        arguments = [cp_args],
+        arguments = [cp_args, corpus_list_file_args],
         executable = ctx.executable._corpus_tool,
     )
 
diff --git a/fuzzing/tools/make_corpus_dir.py b/fuzzing/tools/make_corpus_dir.py
index 1d81aba..aeae9e3 100644
--- a/fuzzing/tools/make_corpus_dir.py
+++ b/fuzzing/tools/make_corpus_dir.py
@@ -29,10 +29,21 @@
 flags.DEFINE_list("corpus_list", [],
                   "Each element in the list stands for a corpus file")
 
+flags.DEFINE_string("corpus_list_file", None,
+                    "An optional file that lists corpus paths by lines")
+
 flags.DEFINE_string("output_dir", None, "The path of the output directory")
 
 flags.mark_flag_as_required("output_dir")
 
+def expand_corpus_to_file_list(corpus, file_list):
+    if not os.path.exists(corpus):
+        raise FileNotFoundError("file " + corpus + " doesn't exist")
+    if os.path.isdir(corpus):
+        # The first element in glob("dir/**") is "dir/", which needs to be excluded
+        file_list.extend(glob.glob(os.path.join(corpus, "**"), recursive=True)[1:])
+    else:
+        file_list.append(corpus)
 
 def main(argv):
     if not os.path.exists(FLAGS.output_dir):
@@ -40,15 +51,13 @@
 
     expanded_file_list = []
     for corpus in FLAGS.corpus_list:
-        if not os.path.exists(corpus):
-            print("ERROR: file " + corpus + " doesn't exist.", file=stderr)
-            return -1
-        if os.path.isdir(corpus):
-            # The first element in glob("dir/**") is "dir/", which needs to be excluded
-            expanded_file_list += glob.glob(os.path.join(corpus, "**"), recursive=True)[1:]
-        else:
-            expanded_file_list.append(corpus)
-    
+        expand_corpus_to_file_list(corpus, expanded_file_list)
+    if FLAGS.corpus_list_file:
+        with open(FLAGS.corpus_list_file) as corpus_list_file:
+            for corpus_line in corpus_list_file:
+                expand_corpus_to_file_list(
+                    corpus_line.rstrip("\n"), expanded_file_list)
+
     if expanded_file_list:
         for corpus in expanded_file_list:
             dest = os.path.join(FLAGS.output_dir, corpus.replace("/", "-"))