Fix: a module with sub_dir can't be placed in APEX

This change fixes the bug that when a module is defined with sub_dir,
then build breaks when the module is included in an APEX.

This was happening because, for example when we have a prebuilt_etc
module having sub_dir set to "foo/bar", then only etc/foo/bar is added
to the canned_fs_config file and other intermediate directories (etc,
etc/foo) are not added. e2fsdroid however expects that every directories
to be listed.

Fixing the problem by adding parent directories when adding a directory
to canned_fs_config.

Bug: 120600179
Test: m (a new test case added to apex_test)
Change-Id: If712ff65761a7e1e3216371bb2eb7acf9cb5dc9e
diff --git a/apex/apex.go b/apex/apex.go
index fdfcf86..5ce0e05 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -684,8 +684,14 @@
 			} else {
 				readOnlyPaths = append(readOnlyPaths, pathInApex)
 			}
-			if !android.InList(f.installDir, executablePaths) {
-				executablePaths = append(executablePaths, f.installDir)
+			dir := f.installDir
+			for !android.InList(dir, executablePaths) && dir != "" {
+				executablePaths = append(executablePaths, dir)
+				dir, _ = filepath.Split(dir) // move up to the parent
+				if len(dir) > 0 {
+					// remove trailing slash
+					dir = dir[:len(dir)-1]
+				}
 			}
 		}
 		sort.Strings(readOnlyPaths)