Fix copy_files implementation

It has to copy all the files into the same directory, stripping the
relative path from the source file.

Bug: 193540681
Test: rbcrun build/make/tests/run.rbc
Change-Id: I2d61d966ad94d73131c7ad6016ce319f8d2ae509
diff --git a/core/product_config.rbc b/core/product_config.rbc
index b6a79cb..ef0d0c9 100644
--- a/core/product_config.rbc
+++ b/core/product_config.rbc
@@ -373,9 +373,14 @@
         if type(val) == "list":
             val.append(_indirect(pcm_name))
 
+def __base(path):
+    """Returns basename."""
+    return path.rsplit("/",1)[-1]
+
+
 def _copy_files(l, outdir):
     """Generate <item>:<outdir>/item for each item."""
-    return ["%s:%s/%s" % (item, outdir, item) for item in __words(l)]
+    return ["%s:%s/%s" % (path, outdir, __base(path)) for path in __words(l)]
 
 def _copy_if_exists(path_pair):
     """If from file exists, returns [from:to] pair."""
diff --git a/tests/device.rbc b/tests/device.rbc
index c91a487..feefcf7 100644
--- a/tests/device.rbc
+++ b/tests/device.rbc
@@ -48,6 +48,8 @@
   cfg["PRODUCT_COPY_FILES"] += (rblf.find_and_copy("audio_platform_info*.xml", "device/google/redfin", "||VENDOR-PATH-PH||/etc") +
       ["xyz:/etc/xyz"])
   cfg["PRODUCT_COPY_FILES"] += rblf.copy_files("x.xml y.xml", "/etc")
+  cfg["PRODUCT_COPY_FILES"] += rblf.copy_files(["from/sub/x", "from/sub/y"], "to")
+
   rblf.add_soong_config_namespace(g, "NS1")
   rblf.add_soong_config_var_value(g, "NS1", "v1", "abc")
   rblf.add_soong_config_var_value(g, "NS1", "v2", "def")
diff --git a/tests/run.rbc b/tests/run.rbc
index e392e47..4d7166a 100644
--- a/tests/run.rbc
+++ b/tests/run.rbc
@@ -57,6 +57,8 @@
           "xyz:/etc/xyz",
           "x.xml:/etc/x.xml",
           "y.xml:/etc/y.xml",
+          "from/sub/x:to/x",
+          "from/sub/y:to/y",
       ],
       "PRODUCT_HOST_PACKAGES": ["host"],
       "PRODUCT_PACKAGES": [