Browse Source

Got test/ working with relative dependencies

This was a decent way to test relative dependencies for future
projects. It isn't necessarily pretty, but it mostly works.

Tracy may not work well because the add-cpp-module-dependency tries to
resolve TracyClient.cpp before the pre-build tracy clone has
executed. This will need to be fixed in Cakelisp. A workaround is
commenting that dependency, letting tracy get cloned, then
uncommenting it for the second build.
RelativeDependencies
Macoy Madson 8 months ago
parent
commit
43885fba84
  1. 26
      Build_Debug.sh
  2. 7
      src/Aubio.cake
  3. 52
      src/AutoTest.cake
  4. 13
      src/Dependencies.cake
  5. 5
      src/Ogre.cake
  6. 2
      src/OgreInitialize.cake
  7. 5
      src/Tracy.cake
  8. 33
      test/Build.sh
  9. 2
      test/data/plugins.cfg
  10. 2
      test/data/plugins_d.cfg
  11. 2
      test/src/Config_Linux.cake
  12. 2
      test/src/GamelibMacros.cake
  13. 4
      test/src/Loader.cake
  14. 2
      test/src/MakeHotReload.cake
  15. 4
      test/src/OgreApp.cake
  16. 6
      test/src/SDLOgreApp.cake
  17. 18
      test/src/VocalGame.cake

26
Build_Debug.sh

@ -1,30 +1,6 @@
#!/bin/sh
# Build Cakelisp itself
echo "\n\nCakelisp\n\n"
cd Dependencies/cakelisp
./Build.sh || exit $?
cd ../..
echo "\n\nOgre\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake test/src/OgreApp.cake || exit $?
echo "\n\nSDL Ogre\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake test/src/SDLOgreApp.cake || exit $?
# echo "\n\nAuto Test (Math only)\n\n"
# ./Dependencies/cakelisp/bin/cakelisp --execute test/src/Config_Linux.cake src/AutoTest.cake src/Math.cake || exit $?
echo "\n\nAuto Test\n\n"
./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake src/AutoTest.cake src/SDL.cake src/Math.cake src/Aubio.cake || exit $?
# ./Dependencies/cakelisp/bin/cakelisp test/src/Config_Linux.cake src/AutoTest.cake src/SDL.cake src/Tracy.cake src/Math.cake src/Aubio.cake || exit $?
echo "\n\nVocal Game (hot reload)\n\n"
./Dependencies/cakelisp/bin/cakelisp --verbose-processes test/src/Config_Linux.cake test/src/MakeHotReload.cake test/src/VocalGame.cake || exit $?
echo "\n\nLoader\n\n"
./Dependencies/cakelisp/bin/cakelisp --execute test/src/Config_Linux.cake test/src/Loader.cake || exit $?
echo "\n\nVocal Game (no reload)\n\n"
./Dependencies/cakelisp/bin/cakelisp \
test/src/Config_Linux.cake test/src/NoHotReload.cake test/src/VocalGame.cake || exit $?
echo "This build script now doesn't make sense. See test/Build.sh"
# TESTING

7
src/Aubio.cake

@ -82,7 +82,7 @@
;;
(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import &comptime-only "ComptimeHelpers.cake" "BuildTools.cake")
(import &comptime-only "ComptimeHelpers.cake" "BuildTools.cake" "Dependencies.cake")
(defun-comptime build-aubio (manager (& ModuleManager) module (* Module) &return bool)
(comptime-cond
@ -113,12 +113,11 @@
(Log "Aubio: Successfully built\n")
(return true))
(add-dependency-git-submodule clone-aubio "https://github.com/aubio/aubio" "Dependencies/Aubio")
(add-dependency-git-submodule clone-aubio "https://github.com/aubio/aubio" "Dependencies/aubio")
(add-compile-time-hook-module pre-build build-aubio)
(add-c-search-directory-module "Dependencies/aubio/src")
(add-library-search-directory "Dependencies/aubio/build/src")
(add-library-dependency "aubio")
;; TODO: Relative path is going to break for sure
(add-library-runtime-search-directory "../Dependencies/aubio/build/src")
(add-library-runtime-search-directory "Dependencies/aubio/build/src")

52
src/AutoTest.cake

@ -3,7 +3,7 @@
;; e.g. (defun test--SDL (&return int) (return -1)) will show up as a failure
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import &comptime-only "Macros.cake")
(import &comptime-only "ComptimeHelpers.cake")
;; This is completely replaced by find-add-tests
(defun main (&return int) (return 0))
@ -14,14 +14,14 @@
(var functions-to-test (<> std::vector (<> std::pair std::string (* (const Token)))))
(var required-imports (<> std::vector (<> std::pair (* (const char)) (* (const Token)))))
(for-in definition-pair (& ObjectDefinitionPair) (field environment definitions)
(unless (!= (in std string npos) (call-on find (field definition-pair first) "test--"))
(continue))
(call-on push_back functions-to-test (call (in std make_pair)
(field definition-pair first)
(field definition-pair second definitionInvocation)))
(call-on push_back required-imports (call (in std make_pair)
(path definition-pair . second . definitionInvocation > source)
(field definition-pair second definitionInvocation))))
(unless (!= (in std string npos) (call-on find (field definition-pair first) "test--"))
(continue))
(call-on push_back functions-to-test (call (in std make_pair)
(field definition-pair first)
(field definition-pair second definitionInvocation)))
(call-on push_back required-imports (call (in std make_pair)
(path definition-pair . second . definitionInvocation > source)
(field definition-pair second definitionInvocation))))
(get-or-create-comptime-var total-tests-found int)
;; No more tests found this round. Exit, otherwise we'll get in an infinite modification loop
@ -33,38 +33,38 @@
(var test-body (<> std::vector Token))
(for-in function-pair (& (<> std::pair std::string (* (const Token)))) functions-to-test
(var function-name-token Token (deref (field function-pair second)))
(set (field function-name-token type) TokenType_Symbol)
(set (field function-name-token contents) (field function-pair first))
(tokenize-push test-body
(set num-errors (+ num-errors
((token-splice-addr function-name-token))))))
(var function-name-token Token (deref (field function-pair second)))
(set (field function-name-token type) TokenType_Symbol)
(set (field function-name-token contents) (field function-pair first))
(tokenize-push test-body
(set num-errors (+ num-errors
((token-splice-addr function-name-token))))))
(var main-definition (* (<> std::vector Token)) (new (<> std::vector Token)))
(call-on push_back (field environment comptimeTokens) main-definition)
(for-in import-pair (& (<> std::pair (* (const char)) (* (const Token)))) required-imports
(var import-str Token (deref (field import-pair second)))
(set (field import-str type) TokenType_String)
(set (field import-str contents) (field import-pair first))
(tokenize-push (deref main-definition)
(import (token-splice-addr import-str))))
(var import-str Token (deref (field import-pair second)))
(set (field import-str type) TokenType_String)
(set (field import-str contents) (field import-pair first))
(tokenize-push (deref main-definition)
(import (token-splice-addr import-str))))
(tokenize-push (deref main-definition)
(defun main (&return int)
(var num-errors int 0)
(token-splice-array test-body)
(return num-errors)))
(defun main (&return int)
(var num-errors int 0)
(token-splice-array test-body)
(return num-errors)))
(set (deref total-tests-found) (call-on size functions-to-test))
(unless (ReplaceAndEvaluateDefinition environment "main" (deref main-definition))
(return false))
(return false))
(set was-code-modified true))
(return true))
(add-compile-time-hook post-references-resolved find-add-tests)
(add-build-config-label "AutoTest")
(set-cakelisp-option executable-output "test/autoTest")
(set-cakelisp-option executable-output "autoTest")
(comptime-define-symbol 'auto-test)

13
src/Dependencies.cake

@ -8,11 +8,18 @@
(tokenize-push output
(defun-comptime (token-splice hook-name) (manager (& ModuleManager) module (* Module) &return bool)
(unless (fileExists (token-splice output-directory))
(Logf "%s: Automatically adding as submodule from %s\n"
(Logf "%s: Automatically adding as submodule from %s\\n\\n"
(token-splice output-directory) (token-splice repository-url))
(run-process-sequential-or
("git" "submodule" "add" (token-splice repository-url) (token-splice output-directory))
(Logf "error: failed to add %s as a git submodule dependency. Are you in a git repository?"
("git" "submodule" "add" (token-splice repository-url) (token-splice output-directory))
(Logf "error: failed to add %s as a git submodule dependency. Are you in a git repository?\\n"
(token-splice output-directory))
(return false))
;; Add its submodules as well
(run-process-sequential-or
("git" "submodule" "update" "--init" "--recursive" :in-directory (token-splice output-directory))
(Logf "error: failed to initialize submodules belonging to %s\\n"
(token-splice output-directory))
(return false)))
(return true))

5
src/Ogre.cake

@ -3,7 +3,7 @@
(import
"OgreInitialize.cake"
&comptime-only "CHelpers.cake" "BuildTools.cake")
&comptime-only "CHelpers.cake" "BuildTools.cake" "Dependencies.cake")
(c-import "<stdio.h>"
;; Ogre dependencies
@ -401,8 +401,7 @@ ln -s %s %s\n"
"OgreHlmsUnlit_d"
"OgreMain_d"
"OgreOverlay_d")
;; TODO: Relative path is going to break for sure
(add-library-runtime-search-directory "../Dependencies/ogre-next/build/Debug/lib" ".")
(add-library-runtime-search-directory "Dependencies/ogre-next/build/Debug/lib" ".")
;; Release. TODO: Use comptime-cond to allow this to be opted in
;; (add-library-search-directory "Dependencies/ogre-next/build/Release/lib")

2
src/OgreInitialize.cake

@ -1,7 +1,7 @@
;; Most of this file comes from the Ogre 2 basic project. It's customized now. Once I get more
;; familiar with Ogre, I'll probably try to move this file into Ogre.cake or something, which
;; currently acts as my "custom code"/integration file
(import &comptime-only "Macros.cake")
(import &comptime-only "CHelpers.cake")
(c-import
"OgreArchiveManager.h"

5
src/Tracy.cake

@ -1,7 +1,7 @@
(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import &comptime-only "Macros.cake")
(import &comptime-only "ComptimeHelpers.cake" "Dependencies.cake")
(c-import &with-decls "Tracy.hpp" "TracyC.h")
@ -73,6 +73,7 @@ unexpected location?")
(module-use-tracy-build-options)
(add-cpp-build-dependency "../Dependencies/tracy/TracyClient.cpp")
(add-c-search-directory-module "Dependencies/tracy")
(add-cpp-build-dependency "TracyClient.cpp")
(add-library-dependency "pthread" "dl")

33
test/Build.sh

@ -0,0 +1,33 @@
#!/bin/sh
CAKELISP_DIR=Dependencies/cakelisp
# Build Cakelisp itself
echo "\n\nCakelisp\n\n"
cd $CAKELISP_DIR
./Build.sh || exit $?
cd ../..
CAKELISP=./Dependencies/cakelisp/bin/cakelisp
echo "\n\nOgre\n\n"
$CAKELISP src/Config_Linux.cake src/OgreApp.cake || exit $?
echo "\n\nSDL Ogre\n\n"
$CAKELISP src/Config_Linux.cake src/SDLOgreApp.cake || exit $?
# echo "\n\nAuto Test (Math only)\n\n"
# $CAKELISP --execute src/Config_Linux.cake src/AutoTest.cake src/Math.cake || exit $?
echo "\n\nAuto Test\n\n"
$CAKELISP src/Config_Linux.cake ../src/AutoTest.cake ../src/SDL.cake ../src/Math.cake ../src/Aubio.cake || exit $?
# $CAKELISP src/Config_Linux.cake ../src/AutoTest.cake ../src/SDL.cake ../src/Tracy.cake ../src/Math.cake ../src/Aubio.cake || exit $?
echo "\n\nVocal Game (hot reload)\n\n"
$CAKELISP src/Config_Linux.cake src/MakeHotReload.cake src/VocalGame.cake || exit $?
echo "\n\nLoader\n\n"
$CAKELISP --execute src/Config_Linux.cake src/Loader.cake || exit $?
echo "\n\nVocal Game (no reload)\n\n"
$CAKELISP \
src/Config_Linux.cake src/NoHotReload.cake src/VocalGame.cake || exit $?

2
test/data/plugins.cfg

@ -1,7 +1,7 @@
# Defines plugins to load
# Define plugin folder
PluginFolder=../Dependencies/ogre-next/build/Release/lib
PluginFolder=Dependencies/ogre-next/build/Release/lib
# Define plugins
# Plugin=RenderSystem_Direct3D11

2
test/data/plugins_d.cfg

@ -1,7 +1,7 @@
# Defines plugins to load
# Define plugin folder
PluginFolder=../Dependencies/ogre-next/build/Debug/lib
PluginFolder=Dependencies/ogre-next/build/Debug/lib
# Define plugins
# Plugin=RenderSystem_Direct3D11

2
test/src/Config_Linux.cake

@ -1,2 +1,4 @@
(skip-build)
(comptime-define-symbol 'Unix)
;; Building from test/, need to go up one into gamelib (a bit unusual)
(add-cakelisp-search-directory "../src")

2
test/src/GamelibMacros.cake

@ -1,7 +1,7 @@
(skip-build)
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import &comptime-only "Macros.cake")
(import &comptime-only "ComptimeHelpers.cake")
;; Given
;; (declare-extern-function my-func (i int &return bool))

4
test/src/Loader.cake

@ -7,7 +7,7 @@
(set-cakelisp-option use-c-linkage true)
(add-build-config-label "HotLoader")
(set-cakelisp-option executable-output "test/Loader")
(set-cakelisp-option executable-output "Loader")
;; TODO: Tracy gets confused when the reloaded lib has its own version of Tracy
(ignore
@ -20,7 +20,7 @@
;; "src/SDL.cake")
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import &comptime-only "Options.cake" "Macros.cake")
(import &comptime-only "Options.cake")
;; TODO: Should this happen automatically, because import automatically adds current working dir?
;; Should it add working dir?
(add-c-search-directory-module ".")

2
test/src/MakeHotReload.cake

@ -1,6 +1,6 @@
(skip-build)
(set-cakelisp-option executable-output "test/libGeneratedCakelisp.so")
(set-cakelisp-option executable-output "libGeneratedCakelisp.so")
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import "HotReloadingCodeModifier.cake")

4
test/src/OgreApp.cake

@ -1,6 +1,6 @@
(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(import "src/Ogre.cake")
(import "Ogre.cake")
;; TODO: Should this happen automatically, because import automatically adds current working dir?
;; Should it add working dir?
(add-c-search-directory-module ".")
@ -39,4 +39,4 @@
(return 0))
;; We need to place the executable relative to our data folders and such
(set-cakelisp-option executable-output "test/ogreApp")
(set-cakelisp-option executable-output "ogreApp")

6
test/src/SDLOgreApp.cake

@ -1,8 +1,8 @@
(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src")
(set-cakelisp-option executable-output "test/SDLOgreApp")
(set-cakelisp-option executable-output "SDLOgreApp")
(import "src/Ogre.cake"
"src/SDL.cake")
(import "Ogre.cake"
"SDL.cake")
;; TODO: Should this happen automatically, because import automatically adds current working dir?
;; Should it add working dir?
(add-c-search-directory-module ".")

18
test/src/VocalGame.cake

@ -1,6 +1,6 @@
(set-cakelisp-option executable-output "test/VocalGame")
(set-cakelisp-option executable-output "VocalGame")
(import &comptime-only "Options.cake" "Macros.cake" "GamelibMacros.cake")
(import &comptime-only "Options.cake" "ComptimeHelpers.cake" "GamelibMacros.cake")
(import "Ogre.cake" "OgreInitialize.cake" "SDL.cake" "Math.cake" "Tracy.cake" "Aubio.cake")
@ -694,7 +694,7 @@
(scope ;; Models/meshes
;; Make sure output dir exists and we have an absolute path to it
(var model-assets ([] (* (const char))) (array "Monkey" "MaterialSphere"))
(var model-relative-dir (* (const char)) "test/data/Models")
(var model-relative-dir (* (const char)) "data/Models")
(makeDirectory model-relative-dir)
;; Output must be absolute or OgreMeshTool will fail (probably due to different working dir)
@ -706,7 +706,7 @@
(var i int 0)
(while (< i (array-size model-assets))
(var blend-asset ([] MAX_PATH_LENGTH char) (array 0))
(PrintfBuffer blend-asset "test/assets/%s.blend" (at i model-assets))
(PrintfBuffer blend-asset "assets/%s.blend" (at i model-assets))
;; It is too slow to check Blender for all the files the blend will export, then check whether
;; the .blend file is more recently modified. Instead, create a file in the cache to represent
@ -728,14 +728,14 @@
("blender"
"--background" blend-asset
"--python-exit-code" "1" ;; If there's a python exception, return 1
"--python" "tools/BlenderToOgre.py"
"--python" "../tools/BlenderToOgre.py"
"--" model-output-dir)
(Log "Asset-Building: failed to build 3D asset. Is Blender on your path? Is blender2ogre set
up on your Blender default preferences? See https://github.com/OGRECave/blender2ogre for setup\n
You may need to copy blender2ogre to your new blender version, e.g.:\n\n
cp -r Dependencies/blender2ogre/io_ogre ~/.config/blender/[version]\n\n
Or, open your new version of Blender and select 'Copy settings from [previous version]'\n
on the splash screen.")
on the splash screen.\n")
(free (type-cast model-output-dir (* void)))
(return false))
@ -760,9 +760,9 @@ on the splash screen.")
(var i int 0)
(while (< i (array-size texture-assets))
(var texture-asset ([] MAX_PATH_LENGTH char) (array 0))
(PrintfBuffer texture-asset "test/assets/%s.png" (at i texture-assets))
(PrintfBuffer texture-asset "assets/%s.png" (at i texture-assets))
(var texture-converted ([] MAX_PATH_LENGTH char) (array 0))
(PrintfBuffer texture-converted "test/data/Materials/Textures/%s.dds" (at i texture-assets))
(PrintfBuffer texture-converted "data/Materials/Textures/%s.dds" (at i texture-assets))
(unless (fileIsMoreRecentlyModified texture-asset texture-converted)
(incr i)
@ -792,7 +792,7 @@ path? You may need to install ImageMagick. See https://www.imagemagick.org/scrip
(return true))
;; TODO: This should be a post-build hook
(add-compile-time-hook-module pre-build process-3d-assets)
(add-compile-time-hook-module pre-build process-3d-assets :priority-decrease 10)
;;
;; Building

Loading…
Cancel
Save