From 0b8e59f4789b338b2f14855a32fea361b702cbad Mon Sep 17 00:00:00 2001 From: Eric Froemling Date: Mon, 12 Oct 2020 09:40:37 -0700 Subject: [PATCH] Wiring up prefab internal libs to cmake builds --- .efrocachemap | 8 +++--- Makefile | 10 ++++++- ballisticacore-cmake/CMakeLists.txt | 2 +- tools/batools/pcommand.py | 41 +++++++++++++++++++++++++++++ tools/pcommand | 2 +- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/.efrocachemap b/.efrocachemap index bfcf9bf7..dcba6120 100644 --- a/.efrocachemap +++ b/.efrocachemap @@ -3948,8 +3948,8 @@ "build/prefab/lib/linux_x86_64/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/32/03/d4dd9c398eab7c7da62b2e7a4096", "build/prefab/lib/linux_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/11/f5/cb2b3a42e4384d6ac4dfe7a98213", "build/prefab/lib/linux_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/06/aa/fc55996ce9a1a3e898d1348873ff", - "build/prefab/lib/mac_x86_64/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/6b/16/c058434a86f13606cbd6bec7167c", - "build/prefab/lib/mac_x86_64/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/cc/e2/f1ef7e986d9b3cc9e5f2d392def7", - "build/prefab/lib/mac_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/bd/b3/3e5c54b74ce8f4d606e766823903", - "build/prefab/lib/mac_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/5a/5a/077d74f31286ced414f08cbd1f94" + "build/prefab/lib/mac_x86_64/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/7d/48/48c832b29b04ec4ccc261d56603b", + "build/prefab/lib/mac_x86_64/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/ce/5c/d36f3f9da946fbee20c3977b94a4", + "build/prefab/lib/mac_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/ea/ff/eb2be69f12eca21808614649776b", + "build/prefab/lib/mac_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/5f/8c/a767dd7cfd77dcef570feab477f1" } \ No newline at end of file diff --git a/Makefile b/Makefile index 2062ad68..08b5882b 100644 --- a/Makefile +++ b/Makefile @@ -716,6 +716,7 @@ cmake: cmake-build # Build but don't run it. cmake-build: assets-cmake resources code @tools/pcommand cmake_prep_dir build/cmake/$(CM_BT_LC) + @tools/pcommand update_prefab_libs standard ${CM_BT_LC} @${STAGE_ASSETS} -cmake build/cmake/$(CM_BT_LC) @cd build/cmake/$(CM_BT_LC) && test -f Makefile \ || cmake -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \ @@ -730,6 +731,7 @@ cmake-server: cmake-server-build cmake-server-build: assets-cmake resources code @tools/pcommand cmake_prep_dir build/cmake/server-$(CM_BT_LC)/dist + @tools/pcommand update_prefab_libs server ${CM_BT_LC} @${STAGE_ASSETS} -cmakeserver -${CM_BT_LC} build/cmake/server-$(CM_BT_LC) @cd build/cmake/server-$(CM_BT_LC)/dist && test -f Makefile \ || cmake -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) -DHEADLESS=true \ @@ -811,9 +813,15 @@ ENV_SRC = tools/pcommand tools/batools/build.py # CMake build-type lowercase CM_BT_LC = $(shell echo $(CMAKE_BUILD_TYPE) | tr A-Z a-z) +_update-prefab-libs: + @tools/pcommand update_prefab_libs standard ${CM_BT_LC} + +_update-prefab-libs-server: + @tools/pcommand update_prefab_libs server ${CM_BT_LC} + # When using CLion, our cmake dir is root. Expose .clang-format there too. ballisticacore-cmake/.clang-format: .clang-format @cd ballisticacore-cmake && ln -sf ../.clang-format . # Tell make which of these targets don't represent files. -.PHONY: +.PHONY: _cmake-prefab-lib diff --git a/ballisticacore-cmake/CMakeLists.txt b/ballisticacore-cmake/CMakeLists.txt index 4de0a9f7..a1e2aec1 100644 --- a/ballisticacore-cmake/CMakeLists.txt +++ b/ballisticacore-cmake/CMakeLists.txt @@ -186,5 +186,5 @@ target_include_directories(ballisticacore PRIVATE # NOTE: seems we need to add 'dl' here for raspberry pi with a manually # built Python 3.8. Might be able to remove later. target_link_libraries(ballisticacore PRIVATE - ballisticacore_internal ode pthread ${Python_LIBRARIES} + ${CMAKE_CURRENT_BINARY_DIR}/prefablib/libballisticacore_internal.a ode pthread ${Python_LIBRARIES} ${SDL2_LIBRARIES} ${EXTRA_LIBRARIES} dl) diff --git a/tools/batools/pcommand.py b/tools/batools/pcommand.py index 995fdaad..f0fbebef 100644 --- a/tools/batools/pcommand.py +++ b/tools/batools/pcommand.py @@ -683,6 +683,47 @@ def update_project() -> None: Updater(check=check, fix=fix).run() +def update_prefab_libs() -> None: + """Update prefab internal libs for builds.""" + import subprocess + import os + from efro.error import CleanError + import batools.build + if len(sys.argv) != 4: + raise CleanError('Expected 2 args (standard/server, debug/release)') + buildtype = sys.argv[2] + mode = sys.argv[3] + if buildtype not in {'standard', 'server'}: + raise CleanError(f'Invalid buildtype: {buildtype}') + if mode not in {'debug', 'release'}: + raise CleanError(f'Invalid mode: {mode}') + platform = batools.build.get_current_prefab_platform() + suffix = '_server' if buildtype == 'server' else '' + target = (f'build/prefab/lib/{platform}{suffix}/{mode}/' + f'libballisticacore_internal.a') + + # Build the target and then copy it to dst if it doesn't exist there yet + # or the existing one is older than our target. + subprocess.run(['make', target], check=True) + + prefix = 'server-' if buildtype == 'server' else '' + suffix = '/dist' if buildtype == 'server' else '' + libdir = f'build/cmake/{prefix}{mode}{suffix}/prefablib' + libpath = os.path.join(libdir, 'libballisticacore_internal.a') + + update = True + time1 = os.path.getmtime(target) + if os.path.exists(libpath): + time2 = os.path.getmtime(libpath) + if time1 <= time2: + update = False + + if update: + if not os.path.exists(libdir): + os.makedirs(libdir, exist_ok=True) + subprocess.run(['cp', target, libdir], check=True) + + def cmake_prep_dir() -> None: """Create a dir, recreating it when cmake/python/etc. version changes. diff --git a/tools/pcommand b/tools/pcommand index 9a582a34..0e328029 100755 --- a/tools/pcommand +++ b/tools/pcommand @@ -37,7 +37,7 @@ from batools.pcommand import ( list_pip_reqs, install_pip_reqs, checkenv, ensure_prefab_platform, prefab_run_var, make_prefab, update_makebob, lazybuild, android_archive_unstripped_libs, efro_gradle, stage_assets, - update_assets_makefile, update_project, cmake_prep_dir) + update_assets_makefile, update_project, update_prefab_libs, cmake_prep_dir) # pylint: enable=unused-import if TYPE_CHECKING: