mor

Cross platform dependency manager

commit edfb6a18162e0dedff883987a6cf6eb74a84448d
parent dbe051c6a936acc3954ad17ff0bbe54cd4718c54
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 12 Oct 2024 22:48:37 +0530

Add multi-level variable expansion

Update README by removing bugs and fixing format

Update requirements.ini with variable tests

Bump version to 0.7
3 files changed, 60 insertions(+), 31 deletions(-)
M
README
|
34
+++++++++++++++++++---------------
M
mor.cmd
|
40
++++++++++++++++++++++++++++------------
M
requirements.ini
|
17
+++++++++++++----
diff --git a/README b/README
@@ -101,7 +101,7 @@ Variables in mor has a specific rule and follows the following regex,
 	; the output folder
 	/=outfolder
 	; arbitrary variables
-	github=https://github.com
+	git=https://git.example.com
 
 Status Messages
 ---------------

@@ -129,28 +129,29 @@ Example
 
 	; packages.ini
 	[$]
-	github=https://github.com
+	git=https://git.example.com
 	match=k-v
 	/=out/.sysroot
 
 	[folder/]
-	libfoo-2.7=$github/foo/libfoo/releases/download/v26.1/foo-26.1-osx-universal_binary.zip
+	libfoo-2.7=$git/releases/libfoo/releases/v26.1/foo-26.1-osx-universal.zip
 	libfoo-git-2.7=$github/foo/libfoo.git
 
 Windows
 -------
-- curl is the preferred downloader for windows, but if it is missing, mor defaults to bitsadmin.exe which is available in older versions of Windows.
+- curl is the preferred downloader for windows, but if it is missing, mor
+defaults to bitsadmin.exe which is available in older versions of Windows.
 
-If you face extreme slowness in downloads when using bitsadmin, it's probably because some other application is using it to download something (like Windows Update).If you are on a hurry, you can do
+If you face extreme slowness in downloads when using bitsadmin, it's probably
+because some other application is using it to download
+something (like Windows Update).If you are on a hurry, you can do
 
 	C:\Users\Admin> bitsadmin /reset
 
 to clear all downloads and try running mor again.
 
-Bugs/Feature/Todo
------------------
-- Deferencing a $variable second time is disabled. This is for simplicity/security.
-
+Bugs
+----
 - Currently it is not possible to null a variable with -D in Windows.
 
 	mor -Dvar= download

@@ -158,15 +159,18 @@ Bugs/Feature/Todo
 The above will silently assign 'download' to $var.
 This is a bug with how the cmd process arguments. Use -Dvar="" instead.
 
-- TODO Implement variables expansion
-- TODO Add test cases
-- TODO Merge if two section with same names are present
+- It is currently not possible to use a '$something' directly in a URL if a
+variable named 'something' is defined in '$' section
+
+- The varable expansion is not really ([a-z][A-z])*[0-9][a-z].
 
 FAQ
 ---
-> Why the weird symbols ($/, $<, $>) instead of simple clean $root, $include, etc in [$]?
-I wanted mor to be as language agnostic as possible and I wanted the core variables to be
-ASCII clean. This is also the reason why the status messages are mostly made up of symbols.
+> Why the weird symbols ($/, $<, $>) instead of simple clean $root, $include,
+etc in [$]?
+I wanted mor to be as language agnostic as possible and I wanted the core
+variables to be ASCII clean. This is also the reason why the status messages
+are mostly made up of symbols.
 
 > Where are the damn CHANGELOGs?
 For the complete changelog,
diff --git a/mor.cmd b/mor.cmd
@@ -1,6 +1,6 @@
 @echo off
 setlocal
-set mor_version=0.6
+set mor_version=0.7
 set root_dir=%cd%\out
 for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
 

@@ -32,13 +32,30 @@ setlocal EnableDelayedExpansion
 
 	for /f "eol=; usebackq delims==] tokens=1,*" %%a in (%~1) do (
 		set tok=%%~a
+		set val=%%~b
 		if "!tok:~0,1!" == "[" (
 			set current_section=!tok!
 			call :logi #!current_section!
 		) else (
-			set key=!current_section![!tok!]
-			set !key!=%%~b
-			call :logi # 	[!tok!] "%%~b"
+			set MOR_V_ 2>NUL >NUL
+			if not ERRORLEVEL 1 (
+				for /f "usebackq delims== tokens=1*" %%s in (`set MOR_V_`) do (
+					set varname=%%s
+					set varname=!varname:MOR_V_=!
+					call set val=%%val:$!varname!=%%t%%
+				)
+			)
+			if "!current_section:~1,1!" == "$" (
+				if "!tok!"=="/" (
+					set root_dir=!val!
+				) else (
+					set MOR_V_!tok!=!val!
+				)
+			) else (
+				set key=!current_section![!tok!]
+				set !key!=!val!
+				call :logi # 	[!tok!] "!val!"
+			)
 		)
 	)
 

@@ -107,11 +124,11 @@ goto :eof
 
 :prime_download <section> <target> <url>
 setlocal EnableDelayedExpansion
-	set current_target_dir="%root_dir%\%1"
+	set current_target_dir="!root_dir!\%1"
 	shift
 	call :logi Current Target Dir: !current_target_dir!
 	if not exist "!current_target_dir!" mkdir "!current_target_dir!"
-	:key_value
+	:MOR_KEY_VAULE
 	if "%~1" == "" goto :eof
 	rem TODO Check if this for loop is really necessary
 	for %%i in (%2) do set ext=%%~xi

@@ -136,7 +153,7 @@ setlocal EnableDelayedExpansion
 	:MOR_AFTER_EXTRACT
 	shift
 	shift
-	goto :key_value
+	goto :MOR_KEY_VAULE
 endlocal
 goto :eof
 

@@ -166,10 +183,10 @@ setlocal
 		bitsadmin /setpriority "%%i" HIGH >>mor.log
 		bitsadmin /setnoprogresstimeout "%%i" 30 >>mor.log
 		bitsadmin /resume "%%i"  >>mor.log
-	:mor_download_start
+	:MOR_DOWNLOAD_START
 		if "%job_id%" == "" (
 			timeout /t 2 >nul
-			goto :mor_download_start
+			goto :MOR_DOWNLOAD_START
 		)
 		for /f %%f in ('bitsadmin /rawreturn /getstate %job_id%') do (
 			set dstate=%%f

@@ -199,10 +216,9 @@ setlocal
 		:BITS_Wait2
 		:BITS_ERWait
 			timeout /t 1 >nul
-			goto:mor_download_start
+			goto:MOR_DOWNLOAD_START
 		:BITS_TRANSFERRED
-			goto :mor_download_end
-	:mor_download_end
+
 		bitsadmin /rawreturn /complete "%job_id%" >>mor.log
 	)
 endlocal
diff --git a/requirements.ini b/requirements.ini
@@ -1,6 +1,8 @@
 ; 1st comment
 [$]
-mor=https://github.com
+a=https://geths.org
+mor=$a
+/=build
 
 [#lib]
 /=testing secondtest

@@ -11,20 +13,23 @@ mor=https://github.com
 [#badlib]
 /=precompiled testing
 
+[#baddynamic]
+/=dynamic
+
 [@lib]
 test1=0.1
 test2=0.3
 
-
 [@wickedlib]
-test1=0.1
-test2=0.3
 test3=0.3
 
 [@badlib]
 test1=0.1
 test2=0.3
 
+[@baddynamic]
+test1=0.9
+
 [badlink]
 something-3.3=https://getsh.org/wrong
 

@@ -33,6 +38,10 @@ something-3.3=https://getsh.org/wrong
 test1-0.1=https://getsh.org/index.html
 test2-0.3=https://getsh.org/bharatvaj/pubkey.asc
 
+[dynamic]
+test1-0.9=$nothing/index.html
+test4-0.1=$mor/index.html
+
 [secondtest]
 test1-0.2=https://getsh.org/index.html
 test1-45=https://google.com/