vndk-def: Fix compute_vndk() w/o generic refs

This commit fixes VNDK computation when generic references are not
specified.

Test: ./tests/test_vndk.py
Change-Id: I345f9bf565843a65eabe082a8e7329b773506e91
diff --git a/vndk/tools/definition-tool/tests/test_vndk.py b/vndk/tools/definition-tool/tests/test_vndk.py
index f03a45e..dc7eb15 100755
--- a/vndk/tools/definition-tool/tests/test_vndk.py
+++ b/vndk/tools/definition-tool/tests/test_vndk.py
@@ -54,12 +54,22 @@
     def test_compute_vndk(self):
         graph, vndk = self._create_graph_vndk('pre_treble', None)
 
-        self.assertEqual(['/system/lib/libcutils.so',
-                          '/system/lib64/libcutils.so'],
+        self.assertEqual(['/system/lib/vndk/libcutils.so',
+                          '/system/lib64/vndk/libcutils.so'],
                          self._get_paths_from_nodes(vndk.vndk_core))
         self.assertEqual([], self._get_paths_from_nodes(vndk.vndk_fwk_ext))
         self.assertEqual([], self._get_paths_from_nodes(vndk.vndk_vnd_ext))
 
+    def test_compute_vndk_indirect_no_gr(self):
+        graph, vndk = self._create_graph_vndk('vndk_indirect', None)
+
+        self.assertEqual(['/system/lib/vndk/libcutils.so',
+                          '/system/lib64/vndk/libcutils.so'],
+                         self._get_paths_from_nodes(vndk.vndk_core))
+        self.assertEqual(['/system/lib/vndk/libcutils_dep.so',
+                          '/system/lib64/vndk/libcutils_dep.so'],
+                         self._get_paths_from_nodes(vndk.vndk_indirect))
+
     def test_compute_vndk_fwk_ext(self):
         graph, vndk = self._create_graph_vndk('vndk_fwk_ext', 'vndk_gr')
 
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libRS.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libRS.so.sym
new file mode 100644
index 0000000..6b2702a
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libRS.so.sym
@@ -0,0 +1,8 @@
+EI_CLASS	32
+EI_DATA		Little-Endian
+E_MACHINE	EM_ARM
+DT_NEEDED	libdl.so
+EXP_SYMBOL	rsContextCreate
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	dlsym
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libc.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libc.so.sym
new file mode 100644
index 0000000..0f9b747
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libc.so.sym
@@ -0,0 +1,12 @@
+EI_CLASS	32
+EI_DATA		Little-Endian
+E_MACHINE	EM_ARM
+DT_NEEDED	libdl.so
+DT_NEEDED	libm.so
+EXP_SYMBOL	fclose
+EXP_SYMBOL	fopen
+EXP_SYMBOL	fread
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	cos
+IMP_SYMBOL	sin
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libcutils.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libcutils.so.sym
new file mode 100644
index 0000000..ba09abf
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libcutils.so.sym
@@ -0,0 +1,10 @@
+EI_CLASS	32
+EI_DATA		Little-Endian
+E_MACHINE	EM_ARM
+DT_NEEDED	libc.so
+DT_NEEDED	libcutils_dep.so
+DT_NEEDED	libdl.so
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	fclose
+IMP_SYMBOL	fopen
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libcutils_dep.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libcutils_dep.so.sym
new file mode 100644
index 0000000..770ee84
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libcutils_dep.so.sym
@@ -0,0 +1,9 @@
+EI_CLASS	32
+EI_DATA		Little-Endian
+E_MACHINE	EM_ARM
+DT_NEEDED	libc.so
+DT_NEEDED	libdl.so
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	fclose
+IMP_SYMBOL	fopen
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libdl.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libdl.so.sym
new file mode 100644
index 0000000..9cfd2a2
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libdl.so.sym
@@ -0,0 +1,6 @@
+EI_CLASS	32
+EI_DATA		Little-Endian
+E_MACHINE	EM_ARM
+EXP_SYMBOL	dlclose
+EXP_SYMBOL	dlopen
+EXP_SYMBOL	dlsym
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libm.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libm.so.sym
new file mode 100644
index 0000000..3919c02
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib/libm.so.sym
@@ -0,0 +1,5 @@
+EI_CLASS	32
+EI_DATA		Little-Endian
+E_MACHINE	EM_ARM
+EXP_SYMBOL	cos
+EXP_SYMBOL	sin
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libRS.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libRS.so.sym
new file mode 100644
index 0000000..95408ef
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libRS.so.sym
@@ -0,0 +1,8 @@
+EI_CLASS	64
+EI_DATA		Little-Endian
+E_MACHINE	EM_AARCH64
+DT_NEEDED	libdl.so
+EXP_SYMBOL	rsContextCreate
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	dlsym
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libc.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libc.so.sym
new file mode 100644
index 0000000..e3843e6
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libc.so.sym
@@ -0,0 +1,12 @@
+EI_CLASS	64
+EI_DATA		Little-Endian
+E_MACHINE	EM_AARCH64
+DT_NEEDED	libdl.so
+DT_NEEDED	libm.so
+EXP_SYMBOL	fclose
+EXP_SYMBOL	fopen
+EXP_SYMBOL	fread
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	cos
+IMP_SYMBOL	sin
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libcutils.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libcutils.so.sym
new file mode 100644
index 0000000..37c0344
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libcutils.so.sym
@@ -0,0 +1,10 @@
+EI_CLASS	64
+EI_DATA		Little-Endian
+E_MACHINE	EM_AARCH64
+DT_NEEDED	libc.so
+DT_NEEDED	libcutils_dep.so
+DT_NEEDED	libdl.so
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	fclose
+IMP_SYMBOL	fopen
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libcutils_dep.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libcutils_dep.so.sym
new file mode 100644
index 0000000..5a4fbf7
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libcutils_dep.so.sym
@@ -0,0 +1,9 @@
+EI_CLASS	64
+EI_DATA		Little-Endian
+E_MACHINE	EM_AARCH64
+DT_NEEDED	libc.so
+DT_NEEDED	libdl.so
+IMP_SYMBOL	dlclose
+IMP_SYMBOL	dlopen
+IMP_SYMBOL	fclose
+IMP_SYMBOL	fopen
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libdl.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libdl.so.sym
new file mode 100644
index 0000000..5e06f27
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libdl.so.sym
@@ -0,0 +1,6 @@
+EI_CLASS	64
+EI_DATA		Little-Endian
+E_MACHINE	EM_AARCH64
+EXP_SYMBOL	dlclose
+EXP_SYMBOL	dlopen
+EXP_SYMBOL	dlsym
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libm.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libm.so.sym
new file mode 100644
index 0000000..e9c0ca4
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/system/lib64/libm.so.sym
@@ -0,0 +1,5 @@
+EI_CLASS	64
+EI_DATA		Little-Endian
+E_MACHINE	EM_AARCH64
+EXP_SYMBOL	cos
+EXP_SYMBOL	sin
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/vendor/lib/libEGL_chipset.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/vendor/lib/libEGL_chipset.so.sym
new file mode 100644
index 0000000..076d58f
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/vendor/lib/libEGL_chipset.so.sym
@@ -0,0 +1,9 @@
+EI_CLASS	32
+EI_DATA		Little-Endian
+E_MACHINE	EM_ARM
+DT_NEEDED	libc.so
+DT_NEEDED	libcutils.so
+DT_NEEDED	libdl.so
+EXP_SYMBOL	eglGetDisplay
+IMP_SYMBOL	fclose
+IMP_SYMBOL	fopen
diff --git a/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/vendor/lib64/libEGL_chipset.so.sym b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/vendor/lib64/libEGL_chipset.so.sym
new file mode 100644
index 0000000..2429b9c
--- /dev/null
+++ b/vndk/tools/definition-tool/tests/testdata/test_vndk/vndk_indirect/vendor/lib64/libEGL_chipset.so.sym
@@ -0,0 +1,9 @@
+EI_CLASS	64
+EI_DATA		Little-Endian
+E_MACHINE	EM_AARCH64
+DT_NEEDED	libc.so
+DT_NEEDED	libcutils.so
+DT_NEEDED	libdl.so
+EXP_SYMBOL	eglGetDisplay
+IMP_SYMBOL	fclose
+IMP_SYMBOL	fopen
diff --git a/vndk/tools/definition-tool/vndk_definition_tool.py b/vndk/tools/definition-tool/vndk_definition_tool.py
index f125f9b..bbe0b74 100755
--- a/vndk/tools/definition-tool/vndk_definition_tool.py
+++ b/vndk/tools/definition-tool/vndk_definition_tool.py
@@ -1314,9 +1314,14 @@
             vndk_core.add(vndk_core_lib)
             return vndk_core_lib
 
+        def add_to_vndk_core(lib):
+            self.rename_lib(lib, PT_SYSTEM, get_vndk_core_lib_name(lib))
+            vndk_core.add(lib)
+
         # Compute vndk-core, vndk-fwk-ext and vndk-vnd-ext.
         if not generic_refs:
-            vndk_core.update(vndk_candidates)
+            for lib in vndk_candidates:
+                add_to_vndk_core(lib)
         else:
             while vndk_candidates:
                 if __debug__:
@@ -1353,10 +1358,6 @@
                         if lib not in user.imported_ext_symbols:
                             replace_linked_lib(user, lib, generic_lib, dep_type)
 
-                def add_to_vndk_core(lib):
-                    self.rename_lib(lib, PT_SYSTEM, get_vndk_core_lib_name(lib))
-                    vndk_core.add(lib)
-
                 def add_to_vndk_fwk_ext(lib, generic_lib):
                     self.rename_lib(lib, PT_SYSTEM,
                                     get_vndk_fwk_ext_lib_name(lib))