Skip to content

Commit 63870bf

Browse files
committed
format code
1 parent 00725ee commit 63870bf

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

xmake/rules/swig/build_module_file.lua

+20-23
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function find_user_outdir(fileconfig)
2828
-- user specified output path
2929
if fileconfig and fileconfig.swigflags then
3030
-- find -outdir path
31-
for i , par in pairs(fileconfig.swigflags) do
31+
for i, par in ipairs(fileconfig.swigflags) do
3232
if par == "-outdir" then
3333
local dirpath = fileconfig.swigflags[i + 1]
3434
if os.isdir(dirpath) then
@@ -39,12 +39,12 @@ function find_user_outdir(fileconfig)
3939
end
4040
end
4141

42-
function jar_build(target , fileconfig , opt)
42+
function jar_build(target, fileconfig, opt)
4343
local javac = assert(find_tool("javac"), "javac not found!")
4444
local jar = assert(find_tool("jar"), "jar not found!")
4545

4646
local java_src_dir = path.join(target:autogendir(), "rules", "swig")
47-
local jar_dst_dir = path.join(target:autogendir(), "rules", "swig")
47+
local java_class_dir = java_src_dir
4848

4949
local user_outdir = find_user_outdir(fileconfig)
5050
if user_outdir then
@@ -55,28 +55,26 @@ function jar_build(target , fileconfig , opt)
5555
local autogenfiles = os.files(path.join(java_src_dir, "*.java"))
5656

5757
-- write file list
58-
local filelistname = os.tmpfile()
58+
local filelistname = path.join(java_src_dir, "buildlist.txt")
5959
local file = io.open(filelistname, "w")
6060
if file then
61-
for _, sourcebatch in pairs(autogenfiles) do
61+
for _, sourcebatch in ipairs(autogenfiles) do
6262
file:print(sourcebatch)
6363
end
6464
file:close()
6565
end
6666

6767
-- compile to class file
6868
progress.show(opt.progress, "${color.build.object}compiling.javac %s class file", target:name())
69-
os.vrunv(javac.program, {"--release", "17", "-d", jar_dst_dir , "@"..filelistname})
69+
os.vrunv(javac.program, {"--release", "17", "-d", java_class_dir, "@" .. filelistname})
7070

7171
-- generate jar file
72-
progress.show(opt.progress, "${color.build.object}compiling.jar %s", target:name()..".jar")
73-
os.vrunv(jar.program, {"-cf" , path.join(java_src_dir , target:name()..".jar") , jar_dst_dir})
72+
progress.show(opt.progress, "${color.build.object}compiling.jar %s", target:name() .. ".jar")
73+
os.vrunv(jar.program, {"-cf", path.join(java_src_dir, target:name() .. ".jar"), java_class_dir})
7474

7575
os.tryrm(filelistname)
7676
end
7777

78-
79-
8078
function swig_par(target, sourcefile, opt)
8179
-- get swig
8280
opt = opt or {}
@@ -90,7 +88,7 @@ function swig_par(target, sourcefile, opt)
9088

9189
-- add commands
9290
local moduletype = assert(target:data("swig.moduletype"), "swig.moduletype not found!")
93-
local argv = { "-" .. moduletype, "-o", sourcefile_cx }
91+
local argv = {"-" .. moduletype, "-o", sourcefile_cx}
9492
if opt.sourcekind == "cxx" then
9593
table.insert(argv, "-c++")
9694
end
@@ -119,13 +117,14 @@ function swig_par(target, sourcefile, opt)
119117
end
120118

121119
table.insert(argv, sourcefile)
122-
return { argv = argv
123-
, objectfile = objectfile
124-
, swig = swig
125-
, sourcefile_cx = sourcefile_cx
126-
, moduletype = moduletype
127-
, fileconfig = fileconfig
128-
}
120+
return {
121+
argv = argv,
122+
objectfile = objectfile,
123+
swig = swig,
124+
sourcefile_cx = sourcefile_cx,
125+
moduletype = moduletype,
126+
fileconfig = fileconfig
127+
}
129128
end
130129

131130
function swig_build_cmd(target, batchcmds, sourcefile, opt, pars)
@@ -149,7 +148,6 @@ function swig_build_cmd(target, batchcmds, sourcefile, opt, pars)
149148
batchcmds:set_depcache(target:dependfile(objectfile))
150149
end
151150

152-
153151
function swig_build_file(target, sourcefile, opt, par)
154152
local par = swig_par(target, sourcefile, opt)
155153

@@ -173,15 +171,15 @@ function swig_build_file(target, sourcefile, opt, par)
173171

174172
-- gen swig depend file , same with gcc .d
175173
local swigdep = os.tmpfile()
176-
local argv2 = {"-MMD" , "-MF" , swigdep}
174+
local argv2 = {"-MMD", "-MF", swigdep}
177175
table.join2(argv2, argv)
178176

179177
-- swig generate file and depend file
180178
os.vrunv(swig.program, argv2)
181179
compiler.compile(sourcefile_cx, objectfile, {target = target})
182180

183181
-- update depend file
184-
local deps = io.readfile(swigdep , {continuation = "\\"})
182+
local deps = io.readfile(swigdep, {continuation = "\\"})
185183
os.tryrm(swigdep)
186184
dependinfo.files = {sourcefile}
187185
dependinfo.depfiles_gcc = deps
@@ -191,7 +189,6 @@ function swig_build_file(target, sourcefile, opt, par)
191189
-- jar build
192190
local buildjar = target:extraconf("rules", "swig.c", "buildjar") or target:extraconf("rules", "swig.cpp", "buildjar")
193191
if moduletype == "java" and buildjar then
194-
jar_build(target , fileconfig , opt)
192+
jar_build(target, fileconfig, opt)
195193
end
196-
197194
end

xmake/rules/swig/xmake.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
rule("swig.base")
2828
on_load(function (target)
2929
target:set("kind", "shared")
30+
local find_user_outdir = import("build_module_file").find_user_outdir
3031
local moduletype = target:extraconf("rules", "swig.c", "moduletype") or target:extraconf("rules", "swig.cpp", "moduletype")
3132
if moduletype == "python" then
3233
target:set("prefixname", "_")
@@ -77,7 +78,7 @@ rule("swig.base")
7778
local autogenfiles
7879
local autogendir = path.join(target:autogendir(), "rules", "swig")
7980

80-
local user_outdir = import("build_module_file").find_user_outdir(fileconfig)
81+
local user_outdir = find_user_outdir(fileconfig)
8182
if user_outdir then
8283
autogendir = user_outdir
8384
end

0 commit comments

Comments
 (0)