|
| 1 | +local tools = import "tools.libsonnet"; |
| 2 | +local _impl = import "run-spec-impl.libsonnet"; |
| 3 | +local r = import "run-spec.libsonnet"; |
| 4 | +{ |
| 5 | + examples:: { |
| 6 | + desugaring:: |
| 7 | + local _input = { |
| 8 | + "task": r.platform_spec({ |
| 9 | + "linux:amd64": r.task_spec({ "target": "gate" }), |
| 10 | + "linux:amd64:jdk19": r.task_spec({ "name": "task" }), |
| 11 | + }) |
| 12 | + }; |
| 13 | + local _result = { |
| 14 | + "linux": { |
| 15 | + "amd64": { |
| 16 | + "jdk19": r.task_spec({ "name": "task" }) + r.include, |
| 17 | + } + |
| 18 | + r.task_spec({ "target": "gate" }) + r.include, |
| 19 | + } |
| 20 | + }; |
| 21 | + std.assertEqual(_impl.get_platform_spec(_impl.desugar_task_dict(_input).task), _result) |
| 22 | + , |
| 23 | + desugaring_includes:: |
| 24 | + local _input = { |
| 25 | + "task": r.platform_spec({ |
| 26 | + "<all-os>": r.task_spec({ "target": "gate" }), |
| 27 | + "linux": r.task_spec({ "os": "linux" }), |
| 28 | + }) |
| 29 | + }; |
| 30 | + local _result = { |
| 31 | + "<all-os>": r.task_spec({ "target": "gate" }) + r.include, |
| 32 | + "linux": r.task_spec({ "os": "linux" }) + r.include, |
| 33 | + }; |
| 34 | + std.assertEqual(_impl.get_platform_spec(_impl.desugar_task_dict(_input).task), _result) |
| 35 | + , |
| 36 | + desugaring_star: |
| 37 | + local _input_star = { |
| 38 | + "task": r.platform_spec({ |
| 39 | + "*:amd64:jdk19": r.task_spec({}), |
| 40 | + "linux:*:jdk19": r.task_spec({}), |
| 41 | + "linux:amd64:*": r.task_spec({}), |
| 42 | + "*": r.task_spec({}), |
| 43 | + "*:aarch64": r.task_spec({}), |
| 44 | + "darwin:*": r.task_spec({}), |
| 45 | + }) |
| 46 | + }; |
| 47 | + local _input_long = { |
| 48 | + "task": r.platform_spec({ |
| 49 | + "<all-os>:amd64:jdk19": r.task_spec({}), |
| 50 | + "linux:<all-arch>:jdk19": r.task_spec({}), |
| 51 | + "linux:amd64:<all-jdk>": r.task_spec({}), |
| 52 | + "<all-os>": r.task_spec({}), |
| 53 | + "<all-os>:aarch64": r.task_spec({}), |
| 54 | + "darwin:<all-arch>": r.task_spec({}), |
| 55 | + }) |
| 56 | + }; |
| 57 | + std.assertEqual(_impl.get_platform_spec(_impl.desugar_task_dict(_input_long).task), _impl.get_platform_spec(_impl.desugar_task_dict(_input_star).task)) |
| 58 | + , |
| 59 | + pushdown:: |
| 60 | + local _input = { |
| 61 | + "task": _impl.add_platform_spec({ |
| 62 | + "<all-os>" : r.exclude, |
| 63 | + "linux": { |
| 64 | + "amd64": { |
| 65 | + "jdk19": r.task_spec({ "name": "task" }) + r.include, |
| 66 | + } + |
| 67 | + r.task_spec({ "target": "gate" }) + r.include, |
| 68 | + } |
| 69 | + }) |
| 70 | + }; |
| 71 | + local _result = { |
| 72 | + "linux": { |
| 73 | + "amd64": { |
| 74 | + "jdk11": r.task_spec({ |
| 75 | + "target": "gate", |
| 76 | + }), |
| 77 | + "jdk17": r.task_spec({ |
| 78 | + "target": "gate", |
| 79 | + }), |
| 80 | + "jdk19": r.task_spec({ |
| 81 | + "name": "task", |
| 82 | + "target": "gate", |
| 83 | + }), |
| 84 | + }, |
| 85 | + }, |
| 86 | + }; |
| 87 | + std.assertEqual(_impl.get_platform_spec(_impl.push_down_task_dict(_input).task), _result) |
| 88 | + , |
| 89 | + pushdown_all_os_exclude:: |
| 90 | + local _input = { |
| 91 | + "task": _impl.add_platform_spec({ |
| 92 | + "<all-os>" : r.exclude, |
| 93 | + "linux": { |
| 94 | + "amd64": r.include, |
| 95 | + } |
| 96 | + }) |
| 97 | + }; |
| 98 | + // The exclude is overridden because ["linux"]["amd64] is more specific than ["<all-os>"]. |
| 99 | + local _result = { |
| 100 | + "linux": { |
| 101 | + "amd64": { |
| 102 | + "jdk11": {}, |
| 103 | + "jdk17": {}, |
| 104 | + "jdk19": {}, |
| 105 | + }, |
| 106 | + }, |
| 107 | + }; |
| 108 | + std.assertEqual(_impl.get_platform_spec(_impl.push_down_task_dict(_input).task), _result) |
| 109 | + , |
| 110 | + pushdown_all_jdk_exclude:: |
| 111 | + local _input = { |
| 112 | + "task": _impl.add_platform_spec({ |
| 113 | + "<all-os>" : { |
| 114 | + "<all-arch>": { |
| 115 | + "<all-jdk>": r.exclude |
| 116 | + } |
| 117 | + }, |
| 118 | + "linux": { |
| 119 | + "amd64": r.include + { |
| 120 | + "jdk19": r.include |
| 121 | + }, |
| 122 | + } |
| 123 | + }) |
| 124 | + }; |
| 125 | + // The include on ["linux"]["amd64"] has no effect because ["<all-os>"]["<all-arch>"]["<all-jdk>"] |
| 126 | + // is more specific than ["linux"]["amd64"]. |
| 127 | + // |
| 128 | + // The include on ["linux"]["amd64"]["jdk19"] works because it is as specific as the exclude on |
| 129 | + // ["<all-os>"]["<all-arch>"]["<all-jdk>"], but the former is applied later than the wildcard |
| 130 | + // variant. |
| 131 | + local _result = { |
| 132 | + "linux": { |
| 133 | + "amd64": { |
| 134 | + "jdk19": {}, |
| 135 | + }, |
| 136 | + }, |
| 137 | + }; |
| 138 | + std.assertEqual(_impl.get_platform_spec(_impl.push_down_task_dict(_input).task), _result) |
| 139 | + , |
| 140 | + expand_variants:: |
| 141 | + local _input = { |
| 142 | + "task": _impl.add_platform_spec({ |
| 143 | + "linux": { |
| 144 | + "amd64": { |
| 145 | + "jdk19": r.task_spec({ "name": "task" }), |
| 146 | + } |
| 147 | + }, |
| 148 | + "variants": { |
| 149 | + "myvariant": { |
| 150 | + "linux": { |
| 151 | + "amd64": { |
| 152 | + "jdk19": r.task_spec({ "name": self.task_variant}), |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + }) |
| 158 | + }; |
| 159 | + local _result = { |
| 160 | + "linux": { |
| 161 | + "amd64": { |
| 162 | + "jdk19": [ |
| 163 | + r.task_spec({"name": "task"}), |
| 164 | + r.task_spec({"name": "myvariant"}), |
| 165 | + ], |
| 166 | + }, |
| 167 | + }, |
| 168 | + }; |
| 169 | + std.assertEqual(_impl.get_platform_spec(_impl.expand_variants_task_dict(_input).task), _result) |
| 170 | + , |
| 171 | + multiply:: |
| 172 | + local _input = { |
| 173 | + "task": r.task_spec({ "name": self.task_name, "platform" : std.join("-", [self.os, self.arch, self.jdk]) }) + _impl.add_platform_spec({ |
| 174 | + "linux": { |
| 175 | + "amd64": { |
| 176 | + "jdk19": [r.add_multiply( |
| 177 | + [ |
| 178 | + r.task_spec({"batch": 1}), |
| 179 | + r.task_spec({"batch": 2}), |
| 180 | + ] |
| 181 | + ) |
| 182 | + ], |
| 183 | + } |
| 184 | + }, |
| 185 | + }) |
| 186 | + }; |
| 187 | + local _result = { |
| 188 | + "task": [ |
| 189 | + { |
| 190 | + "batch": 1, |
| 191 | + "name": "task", |
| 192 | + "platform": "linux-amd64-jdk19", |
| 193 | + }, |
| 194 | + { |
| 195 | + "batch": 2, |
| 196 | + "name": "task", |
| 197 | + "platform": "linux-amd64-jdk19", |
| 198 | + }, |
| 199 | + ] |
| 200 | + }; |
| 201 | + std.assertEqual(_impl.generate_builds_dict(_input), _result) |
| 202 | + , |
| 203 | + evaluate_late:: |
| 204 | + local _input = { |
| 205 | + "task": [ |
| 206 | + { |
| 207 | + "name": "task", |
| 208 | + } + r.evaluate_late({ |
| 209 | + "second": function (b) { |
| 210 | + "name" : b.name + "-second" |
| 211 | + }, |
| 212 | + "first": function (b) { |
| 213 | + "name" : b.name + "-first" |
| 214 | + }, |
| 215 | + }), |
| 216 | + ] |
| 217 | + }; |
| 218 | + local _result = { |
| 219 | + "task": [ |
| 220 | + { |
| 221 | + "name": "task-first-second", |
| 222 | + }, |
| 223 | + ] |
| 224 | + }; |
| 225 | + std.assertEqual(_impl.apply_evaluate_late(_input), _result) |
| 226 | + , |
| 227 | + } |
| 228 | +} |
0 commit comments