mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 04:50:29 +00:00
Add -vet-packages:<comma-separated-string-array>
This commit is contained in:
@@ -383,6 +383,7 @@ struct BuildContext {
|
||||
|
||||
u64 vet_flags;
|
||||
u32 sanitizer_flags;
|
||||
StringSet vet_packages;
|
||||
|
||||
bool has_resource;
|
||||
String link_flags;
|
||||
@@ -1462,8 +1463,6 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
|
||||
bc->thread_count = gb_max(bc->affinity.thread_count, 1);
|
||||
}
|
||||
|
||||
string_set_init(&bc->custom_attributes);
|
||||
|
||||
bc->ODIN_VENDOR = str_lit("odin");
|
||||
bc->ODIN_VERSION = ODIN_VERSION;
|
||||
bc->ODIN_ROOT = odin_root_dir();
|
||||
|
||||
@@ -533,18 +533,13 @@ gb_internal u64 check_vet_flags(CheckerContext *c) {
|
||||
c->curr_proc_decl->proc_lit) {
|
||||
file = c->curr_proc_decl->proc_lit->file();
|
||||
}
|
||||
if (file && file->vet_flags_set) {
|
||||
return file->vet_flags;
|
||||
}
|
||||
return build_context.vet_flags;
|
||||
|
||||
return ast_file_vet_flags(file);
|
||||
}
|
||||
|
||||
gb_internal u64 check_vet_flags(Ast *node) {
|
||||
AstFile *file = node->file();
|
||||
if (file && file->vet_flags_set) {
|
||||
return file->vet_flags;
|
||||
}
|
||||
return build_context.vet_flags;
|
||||
return ast_file_vet_flags(file);
|
||||
}
|
||||
|
||||
enum VettedEntityKind {
|
||||
@@ -6497,10 +6492,7 @@ gb_internal void check_parsed_files(Checker *c) {
|
||||
TIME_SECTION("check scope usage");
|
||||
for (auto const &entry : c->info.files) {
|
||||
AstFile *f = entry.value;
|
||||
u64 vet_flags = build_context.vet_flags;
|
||||
if (f->vet_flags_set) {
|
||||
vet_flags = f->vet_flags;
|
||||
}
|
||||
u64 vet_flags = ast_file_vet_flags(f);
|
||||
check_scope_usage(c, f->scope, vet_flags);
|
||||
}
|
||||
|
||||
|
||||
30
src/main.cpp
30
src/main.cpp
@@ -346,6 +346,7 @@ enum BuildFlagKind {
|
||||
BuildFlag_VetSemicolon,
|
||||
BuildFlag_VetCast,
|
||||
BuildFlag_VetTabs,
|
||||
BuildFlag_VetPackages,
|
||||
|
||||
BuildFlag_CustomAttribute,
|
||||
BuildFlag_IgnoreUnknownAttributes,
|
||||
@@ -555,6 +556,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
add_flag(&build_flags, BuildFlag_VetSemicolon, str_lit("vet-semicolon"), BuildFlagParam_None, Command__does_check);
|
||||
add_flag(&build_flags, BuildFlag_VetCast, str_lit("vet-cast"), BuildFlagParam_None, Command__does_check);
|
||||
add_flag(&build_flags, BuildFlag_VetTabs, str_lit("vet-tabs"), BuildFlagParam_None, Command__does_check);
|
||||
add_flag(&build_flags, BuildFlag_VetPackages, str_lit("vet-packages"), BuildFlagParam_String, Command__does_check);
|
||||
|
||||
add_flag(&build_flags, BuildFlag_CustomAttribute, str_lit("custom-attribute"), BuildFlagParam_String, Command__does_check, true);
|
||||
add_flag(&build_flags, BuildFlag_IgnoreUnknownAttributes, str_lit("ignore-unknown-attributes"), BuildFlagParam_None, Command__does_check);
|
||||
@@ -1221,6 +1223,29 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
case BuildFlag_VetCast: build_context.vet_flags |= VetFlag_Cast; break;
|
||||
case BuildFlag_VetTabs: build_context.vet_flags |= VetFlag_Tabs; break;
|
||||
|
||||
case BuildFlag_VetPackages:
|
||||
{
|
||||
GB_ASSERT(value.kind == ExactValue_String);
|
||||
String val = value.value_string;
|
||||
String_Iterator it = {val, 0};
|
||||
for (;;) {
|
||||
String pkg = string_split_iterator(&it, ',');
|
||||
if (pkg.len == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
pkg = string_trim_whitespace(pkg);
|
||||
if (!string_is_valid_identifier(pkg)) {
|
||||
gb_printf_err("-%.*s '%.*s' must be a valid identifier\n", LIT(name), LIT(pkg));
|
||||
bad_flags = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
string_set_add(&build_context.vet_packages, pkg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BuildFlag_CustomAttribute:
|
||||
{
|
||||
GB_ASSERT(value.kind == ExactValue_String);
|
||||
@@ -1234,7 +1259,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
|
||||
attr = string_trim_whitespace(attr);
|
||||
if (!string_is_valid_identifier(attr)) {
|
||||
gb_printf_err("-custom-attribute '%.*s' must be a valid identifier\n", LIT(attr));
|
||||
gb_printf_err("-%.*s '%.*s' must be a valid identifier\n", LIT(name), LIT(attr));
|
||||
bad_flags = true;
|
||||
continue;
|
||||
}
|
||||
@@ -3150,6 +3175,9 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
|
||||
build_context.command = command;
|
||||
|
||||
string_set_init(&build_context.custom_attributes);
|
||||
string_set_init(&build_context.vet_packages);
|
||||
|
||||
if (!parse_build_flags(args)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
#include "parser_pos.cpp"
|
||||
|
||||
gb_internal bool in_vet_packages(AstFile *file) {
|
||||
if (file == nullptr) {
|
||||
return true;
|
||||
}
|
||||
if (file->pkg == nullptr) {
|
||||
return true;
|
||||
}
|
||||
if (build_context.vet_packages.entries.count == 0) {
|
||||
return true;
|
||||
}
|
||||
return string_set_exists(&build_context.vet_packages, file->pkg->name);
|
||||
}
|
||||
|
||||
gb_internal u64 ast_file_vet_flags(AstFile *f) {
|
||||
if (f != nullptr && f->vet_flags_set) {
|
||||
return f->vet_flags;
|
||||
}
|
||||
return build_context.vet_flags;
|
||||
|
||||
bool found = in_vet_packages(f);
|
||||
if (found) {
|
||||
return build_context.vet_flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
gb_internal bool ast_file_vet_style(AstFile *f) {
|
||||
@@ -5372,18 +5390,9 @@ gb_internal Ast *parse_stmt(AstFile *f) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
gb_internal u64 check_vet_flags(AstFile *file) {
|
||||
if (file && file->vet_flags_set) {
|
||||
return file->vet_flags;
|
||||
}
|
||||
return build_context.vet_flags;
|
||||
}
|
||||
|
||||
|
||||
gb_internal void parse_enforce_tabs(AstFile *f) {
|
||||
// Checks to see if tabs have been used for indentation
|
||||
if ((check_vet_flags(f) & VetFlag_Tabs) == 0) {
|
||||
if ((ast_file_vet_flags(f) & VetFlag_Tabs) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user