Files
herolib/install_herolib.vsh
Mahmoud-Emad a65cbd606b feat: improve build and serialization logic
- Update v fmt exit code handling
- Support dynamic organization for symlinks
- Add f32 and list f64 serialization/deserialization
- Improve JSON decoding for bid requirements/pricing
- Add basic tests for Bid and Node creation
2025-10-12 13:27:10 +03:00

116 lines
3.2 KiB
GLSL
Executable File

#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import os
fn addtoscript(tofind string, toadd string) ! {
home_dir := os.home_dir()
mut rc_file := '${home_dir}/.zprofile'
if !os.exists(rc_file) {
rc_file = '${home_dir}/.bashrc'
if !os.exists(rc_file) {
return error('No .zprofile or .bashrc found in home directory')
}
}
// Read current content
mut content := os.read_file(rc_file)!
// Remove existing alias if present
lines := content.split('\n')
mut new_lines := []string{}
mut prev_is_emtpy := false
for line in lines {
if prev_is_emtpy {
if line.trim_space() == '' {
continue
} else {
prev_is_emtpy = false
}
}
if line.trim_space() == '' {
prev_is_emtpy = true
}
if !line.contains(tofind) {
new_lines << line
}
}
new_lines << toadd
new_lines << ''
// Write back to file
new_content := new_lines.join('\n')
os.write_file(rc_file, new_content)!
}
abs_dir_of_script := dir(@FILE)
println('Script directory: ${abs_dir_of_script}')
// Determine the organization name from the current path
// This makes the script work with any organization (incubaid, etc.)
path_parts := abs_dir_of_script.split('/')
mut org_name := 'incubaid' // default fallback
for i, part in path_parts {
if part == 'github' && i + 1 < path_parts.len {
org_name = path_parts[i + 1]
break
}
}
println('Detected organization: ${org_name}')
println('Will create symlink: ${os.home_dir()}/.vmodules/${org_name}/herolib -> ${abs_dir_of_script}/lib')
// Reset symlinks (cleanup)
println('Resetting all symlinks...')
os.rm('${os.home_dir()}/.vmodules/incubaid/herolib') or {}
os.rm('${os.home_dir()}/.vmodules/${org_name}/herolib') or {}
// Create necessary directories
os.mkdir_all('${os.home_dir()}/.vmodules/${org_name}') or {
panic('Failed to create directory ~/.vmodules/${org_name}: ${err}')
}
// Create new symlinks
symlink_target := '${abs_dir_of_script}/lib'
symlink_path := '${os.home_dir()}/.vmodules/${org_name}/herolib'
os.symlink(symlink_target, symlink_path) or { panic('Failed to create herolib symlink: ${err}') }
// Verify the symlink was created
// Note: os.exists() may return false for broken symlinks, so we check if it's a link first
if os.is_link(symlink_path) {
println(' Symlink created successfully: ${symlink_path}')
println(' Points to: ${symlink_target}')
// Verify the target exists
if os.exists(symlink_target) {
println(' Target directory exists and is accessible')
} else {
eprintln(' Warning: Symlink target does not exist: ${symlink_target}')
}
} else {
panic('Failed to create herolib symlink at ${symlink_path}')
}
println('Herolib installation completed successfully!')
// Add vtest alias
addtoscript('alias vtest=', "alias vtest='v -stats -enable-globals -show-c-output -n -w -cg -gc none -cc tcc test' ") or {
eprintln('Failed to add vtest alias: ${err}')
exit(1)
}
// Add vrun alias
addtoscript('alias vrun=', "alias vrun='v -stats -enable-globals -show-c-output -n -w -cg -gc none -cc tcc run' ") or {
eprintln('Failed to add vrun alias: ${err}')
exit(1)
}
addtoscript('HOME/hero/bin', 'export PATH="\$PATH:\$HOME/hero/bin"') or {
eprintln('Failed to add path to hero, ${err}')
exit(1)
}
// ulimit -n 32000
println('Added vtest alias to shell configuration')