@@ -28,7 +28,7 @@ function find_user_outdir(fileconfig)
28
28
-- user specified output path
29
29
if fileconfig and fileconfig .swigflags then
30
30
-- find -outdir path
31
- for i , par in pairs (fileconfig .swigflags ) do
31
+ for i , par in ipairs (fileconfig .swigflags ) do
32
32
if par == " -outdir" then
33
33
local dirpath = fileconfig .swigflags [i + 1 ]
34
34
if os .isdir (dirpath ) then
@@ -39,12 +39,12 @@ function find_user_outdir(fileconfig)
39
39
end
40
40
end
41
41
42
- function jar_build (target , fileconfig , opt )
42
+ function jar_build (target , fileconfig , opt )
43
43
local javac = assert (find_tool (" javac" ), " javac not found!" )
44
44
local jar = assert (find_tool (" jar" ), " jar not found!" )
45
45
46
46
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
48
48
49
49
local user_outdir = find_user_outdir (fileconfig )
50
50
if user_outdir then
@@ -55,28 +55,26 @@ function jar_build(target , fileconfig , opt)
55
55
local autogenfiles = os .files (path .join (java_src_dir , " *.java" ))
56
56
57
57
-- write file list
58
- local filelistname = os . tmpfile ( )
58
+ local filelistname = path . join ( java_src_dir , " buildlist.txt " )
59
59
local file = io.open (filelistname , " w" )
60
60
if file then
61
- for _ , sourcebatch in pairs (autogenfiles ) do
61
+ for _ , sourcebatch in ipairs (autogenfiles ) do
62
62
file :print (sourcebatch )
63
63
end
64
64
file :close ()
65
65
end
66
66
67
67
-- compile to class file
68
68
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 })
70
70
71
71
-- 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 })
74
74
75
75
os .tryrm (filelistname )
76
76
end
77
77
78
-
79
-
80
78
function swig_par (target , sourcefile , opt )
81
79
-- get swig
82
80
opt = opt or {}
@@ -90,7 +88,7 @@ function swig_par(target, sourcefile, opt)
90
88
91
89
-- add commands
92
90
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 }
94
92
if opt .sourcekind == " cxx" then
95
93
table.insert (argv , " -c++" )
96
94
end
@@ -119,13 +117,14 @@ function swig_par(target, sourcefile, opt)
119
117
end
120
118
121
119
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
+ }
129
128
end
130
129
131
130
function swig_build_cmd (target , batchcmds , sourcefile , opt , pars )
@@ -149,7 +148,6 @@ function swig_build_cmd(target, batchcmds, sourcefile, opt, pars)
149
148
batchcmds :set_depcache (target :dependfile (objectfile ))
150
149
end
151
150
152
-
153
151
function swig_build_file (target , sourcefile , opt , par )
154
152
local par = swig_par (target , sourcefile , opt )
155
153
@@ -173,15 +171,15 @@ function swig_build_file(target, sourcefile, opt, par)
173
171
174
172
-- gen swig depend file , same with gcc .d
175
173
local swigdep = os .tmpfile ()
176
- local argv2 = {" -MMD" , " -MF" , swigdep }
174
+ local argv2 = {" -MMD" , " -MF" , swigdep }
177
175
table .join2 (argv2 , argv )
178
176
179
177
-- swig generate file and depend file
180
178
os .vrunv (swig .program , argv2 )
181
179
compiler .compile (sourcefile_cx , objectfile , {target = target })
182
180
183
181
-- update depend file
184
- local deps = io .readfile (swigdep , {continuation = " \\ " })
182
+ local deps = io .readfile (swigdep , {continuation = " \\ " })
185
183
os .tryrm (swigdep )
186
184
dependinfo .files = {sourcefile }
187
185
dependinfo .depfiles_gcc = deps
@@ -191,7 +189,6 @@ function swig_build_file(target, sourcefile, opt, par)
191
189
-- jar build
192
190
local buildjar = target :extraconf (" rules" , " swig.c" , " buildjar" ) or target :extraconf (" rules" , " swig.cpp" , " buildjar" )
193
191
if moduletype == " java" and buildjar then
194
- jar_build (target , fileconfig , opt )
192
+ jar_build (target , fileconfig , opt )
195
193
end
196
-
197
194
end
0 commit comments