Wish Using script output as value for #Region attributes

Sandman

Expert
Licensed User
Longtime User
I use Mercurial for my projects, and I just realized that it would be mighty nice to get the id of the current commit to VersionName. It could be generalized to allow for execution of a binary and using the first line of the response as the actual value for any Region attribute.

So, to give an example of what I mean, something like this. (I do realize the syntax I use here is a bit weird, it's just to visualize.)

B4X:
#VersionName: ${c:\myscripts\hg.bat}

And in this case the hg.bat would contain something like this:
B4X:
@echo off
cd /path/to/my/project
hg commit --quiet --message "Automatic commit from B4A compilation"
hg id -i

The last line produces something like 82870ef2ddda, which is the hg tag for that commit, which would then automatically be used as VersionName. When I start getting feedback about bugs, I can check their VersionName to find the exactly correct source and then investigate.
 

DonManfred

Expert
Licensed User
Longtime User

Sandman

Expert
Licensed User
Longtime User
That might actually work nicely, thanks.

However, I feel kind of hesitant to edit my b4a files from an external process. But I suppose that the conditional build command could generate a commit.txt in the Files folder, which could be read by the app and displayed in the About window.

That should work, right?
 

DonManfred

Expert
Licensed User
Longtime User
However, I feel kind of hesitant to edit my b4a files from an external process
See the tutorial. It does not change your project. It only creates a file which will be read by the app at runtime....
Changing the b4a file was my idea (i would do it that way).
 

Sandman

Expert
Licensed User
Longtime User
Yeah, I went that route too. Here's the bat file I ended up with. Apologies to all that are fluent in bat files, I'm coding them using my elbows and hoping for the best. :)

B4X:
@echo off
SET PROJECTDIR="C:\path\to\my\project"
cd %PROJECTDIR%
hg addremove --quiet
hg commit --quiet --message "Automatic commit from B4A compilation"
FOR /F "usebackq" %%i IN (`hg id -i`) DO SET HGID=%%i
fnr.exe --cl --dir %PROJECTDIR% --fileMask "main.b4a" --excludeFileMask "*.dll, *.exe" --useRegEx --find "(^.*VersionName):(.*)$" --replace "$1: %HGID%"

This script has one dependency: fnr.exe, a Find and Replace tool that can be found at http://findandreplace.codeplex.com/.

I verified using Meld that the script only changed the one file, and nothing else in the project.
 

Sandman

Expert
Licensed User
Longtime User
Agreed, which is why your quoted text says "main.b4a". :)

You are obviously free to adjust the script to suit your situation - or renaming your project to "main", if that seems better. :)
 

Sandman

Expert
Licensed User
Longtime User
Well, this didn't work. The IDE doesn't reload the main module when the script updates it, and as such it's not used when compiling. I've posted a wish about this here.
 

JordiCP

Expert
Licensed User
Longtime User
Here
step id can be one of the following:
1 - Before the compiler cleans the objects folder (it happens after the code is parsed).
2 - Before R.java file is generated.
3 - Before the package is signed (the APK file at this point is: bin\temp.ap_).
4 - Before the APK is installed.
5 - After the APK is installed.
6 (new in v5.01) - After Java compilation.

I think it can't be used to edit the B4a file, since the earliest step that this command allows is 1, and it only happens after parsing the source (and the IDE does not update it).

Instead, doing it in step '2' and editing the 'android:versionName' entry in the already generated AndroidManifest.xml in Objects folder works ok.
 
Top