Skip to content

Commit 147f1dd

Browse files
authored
d2x: fix lang switch failed issue (d2x-buildtools list bug) - add config api to config lang (#40)
- mcpp-community/OpenOrg#1 Signed-off-by: sunrisepeak <speakshen@163.com>
1 parent 9b9b9ff commit 147f1dd

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

d2x/buildtools/xmake/main.lua

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import("core.base.json")
22
import("core.base.option")
33
import("core.project.project")
4+
import("core.project.config")
5+
6+
local function get_d2x_lang()
7+
local d2x_json_file = path.join(os.projectdir(), ".d2x.json")
8+
if os.isfile(d2x_json_file) then
9+
local d2x_config = json.loadfile(d2x_json_file) or {}
10+
return d2x_config["lang"]
11+
end
12+
return nil
13+
end
414

515
function list()
16+
17+
config.load()
18+
local lang = get_d2x_lang()
19+
if lang and #lang > 0 then
20+
config.set("lang", lang, {force = true})
21+
end
22+
623
local targets = project.targets()
724
for name, _ in pairs(targets) do
825
local files = targets[name]:sourcefiles()
@@ -33,12 +50,9 @@ function main()
3350
--print("project file: " .. project.rootfile())
3451

3552
if command == "init" then
36-
local d2x_json_file = path.join(os.projectdir(), ".d2x.json")
37-
if os.isfile(d2x_json_file) then
38-
local d2x_config = json.loadfile(d2x_json_file) or {}
39-
if d2x_config["lang"] then
40-
os.exec("xmake f --lang=" .. d2x_config["lang"])
41-
end
53+
local lang = get_d2x_lang()
54+
if lang and #lang > 0 then
55+
os.exec("xmake f --lang=" .. lang)
4256
end
4357
elseif command == "list" then
4458
list()
@@ -50,4 +64,4 @@ function main()
5064
print("Unknown command: " .. tostring(command))
5165
end
5266

53-
end
67+
end

0 commit comments

Comments
 (0)