scripts/unit-test: ldconfig should be run before each build

We need to make sure our ld.so.cache is updated for each of the builds
in case a dependency was just installed before running the next one.

Tested:
    Ran on phosphor-net-ipmid and the build still passes.

Change-Id: I1481218a23ed895a8b254f2d18f9973bb498c40d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index c7a94ff..befc801 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -322,6 +322,11 @@
     build_for_testing   Enable options related to testing on the package?
     """
     pkgdir = os.path.join(WORKSPACE, pkg)
+    os.chdir(pkgdir)
+
+    # Refresh dynamic linker run time bindings for dependencies
+    check_call_cmd(pkgdir, 'sudo', '-n', '--', 'ldconfig')
+
     # Build & install this package
     conf_flags = [
         enFlag('silent-rules', False),
@@ -330,7 +335,6 @@
         enFlag('code-coverage', build_for_testing),
         enFlag('valgrind', build_for_testing),
     ]
-    os.chdir(pkgdir)
     # Add any necessary configure flags for package
     if CONFIGURE_FLAGS.get(pkg) is not None:
         conf_flags.extend(CONFIGURE_FLAGS.get(pkg))
@@ -592,8 +596,6 @@
             build_and_install(dep, False)
         top_dir = os.path.join(WORKSPACE, UNIT_TEST_PKG)
         os.chdir(top_dir)
-        # Refresh dynamic linker run time bindings for dependencies
-        check_call_cmd(top_dir, 'sudo', '-n', '--', 'ldconfig')
         # Run package unit tests
         build_and_install(UNIT_TEST_PKG, True)
         run_unit_tests(top_dir)