diff options
| author | ruki <[email protected]> | 2025-02-20 23:07:28 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-02-20 23:07:28 +0800 |
| commit | 9bba35fe3c7e835b638a94e54163e79a4d056ed0 (patch) | |
| tree | c27dd5929b520f098cd63426de0ba7dabb49b01e | |
| parent | 0098d8212430faf1833013d8fb447addb68a6ebb (diff) | |
fix kotlin runenvs
| -rw-r--r-- | xmake/modules/core/tools/kotlinc_native.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_kotlinc_native.lua | 8 | ||||
| -rw-r--r-- | xmake/toolchains/kotlin-native/xmake.lua | 41 |
3 files changed, 46 insertions, 10 deletions
diff --git a/xmake/modules/core/tools/kotlinc_native.lua b/xmake/modules/core/tools/kotlinc_native.lua index d637636b2..69929f6cb 100644 --- a/xmake/modules/core/tools/kotlinc_native.lua +++ b/xmake/modules/core/tools/kotlinc_native.lua @@ -29,14 +29,15 @@ function init(self) end -- make the build arguments list -function buildargv(self, sourcefiles, targetkind, targetfile, flags) +function buildargv(self, sourcefiles, targetkind, targetfile, flags, opt) return self:program(), table.join(flags, sourcefiles, "-o", targetfile) end -- build the target file -function build(self, sourcefiles, targetkind, targetfile, flags) +function build(self, sourcefiles, targetkind, targetfile, flags, opt) os.mkdir(path.directory(targetfile)) - os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags)) + local program, argv = buildargv(self, sourcefiles, targetkind, targetfile, flags) + os.runv(program, argv, {envs = self:runenvs()}) if targetkind == "binary" then local targetfile_real = targetfile .. (self:is_plat("windows") and ".exe" or ".kexe") if os.isfile(targetfile_real) then diff --git a/xmake/modules/detect/tools/find_kotlinc_native.lua b/xmake/modules/detect/tools/find_kotlinc_native.lua index c383a40d2..2fcbfdf3d 100644 --- a/xmake/modules/detect/tools/find_kotlinc_native.lua +++ b/xmake/modules/detect/tools/find_kotlinc_native.lua @@ -40,7 +40,13 @@ function main(opt) opt.check = opt.check or "-version" opt.command = opt.command or "-version" - local program = find_program(opt.program or ("kotlinc-native" .. (is_host("windows") and ".bat" or "")), opt) + local program = opt.program or "kotlinc-native" + if is_host("windows") then + program = program .. ".bat" + elseif is_host("linux") then + opt.shell = true + end + program = find_program(program, opt) local version = nil if program and opt and opt.version then version = find_programver(program, opt) diff --git a/xmake/toolchains/kotlin-native/xmake.lua b/xmake/toolchains/kotlin-native/xmake.lua index 3d239d71b..a3b5361d8 100644 --- a/xmake/toolchains/kotlin-native/xmake.lua +++ b/xmake/toolchains/kotlin-native/xmake.lua @@ -23,26 +23,46 @@ toolchain("kotlin-native") set_homepage("https://kotlinlang.org") set_description("The Kotlin Programming Language Compiler. ") - local suffix = is_host("windows") and ".bat" or "" - set_toolset("kc", "$(env KC)", "kotlinc-native" .. suffix) - set_toolset("kcld", "$(env KC)", "kotlinc-native" .. suffix) - set_toolset("kcsh", "$(env KC)", "kotlinc-native" .. suffix) - set_toolset("kcar", "$(env KC)", "kotlinc-native" .. suffix) + set_toolset("kc", "$(env KC)", "kotlinc-native") + set_toolset("kcld", "$(env KC)", "kotlinc-native") + set_toolset("kcsh", "$(env KC)", "kotlinc-native") + set_toolset("kcar", "$(env KC)", "kotlinc-native") on_check(function (toolchain) import("lib.detect.find_tool") local paths = {} + local runenvs = {} + local java_home = os.getenv("JAVA_HOME") + local pathenvs = os.getenv("PATH") + if pathenvs then + pathenvs = path.splitenv(pathenvs) + else + pathenvs = {} + end for _, package in ipairs(toolchain:packages()) do local envs = package:envs() if envs then table.join2(paths, envs.PATH) + table.join2(pathenvs, envs.PATH) + if not java_home then + java_home = envs.JAVA_HOME + end + end + end + if not find_tool("java") then + if #pathenvs > 0 then + runenvs.PATH = path.joinenv(pathenvs) + end + if java_home then + runenvs.JAVA_HOME = table.unwrap(java_home) end end if toolchain:bindir() then table.insert(paths, toolchain:bindir()) end - local kotlinc_native = find_tool("kotlinc-native", {paths = paths}) + + local kotlinc_native = find_tool("kotlinc-native", {paths = paths, envs = runenvs}) if kotlinc_native and kotlinc_native.program then kotlinc_native = kotlinc_native.program end @@ -51,6 +71,7 @@ toolchain("kotlin-native") local bindir = path.directory(kotlinc_native) toolchain:config_set("bindir", bindir) toolchain:config_set("sdkdir", path.directory(bindir)) + toolchain:config_set("runenvs", runenvs) end toolchain:configs_save() return true @@ -60,6 +81,14 @@ toolchain("kotlin-native") on_load(function (toolchain) import("private.core.base.is_cross") + -- bind runenvs for java + local runenvs = toolchain:config("runenvs") + if runenvs then + for k, v in pairs(runenvs) do + toolchain:add("runenvs", k, table.unpack(path.splitenv(v))) + end + end + -- kotlinc-native -list-targets local target_plat = toolchain:plat() local target_arch = toolchain:arch() |
