[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].
This commit is contained in:
nmlgc 2024-06-17 01:45:04 +02:00
parent b59ee0bb5f
commit dd129f4f6f
3 changed files with 35 additions and 8 deletions

View File

@ -11,6 +11,8 @@
---the following benefits: ---the following benefits:
--- ---
---* Automatic slash-to-backslash conversion for tool filenames ---* 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 ---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 ---to get the transformed rules back into the repo. All rule lines are printed
@ -18,6 +20,7 @@
---batch file inside `build.bat`. ---batch file inside `build.bat`.
---@class Rules ---@class Rules
---@field private rules Rule[] ---@field private rules Rule[]
---@field private outdirs table<string, boolean> Set of output directories
local Rules = {} local Rules = {}
Rules.__index = Rules Rules.__index = Rules
@ -25,6 +28,7 @@ function NewRules()
---@type Rules ---@type Rules
local ret = { local ret = {
rules = {}, rules = {},
outdirs = {},
} }
return setmetatable(ret, Rules) return setmetatable(ret, Rules)
end end
@ -52,6 +56,14 @@ function Rules:insert(inputs, tool, args, outputs)
end) end)
args = args:gsub("%%o", table.concat(outs, " ")) 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 } local rule = { inputs = ins, tool = tool, args = args }
table.insert(self.rules, rule) table.insert(self.rules, rule)
return string.format("%s %s", tool, args) return string.format("%s %s", tool, args)
@ -75,6 +87,15 @@ $ : natively run DOS-based tools. Automatically generated whenever `Tupfile.lua`
$ : is modified. $ : is modified.
$ @echo off $ @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 for _, rule in pairs(self.rules) do
local cmd = rule.args:gsub("%%f", table.concat(rule.inputs, " ")) local cmd = rule.args:gsub("%%f", table.concat(rule.inputs, " "))
print(string.format("$ %s %s", rule.tool:gsub("/", "\\"), cmd)) print(string.format("$ %s %s", rule.tool:gsub("/", "\\"), cmd))

View File

@ -26,14 +26,6 @@ call set_errorlevel_to_1.bat
bcc32 >NUL %STDERR_IGNORE% bcc32 >NUL %STDERR_IGNORE%
if errorlevel 1 goto no_bcc32 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 : 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. : returning `version` subcommand to figure out whether we should fall back.
bin\tup version >NUL bin\tup version >NUL

View File

@ -2,6 +2,20 @@
: natively run DOS-based tools. Automatically generated whenever `Tupfile.lua` : natively run DOS-based tools. Automatically generated whenever `Tupfile.lua`
: is modified. : is modified.
@echo off @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 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\zun_stub.asm obj\Pipeline\zun_stub.obj
tasm32 /m /mx /kh32768 /t Pipeline\cstmstub.asm obj\Pipeline\cstmstub.obj tasm32 /m /mx /kh32768 /t Pipeline\cstmstub.asm obj\Pipeline\cstmstub.obj