mor

Cross platform dependency manager
git clone git@getsh.org:mor.git
Log | Files | Refs | README | LICENSE

commit 31e3f5eabbf5e5be1be83b7777c478b061701ce6
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date:   Sat, 13 Apr 2024 03:23:44 +0530

O brave new world

...that has such scripts in it!

Add mor.cmd and assign crlf to it

Add README with things that ought to be done

Add a sample requirements.ini

Diffstat:
A.gitattributes | 1+
AREADME | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amor.cmd | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arequirements.ini | 5+++++
4 files changed, 237 insertions(+), 0 deletions(-)

diff --git a/.gitattributes b/.gitattributes @@ -0,0 +1 @@ +mor.cmd text eol=crlf diff --git a/README b/README @@ -0,0 +1,122 @@ +mor +=== + .--. + / \ + ==( )-( ) + ( ._) + |(-=) | + +mor(pheus) is tool that simplifies dependency management the right way. +Some might even say it is a red-pill way of dependency management. + +mor searches for requirements.ini file in the current folder, and uses it's content to +download files. + +GOALS +----- +* Should work standalone +* Cross-platform +* Tiny - .cmd on windows, .sh on *NIX + +Section +------- +mor uses [sections] of the .ini file to setup targets and subdirectories + +Sections in mor are the names of the sub-directories + + [precompiled] + libfoo-2.7=https://example.com/awavauatush/libfoo.git + +The result of this is the following, + + $ mor precompiled + $ ls precompiled + libfoo-2.7 + +Targets +------- + +Not all targets are sub-directoies mind you! + +Sections that have a '@' or '#' as the starting letter are treated as target(@) and target query(#). + +Previously we have created [precompiled] section and invoked the mor command to download it. Real life +is seldom this simple. + +Usually we are in a situation where the pre-compiled binaries are different for different architectures +and platforms. + + ; packages.ini + [precompiled-macos] + libfoo-2.7=https://example.com/macos/precompiled.zip + + [precompiled-linux] + libfoo-2.7=https://example.com/linux/precompiled.zip + +In that case we can define a target query with '#', + + ; packages.ini + [#lib] + match=k-v + paths=precompiled-$platform download + + ; requirements.ini + [@lib] + libfoo=2.7 + +The $platform in the above can be passed to mor as, + + mor -Dplatform=linux @lib + +Variable +-------- + +mor treats any word that starts with '$' as variable and tries to expand it. + +Variables in mor has a specific rule and follows the following regex, + + ([a-z][A-z])*[0-9][a-z] + +Specials +-------- +$ - use to deference a variable + + +Example +------- + ; packages.ini + [$] + github=https://github.com + select=k-v + /=out/.sysroot + + [folder/] + libfoo-2.7=$github/foo/libfoo/releases/download/v26.1/foo-26.1-osx-universal_binary.zip + libfoo-git-2.7=$github/foo/libfoo.git + + ; requirements.ini + [$] + >[]=packages.ini + @[]=@lib @build + + [@lib] + libfoo=2.7 + + # when using apple-darwin, use @lib + [@lib:x86_64-apple-darwin] + libfoo-git=2.7 + +Bugs/Feature +------------ +- Deferencing a $variable second time is disabled. This is for simplicity/security. + +- Currently it is not possible to null a variable with -D in Windows. + + mor -Dvar= download + +The above will silently assign 'download' to $var. +This is a bug with how the cmd process arguments. Use -Dvar="" instead. + +Credits +------- +The graphics is a derivative of "butler" by jgs. diff --git a/mor.cmd b/mor.cmd @@ -0,0 +1,109 @@ +@echo off +setlocal EnableDelayedExpansion +set mor_version=0.1 + +rem default values +set /a is_logi=0 +set config_file=requirements.ini + +call :read_ini requirements.ini + +exit /b + +if "%~1" == "" goto print_usage +goto :main + +:unarchive <archive> <destination> +if "%~1x" == ".zip" do unzip "%~1" -d "%~2" +goto :eof + +:logi +if %is_logi% equ 1 echo %* +goto :eof + +:print_usage +echo Usage: mor [ -c requirements.ini] [-d] [-Dvar1=value1 ...] [[@]target1, ...] +goto :eof + +:read_ini <config_file.ini> +rem uses zero-space width character as a field separator +setlocal EnableDelayedExpansion +set /a section_count=0 +set current_section=[ + +rem locally remove env variables starting with '[' +for /f "usebackq delims== tokens=1" %%l in ( `set [` ) do ( + set %%l= + echo before: set %%l= +) 2>nul + +for /f "usebackq delims=: tokens=1,*" %%l in ( `findstr /n /v ^; "%1"` ) do ( + for /f "usebackq delims==] tokens=1,*" %%a in ( '%%m' ) do ( + echo actual: %%m + set key=%%a + if "!key:~0,1!" == "[" ( + set current_section=%%a + set %%a= + echo section set: !current_section! + ) else ( + set [precompiled || ( + echo [precompiled not found, maybe first? + ) + for /f "usebackq delims== tokens=1,*" %%t in (`set !current_section!`) do ( + set "!current_section!=%%u %%a %%b " + echo set "!current_section!=%%u %%a %%b " + ) + + ) + ) +) +for /f "useback delims== tokens=1,*" %%l in (`set [`) do ( + echo %%l: %%m +) +echo -------------- +for /f "tokens=1,2" %%t in ( "!%section%!" ) do ( + echo %%t + echo %%u +) +endlocal +goto :eof + +:main +setlocal +:parse +set arg=%~1 +if "%~1" == "" goto :eof +if "%~1" == "-v" ( + echo mor v%mor_version% + goto :eof +) else if "%arg%" == "-c" ( + set config_file="%~2" + call :logi -c !config_file! + shift +) else if "%arg%" == "-d" ( + set /a is_logi=1 +) else if "%arg%" == "-D" ( + set d=%~2 + call :logi -D !d!=%~3 + shift + shift +) else if "%arg:~0,2%" == "-D" ( + set arg=%~1 + set d=%arg:~2% + call :logi -D!d!=%~2 + shift +) else if "%arg%" == "-" ( + echo mor: invalid argument '-' +) else ( + set targets=%~1 + echo %targets% +) +if "%arg:~0,1%" == "=" echo "= command" + +shift +goto parse +endlocal +goto :eof + + +endlocal diff --git a/requirements.ini b/requirements.ini @@ -0,0 +1,5 @@ +; 1st comment +[precompiled] +test1-0.1=https://getsh.org/bharatvaj/pubkey.asc +test2-0.1=https://getsh.org/popeye/pubkey.asc +;comment