Created
October 29, 2023 10:44
-
-
Save mzaks/5b6c7ae115265e88164d86f86b81d096 to your computer and use it in GitHub Desktop.
Poor persons module management for Mojo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function check_out_remote_module() ( | |
rurl="$1" | |
shift | |
declare -a paths | |
declare -a module_names | |
for var in "$@" | |
do | |
IFS="=" | |
read -ra module_name_components <<< "$var" | |
components_count=${#module_name_components[@]} | |
path=${module_name_components[0]} | |
module_name=${module_name_components[$components_count-1]} | |
paths=("${paths[@]}" "$path") | |
module_names=("${module_names[@]}" "$module_name") | |
done | |
IFS=" " | |
for module_name in "${module_names[@]}" | |
do | |
rm -rf ../$module_name | |
done | |
current_date_time=$(date) | |
echo "URL: $rurl" | |
git clone -n --depth=1 --filter=tree:0 $rurl | |
cd ${rurl##*/} | |
git sparse-checkout set --no-cone "${paths[@]}" | |
git checkout | |
for i in "${!paths[@]}" | |
do | |
module_name=${module_names[$i]} | |
path=${paths[$i]} | |
cp -R ./$path ../../$module_name | |
echo $current_date_time > ../../$module_name/.checkoutinfo | |
echo "URL: $rurl" >> ../../$module_name/.checkoutinfo | |
echo "Path: $path" >> ../../$module_name/.checkoutinfo | |
done | |
cd ../ | |
) | |
function checkout()( | |
# Add check out remote module calls here | |
# Examples, replace with your own!!! | |
check_out_remote_module "https://github.com/mzaks/mojo-csv" "csv" | |
check_out_remote_module "https://github.com/mzaks/mojo-trees" "fiby_tree" "left_child_right_sibling=lcrs_tree" | |
check_out_remote_module "https://github.com/tairov/llama2.mojo" "read/libc/stdio=file_io" | |
check_out_remote_module "-b v0.2.0 https://github.com/gabrieldemarmiesse/mojo-stdlib-extensions" "stdlib_extensions/builtins=list" | |
) | |
mkdir -p "_deps" | |
cd "_deps" | |
checkout | |
rm -rf "../_deps" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to execute
chmod 755 checkout_remote_modules.sh