mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Handle multiple +build package tags with '!' (nots)
This commit is contained in:
+57
-39
@@ -4217,6 +4217,22 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String build_tag_get_token(String s, String *out) {
|
||||||
|
s = string_trim_whitespace(s);
|
||||||
|
isize n = 0;
|
||||||
|
while (n < s.len) {
|
||||||
|
Rune rune = 0;
|
||||||
|
isize width = gb_utf8_decode(&s[n], s.len-n, &rune);
|
||||||
|
if (rune_is_whitespace(rune)) {
|
||||||
|
*out = substring(s, n+width, s.len);
|
||||||
|
return substring(s, 0, n);
|
||||||
|
}
|
||||||
|
n += width;
|
||||||
|
}
|
||||||
|
out->len = 0;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
bool parse_build_tag(Token token_for_pos, String s) {
|
bool parse_build_tag(Token token_for_pos, String s) {
|
||||||
String const prefix = str_lit("+build");
|
String const prefix = str_lit("+build");
|
||||||
GB_ASSERT(string_starts_with(s, prefix));
|
GB_ASSERT(string_starts_with(s, prefix));
|
||||||
@@ -4226,49 +4242,51 @@ bool parse_build_tag(Token token_for_pos, String s) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto platforms = array_make<String>(heap_allocator());
|
|
||||||
defer (array_free(&platforms));
|
|
||||||
|
|
||||||
isize n = 0;
|
|
||||||
while (n < s.len) {
|
|
||||||
Rune rune = 0;
|
|
||||||
isize width = gb_utf8_decode(&s[n], s.len, &rune);
|
|
||||||
if (rune_is_whitespace(rune)) {
|
|
||||||
String f = substring(s, 0, n);
|
|
||||||
array_add(&platforms, f);
|
|
||||||
s = substring(s, n+width, s.len);
|
|
||||||
n = 0;
|
|
||||||
continue;
|
|
||||||
} else if (n+width == s.len) {
|
|
||||||
String f = substring(s, 0, n+width);
|
|
||||||
array_add(&platforms, f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
n += width;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool any_correct = false;
|
bool any_correct = false;
|
||||||
for_array(i, platforms) {
|
|
||||||
String p = platforms[i];
|
do {
|
||||||
TargetOsKind os = get_target_os_from_string(p);
|
String p = build_tag_get_token(s, &s);
|
||||||
TargetArchKind arch = get_target_arch_from_string(p);
|
if (p.len == 0) break;
|
||||||
if (os != TargetOs_Invalid) {
|
bool is_notted = false;
|
||||||
GB_ASSERT(arch == TargetArch_Invalid);
|
if (p[0] == '!') {
|
||||||
any_correct = true;
|
is_notted = true;
|
||||||
if (os == build_context.target_os) {
|
p = substring(p, 1, p.len);
|
||||||
return true;
|
if (p.len == 0) {
|
||||||
}
|
error(token_for_pos, "Expected a build platform after '!'");
|
||||||
} else if (arch != TargetArch_Invalid) {
|
break;
|
||||||
any_correct = true;
|
|
||||||
if (arch == build_context.target_arch) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (os == TargetOs_Invalid && arch == TargetArch_Invalid) {
|
|
||||||
error(token_for_pos, "Invalid build tag platform: %.*s", LIT(p));
|
if (p.len > 0) {
|
||||||
|
TargetOsKind os = get_target_os_from_string(p);
|
||||||
|
TargetArchKind arch = get_target_arch_from_string(p);
|
||||||
|
if (os != TargetOs_Invalid) {
|
||||||
|
GB_ASSERT(arch == TargetArch_Invalid);
|
||||||
|
any_correct = true;
|
||||||
|
if (is_notted) {
|
||||||
|
if (os != build_context.target_os) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (os == build_context.target_os) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (arch != TargetArch_Invalid) {
|
||||||
|
any_correct = true;
|
||||||
|
if (is_notted) {
|
||||||
|
if (arch != build_context.target_arch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (arch == build_context.target_arch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (os == TargetOs_Invalid && arch == TargetArch_Invalid) {
|
||||||
|
error(token_for_pos, "Invalid build tag platform: %.*s", LIT(p));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (s.len > 0);
|
||||||
|
|
||||||
if (any_correct) {
|
if (any_correct) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user