From dd129f4f6fdf6c52627cc1456c2bfec4472a3762 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Mon, 17 Jun 2024 01:45:04 +0200 Subject: [PATCH] [Build] Rules: Add output directory creation to the dumb batch file `tup generate` does this as well, but only emits the `mkdir` calls for the directories that are missing in the current working tree, requiring a clean checkout to actually emit all necessary ones. This is much more convenient. Part of P0282, funded by [Anonymous]. --- Pipeline/rules.lua | 21 +++++++++++++++++++++ build32b.bat | 8 -------- build_dumb.bat | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Pipeline/rules.lua b/Pipeline/rules.lua index b1ad39ce..a52532b4 100644 --- a/Pipeline/rules.lua +++ b/Pipeline/rules.lua @@ -11,6 +11,8 @@ ---the following benefits: --- ---* Automatic slash-to-backslash conversion for tool filenames +---* Emits `mkdir` commands for *all* referenced output directories, not just +--- the ones that are missing from the current working tree. --- ---Since Tup forbids writing files from the Tupfile, we have to abuse stdout ---to get the transformed rules back into the repo. All rule lines are printed @@ -18,6 +20,7 @@ ---batch file inside `build.bat`. ---@class Rules ---@field private rules Rule[] +---@field private outdirs table Set of output directories local Rules = {} Rules.__index = Rules @@ -25,6 +28,7 @@ function NewRules() ---@type Rules local ret = { rules = {}, + outdirs = {}, } return setmetatable(ret, Rules) end @@ -52,6 +56,14 @@ function Rules:insert(inputs, tool, args, outputs) end) args = args:gsub("%%o", table.concat(outs, " ")) + tup_append_assignment(outs, outputs.extra_outputs) + for _, output in ipairs(outs) do + local dir = output:gsub("/", "\\"):match("(.*)\\") + if (dir ~= nil) then + self.outdirs[dir] = true + end + end + local rule = { inputs = ins, tool = tool, args = args } table.insert(self.rules, rule) return string.format("%s %s", tool, args) @@ -75,6 +87,15 @@ $ : natively run DOS-based tools. Automatically generated whenever `Tupfile.lua` $ : is modified. $ @echo off ]]) + local outdirs_sorted = {} + for dir in pairs(self.outdirs) do + table.insert(outdirs_sorted, dir) + end + table.sort(outdirs_sorted) + for _, dir in pairs(outdirs_sorted) do + print(string.format("$ mkdir %s %%STDERR_IGNORE%%", dir)) + end + for _, rule in pairs(self.rules) do local cmd = rule.args:gsub("%%f", table.concat(rule.inputs, " ")) print(string.format("$ %s %s", rule.tool:gsub("/", "\\"), cmd)) diff --git a/build32b.bat b/build32b.bat index 0657d146..24f50f9c 100755 --- a/build32b.bat +++ b/build32b.bat @@ -26,14 +26,6 @@ call set_errorlevel_to_1.bat bcc32 >NUL %STDERR_IGNORE% if errorlevel 1 goto no_bcc32 -: Neither BCC32 nor TASM32 automatically create nonexisting output -: directories. Tup would, but not everybody can use it. -mkdir obj %STDERR_IGNORE% -mkdir obj\Pipeline %STDERR_IGNORE% -mkdir bin\Pipeline %STDERR_IGNORE% -for %%i in (1 2 3 4 5) do mkdir obj\th0%%i %STDERR_IGNORE% -for %%i in (1 2 3 4 5) do mkdir bin\th0%%i %STDERR_IGNORE% - : Regular Tup would return 1 when hitting Ctrl-C, so let's use the immediately : returning `version` subcommand to figure out whether we should fall back. bin\tup version >NUL diff --git a/build_dumb.bat b/build_dumb.bat index 10d33103..1afb4022 100644 --- a/build_dumb.bat +++ b/build_dumb.bat @@ -2,6 +2,20 @@ : natively run DOS-based tools. Automatically generated whenever `Tupfile.lua` : is modified. @echo off +mkdir Research %STDERR_IGNORE% +mkdir bin\Pipeline %STDERR_IGNORE% +mkdir obj %STDERR_IGNORE% +mkdir obj\Pipeline %STDERR_IGNORE% +mkdir obj\th01 %STDERR_IGNORE% +mkdir obj\th02 %STDERR_IGNORE% +mkdir obj\th03 %STDERR_IGNORE% +mkdir obj\th04 %STDERR_IGNORE% +mkdir obj\th05 %STDERR_IGNORE% +mkdir th01\sprites %STDERR_IGNORE% +mkdir th02\sprites %STDERR_IGNORE% +mkdir th03\sprites %STDERR_IGNORE% +mkdir th04\sprites %STDERR_IGNORE% +mkdir th05\sprites %STDERR_IGNORE% bcc32 -w-8004 -w-8012 -O2 -v- -x- -nbin/Pipeline/ Pipeline/bmp2arr.c Pipeline/bmp2arrl.c tasm32 /m /mx /kh32768 /t Pipeline\zun_stub.asm obj\Pipeline\zun_stub.obj tasm32 /m /mx /kh32768 /t Pipeline\cstmstub.asm obj\Pipeline\cstmstub.obj