Browse Source

Added patches to OIIO source to fix rpaths and pthreads linking, and fixed up tests to account for rpaths being correct now

Signed-off-by: Chris Galvan <[email protected]>
Chris Galvan 3 years ago
parent
commit
e7336aade8

+ 46 - 15
package-system/openimageio-opencolorio/build_openimageio.py

@@ -153,8 +153,10 @@ def exec_and_exit_if_failed(invoke_params, cwd=script_folder, shell=False):
 def clone_repo(url, tag, dest_folder):
     if pathlib.Path(dest_folder).exists():
         print(f"Not re-cloning {url} to {dest_folder} becuase it already exists (use --clean to clean fully)")
+        exec_and_exit_if_failed(['git', 'fetch'], cwd=dest_folder)
         exec_and_exit_if_failed(['git', 'clean', '-f'], cwd=dest_folder)
         exec_and_exit_if_failed(['git', 'restore', '.'], cwd=dest_folder)
+        exec_and_exit_if_failed(['git', 'reset', '--hard', tag], cwd=dest_folder)
     else:
         exec_and_exit_if_failed(['git', 'clone', '--depth=1', '--single-branch', '--depth=1', '--recursive',
               '-b', tag,   
@@ -659,7 +661,8 @@ def BuildOpenImageIO(release=True):
 if not SKIP_OPENIMAGEIO:
     print("\n----------------------------- BUILD OpenImageIO ------------------------------")
 
-    clone_repo(openimageio_repository_url, openimageio_repository_tag, source_folder_path / 'openimageio')
+    oiio_source_path = source_folder_path / 'openimageio'
+    clone_repo(openimageio_repository_url, openimageio_repository_tag, oiio_source_path)
 
     if openimageio_build_folder.exists():
         shutil.rmtree(str(openimageio_build_folder.resolve()), ignore_errors=True)
@@ -673,7 +676,22 @@ if not SKIP_OPENIMAGEIO:
 
     # openimageio looks for OpenColorIO in a way that is not compatible with generated configs.
     # remove its find file, allow it to just use the OpenColorIO_ROOT:
-    os.remove(source_folder_path / 'openimageio' / 'src' / 'cmake' / 'modules' / 'FindOpenColorIO.cmake' )
+    os.remove(oiio_source_path / 'src' / 'cmake' / 'modules' / 'FindOpenColorIO.cmake' )
+
+    # The OIIO cmake sets CMAKE_INSTALL_RPATH_USE_LINK_PATH to TRUE, which will
+    # cause anything in the link path to be appended to the RPATH, which results
+    # in absolute paths to boost and other dependencies that we dont' want in there
+    # so we need to patch it to prevent that
+    patch_file_path = script_folder / 'disable_rpath_use_link_path.patch'
+    patch_cmd = ['git', 'apply', '--ignore-whitespace', str(patch_file_path.absolute())]
+    exec_and_exit_if_failed(patch_cmd, cwd=oiio_source_path)
+
+    # On Linux only, we need to also patch to make sure the pthreads is linked
+    # appropriately, otherwise specifically the testtex executable will fail to link
+    if args.platform == "linux":
+        pthread_patch_file_path = script_folder / 'linux_pthreads_fix.patch'
+        pthread_patch_cmd = ['git', 'apply', '--ignore-whitespace', str(pthread_patch_file_path.absolute())]
+        exec_and_exit_if_failed(pthread_patch_cmd, cwd=oiio_source_path)
 
     # On windows only, we also need to do a debug build
     # We do the debug build before the release because the
@@ -797,6 +815,7 @@ elif args.platform == 'windows':
 else: # linux
     shared_lib_suffix = '.so'
 
+test_shared_libs_dir = None
 def TestOpenImageIO(release=True):
     build_type = 'Release' if release else 'Debug'
     test_configure_command = [
@@ -866,9 +885,21 @@ def TestOpenImageIO(release=True):
         ocio_version_suffix = ''
         shared_lib_dir = 'lib'
 
-    shutil.copy2(src=final_package_image_root / 'OpenColorIO' / shared_lib_dir / f'{lib_prefix}OpenColorIO{ocio_debug}{ocio_version_suffix}{shared_lib_suffix}', dst=test_executable_dir)
-    shutil.copy2(src=final_package_image_root / 'OpenImageIO' / shared_lib_dir / f'{lib_prefix}OpenImageIO{oiio_debug}{shared_lib_suffix}', dst=test_executable_dir)
-    shutil.copy2(src=final_package_image_root / 'OpenImageIO' / shared_lib_dir / f'{lib_prefix}OpenImageIO_Util{oiio_debug}{shared_lib_suffix}', dst=test_executable_dir)
+    ocio_lib = final_package_image_root / 'OpenColorIO' / shared_lib_dir / f'{lib_prefix}OpenColorIO{ocio_debug}{ocio_version_suffix}{shared_lib_suffix}*'
+    oiio_lib = final_package_image_root / 'OpenImageIO' / shared_lib_dir / f'{lib_prefix}OpenImageIO{oiio_debug}{shared_lib_suffix}*'
+    oiio_util_lib = final_package_image_root / 'OpenImageIO' / shared_lib_dir / f'{lib_prefix}OpenImageIO_Util{oiio_debug}{shared_lib_suffix}*'
+
+    # Copy all of the OIIO and OCIO shared libs into the test directory to simulate
+    # being copied as runtime dependencies
+    for shared_lib in [ocio_lib, oiio_lib, oiio_util_lib]:
+        for file_path in glob.glob(shared_lib.as_posix()):
+            shutil.copy2(src=file_path, dst=test_executable_dir, follow_symlinks=False)
+
+    # For the release build only, we will re-use this test_executable_dir to
+    # test the python bindings later since we've already copied the shared libs into it
+    if release:
+        global test_shared_libs_dir
+        test_shared_libs_dir = test_executable_dir
 
     exec_and_exit_if_failed(test_exec_command, cwd=test_script_folder)
 
@@ -895,17 +926,17 @@ if args.platform == 'windows':
 else:
     ocio_site_packages = final_package_image_root / 'OpenColorIO' / 'lib' / 'python3.7' / 'site-packages'
 
-# Insert our site-packages folders with the pyds into the sys.path so that the test can
-# import from them, as well as our actual test scripts folder so we can import the tests
+# Copy our site-packages pyd's for OIIO/OCIO into our test directory where
+# we've already copied all the OIIO/OCIO shared libraries to simulate
+# them being copied to the bin directory as runtime dependencies
+for site_packages_dir in [oiio_site_packages, ocio_site_packages]:
+    for file_path in glob.glob((site_packages_dir / '*.*').as_posix()):
+        shutil.copy2(src=file_path, dst=test_shared_libs_dir)
+
+# Insert our test scripts folder into the sys.path so that we can import the tests
+# As well as the test_shared_libs_dir that has the python bindings
 sys.path.insert(1, str(test_script_folder.absolute().resolve()))
-sys.path.insert(1, str(oiio_site_packages.absolute().resolve()))
-sys.path.insert(1, str(ocio_site_packages.absolute().resolve()))
-
-# Also need to add OpenColorIO and OpenImageIO bin directories to the PATH
-# so their shared libs can be found
-ocio_bin = final_package_image_root / 'OpenColorIO' / 'bin'
-oiio_bin = final_package_image_root / 'OpenImageIO' / 'bin'
-os.environ["PATH"] = f"{str(ocio_bin.absolute().resolve())}{os.pathsep}{str(oiio_bin.absolute().resolve())}{os.pathsep}{os.environ['PATH']}"
+sys.path.insert(1, str(test_shared_libs_dir.absolute().resolve()))
 
 from python_tests import test_OpenImageIO, test_OpenColorIO
 

+ 13 - 0
package-system/openimageio-opencolorio/disable_rpath_use_link_path.patch

@@ -0,0 +1,13 @@
+diff --git a/src/cmake/compiler.cmake b/src/cmake/compiler.cmake
+index 185a3fb..df3357c 100644
+--- a/src/cmake/compiler.cmake
++++ b/src/cmake/compiler.cmake
+@@ -567,7 +567,7 @@ else ()
+     endif ()
+     # add the automatically determined parts of the RPATH that
+     # point to directories outside the build tree to the install RPATH
+-    set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
++    set (CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
+     if (VERBOSE)
+         message (STATUS "CMAKE_INSTALL_RPATH = ${CMAKE_INSTALL_RPATH}")
+     endif ()

+ 16 - 0
package-system/openimageio-opencolorio/linux_pthreads_fix.patch

@@ -0,0 +1,16 @@
+diff --git a/src/libOpenImageIO/CMakeLists.txt b/src/libOpenImageIO/CMakeLists.txt
+index 312ae44..be93f75 100644
+--- a/src/libOpenImageIO/CMakeLists.txt
++++ b/src/libOpenImageIO/CMakeLists.txt
+@@ -121,6 +121,11 @@ endif ()
+ # Propagate C++ minimum to downstream
+ target_compile_features (OpenImageIO PUBLIC cxx_std_14)
+ 
++find_package (Threads)
++if (CMAKE_USE_PTHREADS_INIT)
++    target_link_libraries(OpenImageIO INTERFACE ${CMAKE_THREAD_LIBS_INIT})
++endif ()
++
+ target_link_libraries (OpenImageIO
+         PUBLIC
+             OpenImageIO_Util