|
20 | 20 |
|
21 | 21 | -- imports
|
22 | 22 | import("lib.detect.find_tool")
|
| 23 | +import("utils.progress") |
| 24 | +import("core.project.depend") |
| 25 | +import("core.tool.compiler") |
23 | 26 |
|
24 |
| -function main(target, batchcmds, sourcefile, opt) |
| 27 | +function main(target, sourcefile, opt) |
25 | 28 | -- get swig
|
26 | 29 | opt = opt or {}
|
27 | 30 | local swig = assert(find_tool("swig"), "swig not found!")
|
@@ -63,13 +66,60 @@ function main(target, batchcmds, sourcefile, opt)
|
63 | 66 | end
|
64 | 67 |
|
65 | 68 | table.insert(argv, sourcefile)
|
66 |
| - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.swig.%s %s", moduletype, sourcefile) |
67 |
| - batchcmds:mkdir(path.directory(sourcefile_cx)) |
68 |
| - batchcmds:vrunv(swig.program, argv) |
69 |
| - batchcmds:compile(sourcefile_cx, objectfile) |
| 69 | + depend.on_changed(function () |
| 70 | + progress.show(opt.progress, "${color.build.object}compiling.swig.%s %s", moduletype, sourcefile) |
| 71 | + os.mkdir(path.directory(sourcefile_cx)) |
| 72 | + os.vrunv(swig.program, argv) |
| 73 | + compiler.compile(sourcefile_cx, objectfile, {target = target}) |
70 | 74 |
|
71 |
| - -- add deps |
72 |
| - batchcmds:add_depfiles(sourcefile) |
73 |
| - batchcmds:set_depmtime(os.mtime(objectfile)) |
74 |
| - batchcmds:set_depcache(target:dependfile(objectfile)) |
| 75 | + local buildjar = target:extraconf("rules", "swig.c", "buildjar") or target:extraconf("rules", "swig.cpp", "buildjar") |
| 76 | + if moduletype == "java" and buildjar then |
| 77 | + local javac = assert(find_tool("javac"), "javac not found!") |
| 78 | + local jar = assert(find_tool("jar"), "jar not found!") |
| 79 | + |
| 80 | + local java_src_dir = path.join(target:autogendir(), "rules", "swig") |
| 81 | + local jar_dst_dir = path.join(target:autogendir(), "rules", "swig") |
| 82 | + |
| 83 | + -- user specified output path |
| 84 | + if fileconfig and fileconfig.swigflags then |
| 85 | + -- find -outdir path |
| 86 | + local idx = -1 |
| 87 | + for i , par in pairs(fileconfig.swigflags) do |
| 88 | + if par == "-outdir" then |
| 89 | + idx = i |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + if idx > 0 then |
| 94 | + java_src_dir = fileconfig.swigflags[idx + 1] |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + -- get java files |
| 99 | + local autogenfiles = os.files(path.join(java_src_dir, "*.java")) |
| 100 | + |
| 101 | + -- write file list |
| 102 | + local filelistname = os.tmpfile() |
| 103 | + local file = io.open(filelistname, "w") |
| 104 | + if file then |
| 105 | + for _, sourcebatch in pairs(autogenfiles) do |
| 106 | + file:print(sourcebatch) |
| 107 | + end |
| 108 | + file:close() |
| 109 | + end |
| 110 | + |
| 111 | + -- compile to class file |
| 112 | + progress.show(opt.progress, "${color.build.object}compiling.javac %s class file", target:name()) |
| 113 | + os.vrunv(javac.program, {"--release", "17", "-d", jar_dst_dir , "@"..filelistname}) |
| 114 | + |
| 115 | + -- generate jar file |
| 116 | + progress.show(opt.progress, "${color.build.object}compiling.jar %s", target:name()..".jar") |
| 117 | + os.vrunv(jar.program, {"-cf" , path.join(java_src_dir , target:name()..".jar") , jar_dst_dir}) |
| 118 | + end |
| 119 | + |
| 120 | + end, {dependfile = target:dependfile(objectfile), |
| 121 | + lastmtime = os.mtime(objectfile), |
| 122 | + files = sourcefile, |
| 123 | + values = argv, |
| 124 | + changed = target:is_rebuilt()}) |
75 | 125 | end
|
0 commit comments