summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorririyeye <[email protected]>2024-09-06 14:46:58 +0800
committerririyeye <[email protected]>2024-09-06 14:46:58 +0800
commit63870bfbcdfc322742ef5cf4c48e4cec59fe1665 (patch)
tree50df4bfcda1a7abb8c541c1482f7901d4b0973a4
parent00725eec8a66efaad2afffb044688709f7c4d55d (diff)
format code
-rw-r--r--xmake/rules/swig/build_module_file.lua43
-rw-r--r--xmake/rules/swig/xmake.lua3
2 files changed, 22 insertions, 24 deletions
diff --git a/xmake/rules/swig/build_module_file.lua b/xmake/rules/swig/build_module_file.lua
index ae48e1350..3e6af313f 100644
--- a/xmake/rules/swig/build_module_file.lua
+++ b/xmake/rules/swig/build_module_file.lua
@@ -28,7 +28,7 @@ function find_user_outdir(fileconfig)
-- user specified output path
if fileconfig and fileconfig.swigflags then
-- find -outdir path
- for i , par in pairs(fileconfig.swigflags) do
+ for i, par in ipairs(fileconfig.swigflags) do
if par == "-outdir" then
local dirpath = fileconfig.swigflags[i + 1]
if os.isdir(dirpath) then
@@ -39,12 +39,12 @@ function find_user_outdir(fileconfig)
end
end
-function jar_build(target , fileconfig , opt)
+function jar_build(target, fileconfig, opt)
local javac = assert(find_tool("javac"), "javac not found!")
local jar = assert(find_tool("jar"), "jar not found!")
local java_src_dir = path.join(target:autogendir(), "rules", "swig")
- local jar_dst_dir = path.join(target:autogendir(), "rules", "swig")
+ local java_class_dir = java_src_dir
local user_outdir = find_user_outdir(fileconfig)
if user_outdir then
@@ -55,10 +55,10 @@ function jar_build(target , fileconfig , opt)
local autogenfiles = os.files(path.join(java_src_dir, "*.java"))
-- write file list
- local filelistname = os.tmpfile()
+ local filelistname = path.join(java_src_dir, "buildlist.txt")
local file = io.open(filelistname, "w")
if file then
- for _, sourcebatch in pairs(autogenfiles) do
+ for _, sourcebatch in ipairs(autogenfiles) do
file:print(sourcebatch)
end
file:close()
@@ -66,17 +66,15 @@ function jar_build(target , fileconfig , opt)
-- compile to class file
progress.show(opt.progress, "${color.build.object}compiling.javac %s class file", target:name())
- os.vrunv(javac.program, {"--release", "17", "-d", jar_dst_dir , "@"..filelistname})
+ os.vrunv(javac.program, {"--release", "17", "-d", java_class_dir, "@" .. filelistname})
-- generate jar file
- progress.show(opt.progress, "${color.build.object}compiling.jar %s", target:name()..".jar")
- os.vrunv(jar.program, {"-cf" , path.join(java_src_dir , target:name()..".jar") , jar_dst_dir})
+ progress.show(opt.progress, "${color.build.object}compiling.jar %s", target:name() .. ".jar")
+ os.vrunv(jar.program, {"-cf", path.join(java_src_dir, target:name() .. ".jar"), java_class_dir})
os.tryrm(filelistname)
end
-
-
function swig_par(target, sourcefile, opt)
-- get swig
opt = opt or {}
@@ -90,7 +88,7 @@ function swig_par(target, sourcefile, opt)
-- add commands
local moduletype = assert(target:data("swig.moduletype"), "swig.moduletype not found!")
- local argv = { "-" .. moduletype, "-o", sourcefile_cx }
+ local argv = {"-" .. moduletype, "-o", sourcefile_cx}
if opt.sourcekind == "cxx" then
table.insert(argv, "-c++")
end
@@ -119,13 +117,14 @@ function swig_par(target, sourcefile, opt)
end
table.insert(argv, sourcefile)
- return { argv = argv
- , objectfile = objectfile
- , swig = swig
- , sourcefile_cx = sourcefile_cx
- , moduletype = moduletype
- , fileconfig = fileconfig
- }
+ return {
+ argv = argv,
+ objectfile = objectfile,
+ swig = swig,
+ sourcefile_cx = sourcefile_cx,
+ moduletype = moduletype,
+ fileconfig = fileconfig
+ }
end
function swig_build_cmd(target, batchcmds, sourcefile, opt, pars)
@@ -149,7 +148,6 @@ function swig_build_cmd(target, batchcmds, sourcefile, opt, pars)
batchcmds:set_depcache(target:dependfile(objectfile))
end
-
function swig_build_file(target, sourcefile, opt, par)
local par = swig_par(target, sourcefile, opt)
@@ -173,7 +171,7 @@ function swig_build_file(target, sourcefile, opt, par)
-- gen swig depend file , same with gcc .d
local swigdep = os.tmpfile()
- local argv2 = {"-MMD" , "-MF" , swigdep}
+ local argv2 = {"-MMD", "-MF", swigdep}
table.join2(argv2, argv)
-- swig generate file and depend file
@@ -181,7 +179,7 @@ function swig_build_file(target, sourcefile, opt, par)
compiler.compile(sourcefile_cx, objectfile, {target = target})
-- update depend file
- local deps = io.readfile(swigdep , {continuation = "\\"})
+ local deps = io.readfile(swigdep, {continuation = "\\"})
os.tryrm(swigdep)
dependinfo.files = {sourcefile}
dependinfo.depfiles_gcc = deps
@@ -191,7 +189,6 @@ function swig_build_file(target, sourcefile, opt, par)
-- jar build
local buildjar = target:extraconf("rules", "swig.c", "buildjar") or target:extraconf("rules", "swig.cpp", "buildjar")
if moduletype == "java" and buildjar then
- jar_build(target , fileconfig , opt)
+ jar_build(target, fileconfig, opt)
end
-
end
diff --git a/xmake/rules/swig/xmake.lua b/xmake/rules/swig/xmake.lua
index 7bfb12738..48c6fcc91 100644
--- a/xmake/rules/swig/xmake.lua
+++ b/xmake/rules/swig/xmake.lua
@@ -27,6 +27,7 @@
rule("swig.base")
on_load(function (target)
target:set("kind", "shared")
+ local find_user_outdir = import("build_module_file").find_user_outdir
local moduletype = target:extraconf("rules", "swig.c", "moduletype") or target:extraconf("rules", "swig.cpp", "moduletype")
if moduletype == "python" then
target:set("prefixname", "_")
@@ -77,7 +78,7 @@ rule("swig.base")
local autogenfiles
local autogendir = path.join(target:autogendir(), "rules", "swig")
- local user_outdir = import("build_module_file").find_user_outdir(fileconfig)
+ local user_outdir = find_user_outdir(fileconfig)
if user_outdir then
autogendir = user_outdir
end