Support data properties for test binaries

Allow tests to specify a data property that lists files or filegroup
modules that will be packaged alongside the test.  Also add a path
property to filegroup modules to allow shifting the path of the
packaged files, and add ExpandSourcesSubDir to expand the filegroup
sources while including a shifted relative path in the Paths objects.

Test: soong tests, manually adding data to a module
Change-Id: I52a48942660e12755d313ef13279313361b4fc35
diff --git a/cc/test.go b/cc/test.go
index f60996c..d3556bf 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -19,9 +19,8 @@
 	"runtime"
 	"strings"
 
-	"github.com/google/blueprint"
-
 	"android/soong/android"
+	"github.com/google/blueprint"
 )
 
 type TestProperties struct {
@@ -38,6 +37,10 @@
 	// relative_install_path. Useful if several tests need to be in the same
 	// directory, but test_per_src doesn't work.
 	No_named_install_directory *bool
+
+	// list of files or filegroup modules that provide data that should be installed alongside
+	// the test
+	Data []string
 }
 
 func init() {
@@ -191,6 +194,7 @@
 	*binaryDecorator
 	*baseCompiler
 	Properties TestBinaryProperties
+	data       android.Paths
 }
 
 func (test *testBinary) linkerProps() []interface{} {
@@ -205,6 +209,8 @@
 }
 
 func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
+	android.ExtractSourcesDeps(ctx, test.Properties.Data)
+
 	deps = test.testDecorator.linkerDeps(ctx, deps)
 	deps = test.binaryDecorator.linkerDeps(ctx, deps)
 	return deps
@@ -217,6 +223,8 @@
 }
 
 func (test *testBinary) install(ctx ModuleContext, file android.Path) {
+	test.data = ctx.ExpandSources(test.Properties.Data, nil)
+
 	test.binaryDecorator.baseInstaller.dir = "nativetest"
 	test.binaryDecorator.baseInstaller.dir64 = "nativetest64"