Skip to content

Commit 34ab508

Browse files
committed
CL: --meta can take a path.
1 parent e9c109d commit 34ab508

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

preprocess-cl.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ exec lua "$0" "$@"
7373
--macrosuffix=suffix
7474
String to append to macro names.
7575
76-
--meta
76+
--meta OR --meta=pathToSaveMetaprogramTo
7777
Output the metaprogram to a temporary file (*.meta.lua). Useful if
7878
an error happens when the metaprogram runs. This file is removed
7979
if there's no error and --debug isn't enabled.
@@ -203,7 +203,7 @@ local hasOutputExtension = false
203203
local hasOutputPaths = false
204204
local isDebug = false
205205
local outputExtension = "lua"
206-
local outputMeta = false
206+
local outputMeta = false -- flag|path
207207
local processingInfoPath = ""
208208
local silent = false
209209
local validate = true
@@ -310,7 +310,7 @@ for _, arg in ipairs(args) do
310310

311311
elseif arg == "--debug" then
312312
isDebug = true
313-
outputMeta = true
313+
outputMeta = outputMeta or true
314314

315315
elseif arg:find"^%-%-handler=" or arg:find"^%-h=" then
316316
messageHandlerPath = arg:gsub("^.-=", "")
@@ -323,6 +323,8 @@ for _, arg in ipairs(args) do
323323

324324
elseif arg == "--meta" then
325325
outputMeta = true
326+
elseif arg:find"^%-%-meta=" then
327+
outputMeta = arg:gsub("^.-=", "")
326328

327329
elseif arg == "--nonil" then
328330
canOutputNil = false
@@ -516,7 +518,7 @@ for i, pathIn in ipairs(pathsIn) do
516518
printfNoise("Processing '%s'...", pathIn)
517519

518520
local pathOut = pathsOut[i]
519-
local pathMeta = pathOut:gsub("%.%w+$", "")..".meta.lua"
521+
local pathMeta = (type(outputMeta) == "string") and outputMeta or pathOut:gsub("%.%w+$", "")..".meta.lua"
520522

521523
if not outputMeta or pathOut == "-" then
522524
pathMeta = nil

tests/suite.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ doTest("Options", function()
856856
removeFile("temp/generatedTest.meta.lua")
857857
runCommandToFail(luaExe, [[preprocess-cl.lua temp/generatedTest.lua2p --meta]])
858858
assert(fileExists("temp/generatedTest.meta.lua"))
859+
860+
writeFile("temp/generatedTest.lua2p", [[ !bad ]])
861+
removeFile("temp/generatedTest.metafoo")
862+
runCommandToFail(luaExe, [[preprocess-cl.lua temp/generatedTest.lua2p --meta=temp/generatedTest.metafoo]])
863+
assert(fileExists("temp/generatedTest.metafoo"))
859864
end
860865

861866
--nonil

0 commit comments

Comments
 (0)