Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jar generate in swig mode #5536

Merged
merged 11 commits into from
Sep 6, 2024
Merged

add jar generate in swig mode #5536

merged 11 commits into from
Sep 6, 2024

Conversation

ririyeye
Copy link
Contributor

在使用swig生成java文件的场景下,添加javac和jar打包文件 这样可以直接使用jar包

使用方法如下 添加buildjar = true参数

- add_rules("swig.c", {moduletype = "java"})
+ add_rules("swig.c", {moduletype = "java" , buildjar = true})

@waruqi
Copy link
Member

waruqi commented Sep 4, 2024

最近有点忙,等后两天我看下

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I've been a little busy lately. I'll check it out in the next two days.

autogenfiles = os.files(path.join(autogendir, "*.java"))
local buildjar = target:extraconf("rules", "swig.c", "buildjar") or target:extraconf("rules", "swig.cpp", "buildjar")
if buildjar then
autogenfiles = path.join(autogendir , target:name()..".jar")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 ,.. 两边空格不对

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autogenfiles = path.join(autogendir, target:name() .. ".jar")

@@ -76,12 +76,23 @@ rule("swig.base")
end
local autogenfiles
local autogendir = path.join(target:autogendir(), "rules", "swig")

local user_outdir = import("build_module_file").find_user_outdir(fileconfig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 import 放到开头

-- 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, 两边空格不对

jar_build(target, fileconfig, opt)

@@ -73,3 +148,50 @@ function main(target, batchcmds, sourcefile, opt)
batchcmds:set_depmtime(os.mtime(objectfile))
batchcmds:set_depcache(target:dependfile(objectfile))
end


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删掉一个空行

end



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删掉多余的空行

-- user specified output path
if fileconfig and fileconfig.swigflags then
-- find -outdir path
for i , par in pairs(fileconfig.swigflags) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, 两边空格不对

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swigflags 是 array ,用 ipairs

end
end

function jar_build(target , fileconfig , opt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, 两边空格不对

local filelistname = os.tmpfile()
local file = io.open(filelistname, "w")
if file then
for _, sourcebatch in pairs(autogenfiles) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 ipairs


-- 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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. 两边加空格

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jar_dst_dir 后面的空格去掉


-- 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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. 两边空格,, 前面的空格去掉

local autogenfiles = os.files(path.join(java_src_dir, "*.java"))

-- write file list
local filelistname = os.tmpfile()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也挪到 autogendir 里去

@@ -63,6 +119,25 @@ function main(target, batchcmds, sourcefile, opt)
end

table.insert(argv, sourcefile)
return { argv = argv
, objectfile = objectfile
, swig = swig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

逗号放后面


-- gen swig depend file , same with gcc .d
local swigdep = os.tmpfile()
local argv2 = {"-MMD" , "-MF" , swigdep}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, 前面空格去掉

compiler.compile(sourcefile_cx, objectfile, {target = target})

-- update depend file
local deps = io.readfile(swigdep , {continuation = "\\"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有这的 空格

@waruqi waruqi merged commit c424990 into xmake-io:dev Sep 6, 2024
20 checks passed
@waruqi
Copy link
Member

waruqi commented Sep 6, 2024

thanks

@waruqi waruqi added this to the v2.9.5 milestone Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants