Introduction
Currently, I am working on a project, one of the main tools in which the language is haxe. As a development environment for haxe, in this project, I use FlashDevelop. During the day, the project is collected many times, and you need to know exactly which build, now, is shared. For this you need to number the assembly. Since neither the haxe nor the FlashDevelop standard tool for generating an assembly number was found, I propose to do a certain trick to solve this problem.
Trick
First, create a Build class containing the following code:
package ;
class Build {
public static var number:Int = 1;
}
Now, anywhere in our project, we can find out the build number by referring to the number field of the Build class.
For example:
new Label(this, 10, height-20, Config.version+"."+Build.number, Colors.white, 12);
The next step was to automate the increment build number. Create a .build file, in the root of the project, this file will contain a single line num = 1 (or the number with which to start the account).
')
num=1
And now, the prebuild.bat script, which will do the “dirty work” for me. Place the script next to the .build file. This script will create a Build class containing the current build number based on the number already contained in the .build file. And then increase it by one and overwrite .build.
@echo off
set filename=.build
set hxclass=.\src\build.hx
call :read_settings %filename% || exit /b 1
set /a RESULT=NUM + 1
echo Build : %RESULT%
echo num=%RESULT%>%filename%
rem
echo package ; class Build { public static var number:Int = %RESULT%; }>%hxclass%
echo
exit /b 0
rem
rem .
rem :
rem %1 -
:read_settings
set fname=%1
rem
if not exist %fname% (
echo FAIL:
exit /b 1
)
for /f "eol=# delims== tokens=1,2" %%i in (%fname%) do (
set %%i=%%j
)
exit /b 0
It remains to answer the question: "How to run prebuild.bat before the general build of the project?".
For FlashDevelop (for other IDEs by analogy), this is done like this: open the Project-> Properties menu, then the Build tab and the Pre-build command line field, in which we write the following $ (ProjectDir) \ prebuild.bat.
On this, the trick is done. Before each build, the Build class will be overwritten with the new value of the number field, which will provide the desired result.
PS Function code read_setting taken from the site rsdn.ru.
The article is published at the request of a friend without a residence permit in Habré.