aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaytan <laytanlaats@hotmail.com>2024-12-01 19:13:59 +0100
committerGitHub <noreply@github.com>2024-12-01 19:13:59 +0100
commit03a53ccce2ada65c3179328ddcb00bb2b990d3db (patch)
tree71bcab79eec52c387414ad1583756aee249f2c12
parent314c41ef33a2d11e4313ecca0c708b8d02cd59d7 (diff)
parent26415bcb0e7941fdeb53721c991c0c80104e1efe (diff)
Merge pull request #4546 from thetarnav/correct-parsing-build-tag-newlines
Correct handling newlines between build tags in `core:odin`
-rw-r--r--core/odin/parser/file_tags.odin24
-rw-r--r--tests/core/odin/test_file_tags.odin21
2 files changed, 30 insertions, 15 deletions
diff --git a/core/odin/parser/file_tags.odin b/core/odin/parser/file_tags.odin
index 84b172148..c5c6637c3 100644
--- a/core/odin/parser/file_tags.odin
+++ b/core/odin/parser/file_tags.odin
@@ -17,6 +17,9 @@ Build_Kind :: struct {
arch: runtime.Odin_Arch_Types,
}
+// empty build kind acts as a marker for separating multiple lines with build tags
+BUILD_KIND_NEWLINE_MARKER :: Build_Kind{}
+
File_Tags :: struct {
build_project_name: [][]string,
build: []Build_Kind,
@@ -147,6 +150,11 @@ parse_file_tags :: proc(file: ast.File, allocator := context.allocator) -> (tags
append(build_project_names, build_project_name_strings[index_start:])
}
case "build":
+
+ if len(build_kinds) > 0 {
+ append(build_kinds, BUILD_KIND_NEWLINE_MARKER)
+ }
+
kinds_loop: for {
os_positive: runtime.Odin_OS_Types
os_negative: runtime.Odin_OS_Types
@@ -248,10 +256,20 @@ match_build_tags :: proc(file_tags: File_Tags, target: Build_Target) -> bool {
project_name_correct ||= group_correct
}
- os_and_arch_correct := len(file_tags.build) == 0
+ os_and_arch_correct := true
- for kind in file_tags.build {
- os_and_arch_correct ||= target.os in kind.os && target.arch in kind.arch
+ if len(file_tags.build) > 0 {
+ os_and_arch_correct_line := false
+
+ for kind in file_tags.build {
+ if kind == BUILD_KIND_NEWLINE_MARKER {
+ os_and_arch_correct &&= os_and_arch_correct_line
+ os_and_arch_correct_line = false
+ } else {
+ os_and_arch_correct_line ||= target.os in kind.os && target.arch in kind.arch
+ }
+ }
+ os_and_arch_correct &&= os_and_arch_correct_line
}
return !file_tags.ignore && project_name_correct && os_and_arch_correct
diff --git a/tests/core/odin/test_file_tags.odin b/tests/core/odin/test_file_tags.odin
index ec686f279..99a995be5 100644
--- a/tests/core/odin/test_file_tags.odin
+++ b/tests/core/odin/test_file_tags.odin
@@ -46,14 +46,16 @@ package main
{os = {.OpenBSD}, arch = runtime.ALL_ODIN_ARCH_TYPES},
{os = {.NetBSD}, arch = runtime.ALL_ODIN_ARCH_TYPES},
{os = {.Haiku}, arch = runtime.ALL_ODIN_ARCH_TYPES},
+ parser.BUILD_KIND_NEWLINE_MARKER,
{os = runtime.ALL_ODIN_OS_TYPES, arch = {.arm32}},
{os = runtime.ALL_ODIN_OS_TYPES, arch = {.arm64}},
},
},
matching_targets = {
- {{.Linux, .amd64, "foo"}, true},
- {{.Windows, .arm64, "foo"}, true},
+ {{.Linux, .amd64, "foo"}, false},
+ {{.Linux, .arm64, "foo"}, true},
{{.Windows, .amd64, "foo"}, false},
+ {{.Windows, .arm64, "foo"}, false},
},
}, {// [3]
src = `
@@ -82,17 +84,12 @@ package main
tags = {
build_project_name = {{"foo", "!bar"}, {"baz"}},
build = {
- {
- os = {.JS},
- arch = {.wasm32},
- }, {
- os = {.JS},
- arch = {.wasm64p32},
- },
+ {os = {.JS}, arch = {.wasm32}},
+ {os = {.JS}, arch = {.wasm64p32}},
},
},
matching_targets = {
- {{.JS, .wasm32, "foo"}, true},
+ {{.JS, .wasm32, "foo"}, true},
{{.JS, .wasm64p32, "baz"}, true},
{{.JS, .wasm64p32, "bar"}, false},
},
@@ -108,9 +105,9 @@ package main`,
},
},
matching_targets = {
- {{.Freestanding, .wasm32, ""}, true},
+ {{.Freestanding, .wasm32, ""}, true},
{{.Freestanding, .wasm64p32, ""}, true},
- {{.Freestanding, .arm64, ""}, false},
+ {{.Freestanding, .arm64, ""}, false},
},
},
}