Browse Source

Merge pull request #4546 from thetarnav/correct-parsing-build-tag-newlines

Correct handling newlines between build tags in `core:odin`
Laytan 8 months ago
parent
commit
03a53ccce2
2 changed files with 30 additions and 15 deletions
  1. 21 3
      core/odin/parser/file_tags.odin
  2. 9 12
      tests/core/odin/test_file_tags.odin

+ 21 - 3
core/odin/parser/file_tags.odin

@@ -17,6 +17,9 @@ Build_Kind :: struct {
 	arch: runtime.Odin_Arch_Types,
 	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 {
 File_Tags :: struct {
 	build_project_name: [][]string,
 	build_project_name: [][]string,
 	build:              []Build_Kind,
 	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:])
 					append(build_project_names, build_project_name_strings[index_start:])
 				}
 				}
 			case "build":
 			case "build":
+
+				if len(build_kinds) > 0 {
+					append(build_kinds, BUILD_KIND_NEWLINE_MARKER)
+				}
+
 				kinds_loop: for {
 				kinds_loop: for {
 					os_positive: runtime.Odin_OS_Types
 					os_positive: runtime.Odin_OS_Types
 					os_negative: 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
 		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
 	return !file_tags.ignore && project_name_correct && os_and_arch_correct

+ 9 - 12
tests/core/odin/test_file_tags.odin

@@ -46,14 +46,16 @@ package main
 					{os = {.OpenBSD}, arch = runtime.ALL_ODIN_ARCH_TYPES},
 					{os = {.OpenBSD}, arch = runtime.ALL_ODIN_ARCH_TYPES},
 					{os = {.NetBSD},  arch = runtime.ALL_ODIN_ARCH_TYPES},
 					{os = {.NetBSD},  arch = runtime.ALL_ODIN_ARCH_TYPES},
 					{os = {.Haiku},   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 = {.arm32}},
 					{os = runtime.ALL_ODIN_OS_TYPES, arch = {.arm64}},
 					{os = runtime.ALL_ODIN_OS_TYPES, arch = {.arm64}},
 				},
 				},
 			},
 			},
 			matching_targets = {
 			matching_targets = {
-				{{.Linux, .amd64, "foo"}, true},
-				{{.Windows, .arm64, "foo"}, true},
+				{{.Linux,   .amd64, "foo"}, false},
+				{{.Linux,   .arm64, "foo"}, true},
 				{{.Windows, .amd64, "foo"}, false},
 				{{.Windows, .amd64, "foo"}, false},
+				{{.Windows, .arm64, "foo"}, false},
 			},
 			},
 		}, {// [3]
 		}, {// [3]
 			src = `
 			src = `
@@ -82,17 +84,12 @@ package main
 			tags = {
 			tags = {
 				build_project_name = {{"foo", "!bar"}, {"baz"}},
 				build_project_name = {{"foo", "!bar"}, {"baz"}},
 				build = {
 				build = {
-					{
-						os = {.JS},
-						arch = {.wasm32},
-					}, {
-						os = {.JS},
-						arch = {.wasm64p32},
-					},
+					{os = {.JS}, arch = {.wasm32}},
+					{os = {.JS}, arch = {.wasm64p32}},
 				},
 				},
 			},
 			},
 			matching_targets = {
 			matching_targets = {
-				{{.JS, .wasm32, "foo"}, true},
+				{{.JS, .wasm32,    "foo"}, true},
 				{{.JS, .wasm64p32, "baz"}, true},
 				{{.JS, .wasm64p32, "baz"}, true},
 				{{.JS, .wasm64p32, "bar"}, false},
 				{{.JS, .wasm64p32, "bar"}, false},
 			},
 			},
@@ -108,9 +105,9 @@ package main`,
 				},
 				},
 			},
 			},
 			matching_targets = {
 			matching_targets = {
-				{{.Freestanding, .wasm32, ""}, true},
+				{{.Freestanding, .wasm32,    ""}, true},
 				{{.Freestanding, .wasm64p32, ""}, true},
 				{{.Freestanding, .wasm64p32, ""}, true},
-				{{.Freestanding, .arm64, ""}, false},
+				{{.Freestanding, .arm64,     ""}, false},
 			},
 			},
 		},
 		},
 	}
 	}