antlr4: improve includedirs (#5867)

* antlr4: improve includedirs

* normalize path
pull/5865/merge
star9029 5 days ago committed by GitHub
parent 7d4031c5a8
commit 5b94ffa012
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      packages/a/antlr4-runtime/xmake.lua
  2. 12
      packages/a/antlr4/rules/lexer.lua
  3. 12
      packages/a/antlr4/rules/parser.lua

@ -42,15 +42,7 @@ package("antlr4-runtime")
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DANTLR_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DANTLR_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
if package:is_plat("windows") then
table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
end
import("package.tools.cmake").install(package, configs)
if package:is_plat("windows") and package:is_debug() then
local dir = package:installdir(package:config("shared") and "bin" or "lib")
os.vcp(path.join(package:buildir(), "runtime/*.pdb"), dir)
end
end)
on_test(function (package)

@ -4,19 +4,23 @@ rule("lexer")
add_deps("@find_antlr4")
on_config(function (target)
-- remove parser g4
local includedirs = {}
local autogendir = path.join(target:autogendir(), "rules/antlr4/lexer")
for _, sourcebatch in pairs(target:sourcebatches()) do
if sourcebatch.rulename == "@antlr4/lexer" then
local sourcefiles = {}
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
if not sourcefile:lower():find("parser") then
-- remove parser g4
if not sourcefile:lower():find("parser", 1, true) then
table.insert(sourcefiles, sourcefile)
table.insert(includedirs, path.normalize(path.join(autogendir, path.directory(sourcefile))))
end
end
sourcebatch.sourcefiles = sourcefiles
break
end
end
target:add("includedirs", table.unique(includedirs), {public = true})
end)
before_buildcmd_file(function (target, batchcmds, sourcefile_g4, opt)
@ -25,7 +29,7 @@ rule("lexer")
table.join2(argv, target:values("antlr4.lexer.flags"))
local autogendir = path.join(target:autogendir(), "rules/antlr4/lexer")
local sourcefile_cxx = path.join(autogendir, path.directory(sourcefile_g4), path.basename(sourcefile_g4) .. ".cpp")
local sourcefile_cxx = path.normalize(path.join(autogendir, path.directory(sourcefile_g4), path.basename(sourcefile_g4) .. ".cpp"))
local sourcefile_dir = path.directory(sourcefile_cxx)
batchcmds:mkdir(sourcefile_dir)
@ -34,8 +38,6 @@ rule("lexer")
table.insert(argv, "-lib")
table.insert(argv, sourcefile_dir)
target:add("includedirs", sourcefile_dir, {public = true})
table.insert(argv, sourcefile_g4)
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.g4 %s", sourcefile_g4)
batchcmds:vrunv(java.program, argv)

@ -4,19 +4,23 @@ rule("parser")
add_deps("@lexer", {order = true})
on_config(function (target)
-- remove lexer g4
local includedirs = {}
local autogendir = path.join(target:autogendir(), "rules/antlr4/parser")
for _, sourcebatch in pairs(target:sourcebatches()) do
if sourcebatch.rulename == "@antlr4/parser" then
local sourcefiles = {}
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
if not sourcefile:lower():find("lexer") then
-- remove lexer g4
if not sourcefile:lower():find("lexer", 1, true) then
table.insert(sourcefiles, sourcefile)
table.insert(includedirs, path.normalize(path.join(autogendir, path.directory(sourcefile))))
end
end
sourcebatch.sourcefiles = sourcefiles
break
end
end
target:add("includedirs", table.unique(includedirs), {public = true})
end)
before_buildcmd_file(function (target, batchcmds, sourcefile_g4, opt)
@ -32,7 +36,7 @@ rule("parser")
table.join2(argv, target:values("antlr4.parser.flags"))
local autogendir = path.join(target:autogendir(), "rules/antlr4/parser")
local sourcefile_cxx = path.join(autogendir, path.directory(sourcefile_g4), path.basename(sourcefile_g4) .. ".cpp")
local sourcefile_cxx = path.normalize(path.join(autogendir, path.directory(sourcefile_g4), path.basename(sourcefile_g4) .. ".cpp"))
local sourcefile_dir = path.directory(sourcefile_cxx)
batchcmds:mkdir(sourcefile_dir)
@ -41,8 +45,6 @@ rule("parser")
table.insert(argv, "-lib")
table.insert(argv, sourcefile_dir)
target:add("includedirs", sourcefile_dir, {public = true})
table.insert(argv, sourcefile_g4)
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.g4 %s", sourcefile_g4)
batchcmds:vrunv(java.program, argv)

Loading…
Cancel
Save