-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathxmake.lua
More file actions
134 lines (125 loc) · 4.53 KB
/
Copy pathxmake.lua
File metadata and controls
134 lines (125 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
set_xmakever("2.9.2") -- Minimum version for build.fence policy and BPF source compilation
-- includes
includes("xmake/repos.lua")
-- rules
add_rules("mode.release", "mode.debug")
-- traffico
target("traffico")
set_kind("binary")
set_default(true)
includes("api")
add_deps("api")
add_deps("chain")
add_deps("intent-bpf")
add_deps("bpf")
add_packages("libbpf")
add_files({ "traffico.c" }, { languages = { "c11" }})
target_end()
-- traffico-cni
add_requires("cjson")
target("traffico-cni")
set_kind("binary")
add_packages("cjson")
includes("api")
add_deps("api")
add_deps("bpf")
add_packages("libbpf")
add_files({ "traffico-cni.c" }, { languages = { "c11" }})
target_end()
-- test
add_requires("bats v1.11.1", { system = false })
add_requires("mini_httpd", { system = false })
target("intent-ir-unit")
set_kind("binary")
set_default(false)
add_includedirs(".")
add_files({ "test/intent_unit.c" }, { languages = { "c11" }})
target_end()
target("ddag-unit")
set_kind("binary")
set_default(false)
add_includedirs(".")
add_files({ "test/ddag_unit.c" }, { languages = { "c11" }})
target_end()
target("enforcement-unit")
set_kind("binary")
set_default(false)
add_includedirs(".")
add_files({ "test/enforcement_unit.c" }, { languages = { "c11" }})
target_end()
target("intent-bpf-unit")
set_kind("binary")
set_default(false)
add_includedirs(".")
add_files({ "test/intent_bpf_unit.c" }, { languages = { "c11" }})
target_end()
target("test")
set_kind("phony")
add_packages("bats", "mini_httpd")
on_run(function (target)
import("core.base.option")
local bats_args = {"-t"}
local selected = table.wrap(option.get("arguments"))
local build_targets = {}
local selected_test_paths = 0
if #selected == 0 then
table.insert(bats_args, "test/")
build_targets = {"traffico", "traffico-cni", "intent-ir-unit", "ddag-unit", "enforcement-unit", "intent-bpf-unit"}
else
local needs_full_suite_targets = false
local needs_intent_ir_unit = false
local needs_ddag_unit = false
local needs_enforcement_unit = false
local needs_intent_bpf_unit = false
for _, arg in ipairs(selected) do
table.insert(bats_args, arg)
if arg == "test" or arg == "test/" or arg:find("%.bats$") then
selected_test_paths = selected_test_paths + 1
if arg:find("intent_unit", 1, true) then
needs_intent_ir_unit = true
elseif arg:find("ddag_unit", 1, true) then
needs_ddag_unit = true
elseif arg:find("enforcement_unit", 1, true) then
needs_enforcement_unit = true
elseif arg:find("intent_bpf_unit", 1, true) then
needs_intent_bpf_unit = true
else
needs_full_suite_targets = true
end
end
end
if selected_test_paths == 0 then
table.insert(bats_args, "test/")
build_targets = {"traffico", "traffico-cni", "intent-ir-unit", "ddag-unit", "enforcement-unit", "intent-bpf-unit"}
elseif needs_full_suite_targets then
build_targets = {"traffico", "traffico-cni", "intent-ir-unit", "ddag-unit", "enforcement-unit", "intent-bpf-unit"}
else
if needs_intent_ir_unit then
table.insert(build_targets, "intent-ir-unit")
end
if needs_ddag_unit then
table.insert(build_targets, "ddag-unit")
end
if needs_enforcement_unit then
table.insert(build_targets, "enforcement-unit")
end
if needs_intent_bpf_unit then
table.insert(build_targets, "intent-bpf-unit")
end
end
end
for _, name in ipairs(build_targets) do
os.execv("xmake", {"build", "-y", name})
end
import("core.project.project")
for _, name in ipairs(build_targets) do
local built = project.target(name)
if built then
os.addenv("PATH", path.absolute(built:targetdir()))
end
end
os.addenv("PATH", path.absolute("tools"))
import("privilege.sudo")
sudo.execv("bats", bats_args)
end)
target_end()