From ef2c01b1d45cdb6e825f49ad576e7e67d4d6d6d2 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 1 Aug 2023 17:58:27 +1000 Subject: [PATCH] refactor build system to allow pulling libraries from packages, assuming directories are set up correctly --- build.lua | 3 --- build.sh | 3 ++- kcfg/base.cfg | 2 ++ kcfg/full.cfg | 3 +++ module/init.lua | 11 ----------- preproc.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 kcfg/base.cfg create mode 100644 kcfg/full.cfg diff --git a/build.lua b/build.lua index 40cdcb9..6bb1576 100644 --- a/build.lua +++ b/build.lua @@ -1,7 +1,4 @@ local preproc = require "preproc" --local tA = {...} -function preproc.directives.includelib(file,name) - return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.preproc(file)) -end preproc(...) diff --git a/build.sh b/build.sh index e06047c..3e095c5 100755 --- a/build.sh +++ b/build.sh @@ -1,8 +1,9 @@ #!/bin/bash LUA=${LUA:-lua} +KVAR=${1:-lua} rm -r target/* mkdir -p target/doc &>/dev/null -$LUA build.lua module/init.lua target/init.lua +$LUA build.lua kcfg/$KVAR.cfg target/init.lua echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)\" > target/version.lua cat target/version.lua target/init.lua > target/tinit.lua mv target/tinit.lua target/init.lua diff --git a/kcfg/base.cfg b/kcfg/base.cfg new file mode 100644 index 0000000..736f6a0 --- /dev/null +++ b/kcfg/base.cfg @@ -0,0 +1,2 @@ +--#include "module/base.lua" +--#include "module/init.lua" diff --git a/kcfg/full.cfg b/kcfg/full.cfg new file mode 100644 index 0000000..940b3c8 --- /dev/null +++ b/kcfg/full.cfg @@ -0,0 +1,3 @@ +--#include "module/base.lua" +--#include "module/rtfsboot.lua" +--#include "module/init.lua" diff --git a/module/init.lua b/module/init.lua index ba38c46..125977a 100644 --- a/module/init.lua +++ b/module/init.lua @@ -1,14 +1,3 @@ ---#include "module/syslog.lua" ---#include "module/sched.lua" ---#include "module/buffer.lua" ---#include "module/osutil.lua" ---#include "module/fs.lua" ---#include "module/io.lua" ---#include "module/devfs.lua" ---#include "module/devfs/syslog.lua" ---#include "module/component-get.lua" ---#include "module/loadfile.lua" - _OSVERSION=_OSVERSION or "PsychOS 2" os.spawn(function() diff --git a/preproc.lua b/preproc.lua index 1cdac5a..82d77ce 100644 --- a/preproc.lua +++ b/preproc.lua @@ -59,6 +59,47 @@ end preproc.directives.include = preproc.preproc +function preproc.directives.includelib(file, name) -- string string -- string -- Returns a preprocessed inlined library + return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.preproc(file)) +end + +function preproc.directives.includepkgfile(package, file) + if (_OSVERSION or ""):sub(1,7) == "PsychOS" then + return preproc.preproc(string.format("/pkg/%s", file)) + else + for path in (os.getenv("PSYCHOSPACKAGES") or "../PsychOSPackages"):gmatch("[^:]+") do + local f = io.open(string.format("%s/%s/%s", path, package, file), "r") + if f then + f:close() + return preproc.preproc(string.format("%s/%s/%s", path, package, file)) + end + end + end + error(string.format("unable to locate file %s from package %s", file, package)) +end + +function preproc.directives.includepkglib(package, file, name) -- string string -- string -- Returns a preprocessed inlined library + return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.directives.includepkgfile(package, file)) +end + +--[[ +function preproc.directives.includepkglib(package, file, name) + if (_OSVERSION or ""):sub(1,7) == "PsychOS" then + return preproc.directives.includelib(string.format("/pkg/%s", file), name) + else + for path in (os.getenv("PSYCHOSPACKAGES") or "../PsychOSPackages"):gmatch("[^:]+") do + print(string.format("%s/%s/%s", path, package, file)) + local f = io.open(string.format("%s/%s/%s", path, package, file), "r") + if f then + f:close() + return preproc.directives.includelib(string.format("%s/%s/%s", path, package, file), name) + end + end + end + error(string.format("unable to locate library %s from package %s", name, package)) +end +]] + return setmetatable(preproc,{__call=function(_,...) local tA = {...} local out = table.remove(tA,#tA)