How to do #+vet explisit-allocators globally?

So, there is a #+vet explisit-allocators tag that i can add at the top of my files. But i want to pass it globally, as a build flag, because i don’t want to manually include it in every file. But if i do odin build ... -vet-explisit-allocators there is no such flag. Am i missing something?

It can’t be applied globally, because “globally” would include base, core, and other packages that may not be written to adhere to it. That’s why it’s strictly per-file.

1 Like

thanks! it makes sense

Edit: I decided on a better way. These will add/ remove “#+vet explicit-allocators” respectively to all .odin files in current directory

If you are looking for a way to turn it on and off without having to edit the files manually, and you are on linux, could do the following. Maybe add it to a build script(s) or create an alias for each to turn on/off. Backup files just in case something gets fat-fingered in the build script and/or alias. sed may work differently on other OSes like Mac or BSD. The below add/remove “#+vet explicit-allocators” to top of all .odin files.

// add line
// first test without -i
grep -qF '#+vet explicit-allocators' *.odin || sed '1i#+vet explicit-allocators' *.odin
// then if all looks good, add -i to sed command
grep -qF '#+vet explicit-allocators' *.odin || sed -i '1i#+vet explicit-allocators' *.odin

// remove line
// first test without -i
sed '/#+vet explicit-allocators/d' *.odin
// then if all looks good, add -i to sed command
sed -i '/#+vet explicit-allocators/d' *.odin

// .bash_aliases
alias vet-explicit-allocators='grep -qF "#+vet explicit-allocators" *.odin || sed -i "1i#+vet explicit-allocators" *.odin'
alias unvet-explicit-allocators='sed -i "/#+vet explicit-allocators/d" *.odin'

Note: Because I’m an absolute geek. I was playing with the above suggested idea, and found it to be very useful if using an editor that auto-reloads file changes and has an LSP installed like ols ( VSCodium with Odin Language by DanielGavin for example). I just run my alias, the file changes, I quick save with ctrl+s, and ols immediately flags non-explicit allocations. Do the opposite, and I’m back to where I was. Pretty neat :slight_smile:

1 Like

2 more aliases for adding/removing recursively all .odin files in current directory and sub directories. Backup files before testing, find and/or sed may work differently on other OSes like Mac or BSD. Careful to only run inside a project folder and not on root for example.

// add (remove then add to prevent accidental duplicates)
alias vetall-explicit-allocators='find . -type f -name "*.odin" -exec sed -i "/#+vet explicit-allocators/d" {} + -exec sed -i "1i#+vet explicit-allocators" {} +'
// remove
alias unvetall-explicit-allocators='find . -type f -name "*.odin" -exec sed -i "/#+vet explicit-allocators/d" {} +'

More geeky-ness. I used this as an excuse to get more practice in solving problems using Odin. I created an Odin program that can add/remove this flag to a single file or all files recursively in the directory specified. This should be OS agnostic, but I am only able to test on Linux. It uses the new “core:os”, which theoretically should produce the same results for most (all?) OSes. Let me know if it does not.

Backup files before testing.
Do not run on root or as root or on odin core files or vendor files

vet_explicit_allocators

cd folder_for_projects
git clone https://github.com/OnlyXuul/vet_explicit_allocators.git
cd vet_explicit_allocators
odin build .
How much of a geek am I?
  • Napoleon Dynamite
  • George McFly
  • Egon Spengler
  • Lewis Skolnick
  • Professor John I.Q. Nerdelbaum Frink Jr.
  • Fogell aka McLovin
0 voters