Browse Source

Broke tests with WIP AutoColor schenanigans

I cleaned up git dependencies so it is possible to get dependencies at
compile-time anywhere. This should slightly speed up comptime
compilation due to all those modules no longer duplicating all that
code.
master
Macoy Madson 9 months ago
parent
commit
c6ec69c4bf
  1. 97
      src/Dependencies.cake
  2. 24
      src/ImGuiAutoColor.cake

97
src/Dependencies.cake

@ -2,59 +2,64 @@
(add-cakelisp-search-directory "Dependencies/cakelisp/runtime")
(import "ComptimeHelpers.cake" "BuildTools.cake" "CHelpers.cake")
(defun-comptime add-git-dependency (repository-url (* (const char)) output-directory (* (const char))
remote-branch-name (* (const char))
&return bool)
(unless (fileExists output-directory)
(comptime-cond
('Dependencies-Clone-Only
(Logf "%s: Cloning from %s. Will NOT be tracked as a submodule\n\n"
output-directory repository-url)
(run-process-sequential-or
("git" "clone" repository-url output-directory)
(Logf "error: failed to clone %s\n" output-directory)
(return false)))
(true
(Logf "%s: Automatically adding as submodule from %s\n\n"
output-directory repository-url)
(run-process-sequential-or
("git" "submodule" "add" repository-url output-directory)
(Logf "error: failed to add %s as a git submodule dependency. Are you in a git repository?\n"
output-directory)
(return false))))
(when remote-branch-name
(var remote-branch-buffer ([] 256 char) (array 0))
(PrintfBuffer remote-branch-buffer "origin/%s" remote-branch-name)
(run-process-sequential-or
("git" "checkout" "--track" remote-branch-buffer
:in-directory output-directory)
(Logf "error: failed to check out %s branch %s\n"
output-directory remote-branch-buffer)
(return false)))
;; Initialize its submodules, in case it has them
(run-process-sequential-or
("git" "submodule" "update" "--init" "--recursive"
:in-directory output-directory)
(Logf "error: failed to initialize submodules belonging to %s\n"
output-directory)
(return false)))
(return true))
;; Define 'Dependencies-Clone-Only to clone only - useful if you don't want to or cannot use git
;; submodules. For example, gamelib/test clones so I don't need to keep removing the test Dependencies.
;; TODO This is pretty wasteful to output a whole new function for this. It should just be a
;; comptime function call with arguments
;; TODO Pitfall: This will pull master, which we might not know works. We need to specify a branch
;; TODO Pitfall: This will pull master, which we might not know works. We need to specify a branch or commit.
;; TODO: We could do the download as soon as we evaluate this macro. For now I'll keep it in pre-build.
(defmacro add-dependency-git-submodule (hook-name symbol repository-url string output-directory string
&optional remote-branch-name string)
(var branch-selection (<> std::vector Token))
(when remote-branch-name
(var remote-branch Token (deref remote-branch-name))
(var remote-branch-buffer ([] 256 char) (array 0))
(PrintfBuffer remote-branch-buffer "origin/%s"
(call-on c_str (path remote-branch-name > contents)))
(set (field remote-branch contents) remote-branch-buffer)
(tokenize-push branch-selection
(run-process-sequential-or
("git" "checkout" "--track" (token-splice-addr remote-branch)
:in-directory (token-splice output-directory))
(Logf "error: failed to check out %s branch %s\n"
(token-splice output-directory) (token-splice-addr remote-branch))
(return false))))
(var remote-branch Token (deref repository-url))
(if remote-branch-name
(set remote-branch (deref remote-branch-name))
(scope
(set (field remote-branch contents) "null")
(set (field remote-branch type) TokenType_Symbol)))
(tokenize-push output
(defun-comptime (token-splice hook-name) (manager (& ModuleManager) module (* Module) &return bool)
(unless (fileExists (token-splice output-directory))
(comptime-cond
('Dependencies-Clone-Only
(Logf "%s: Cloning from %s. Will NOT be tracked as a submodule\n\n"
(token-splice output-directory) (token-splice repository-url))
(run-process-sequential-or
("git" "clone" (token-splice repository-url) (token-splice output-directory))
(Logf "error: failed to clone %s\n" (token-splice output-directory))
(return false)))
(true
(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?\n"
(token-splice output-directory))
(return false))))
(token-splice-array branch-selection)
;; Initialize its submodules, in case it has them
(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))
(return (add-git-dependency (token-splice repository-url) (token-splice output-directory)
(token-splice-addr remote-branch))))
;; High priority so that it comes before dependency build steps
(add-compile-time-hook-module pre-build (token-splice hook-name) :priority-increase 10))
(return true))

24
src/ImGuiAutoColor.cake

@ -1,8 +1,9 @@
;; Automatically set ImGui theme colors based on the user's current wallpaper.
(import "ImGui.cake" "TaskSystem.cake" "SDL.cake"
"AutoColor.cake"
"CHelpers.cake")
(download-import-auto-color)
(c-import "<stdlib.h>" "<stdio.h>" "<math.h>")
(var target-base16-colors ([] 16 auto-color))
@ -176,6 +177,27 @@
(pick-colors-from-background base16-colors succeeded)
(set-target-base16-colors :pin-to-main-thread base16-colors succeeded)))
;;
;; Dependencies
;;
;; We need to do this in a macro because Cakelisp expects .cake imports to be immediately
;; available. We use the macro invocation to download it just in time for importing.
(defmacro download-import-auto-color ()
(unless (add-git-dependency
"https://macoy.me/code/macoy/auto-color.git"
"Dependencies/auto-color"
null) ;; Master branch is fine
(return false))
(tokenize-push output
(add-cakelisp-search-directory "Dependencies/auto-color/src")
(import "AutoColor.cake"))
(return true))
;;
;; Testing
;;
(comptime-cond
('auto-test
(c-import "<stdio.h>")

Loading…
Cancel
Save