Skip to content

Commit

Permalink
Batch config
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangminh1789 committed Sep 22, 2023
1 parent 759c3e3 commit f4bceb4
Show file tree
Hide file tree
Showing 20 changed files with 468 additions and 42 deletions.
8 changes: 8 additions & 0 deletions AutoBuild/Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions AutoBuild/Assets/Editor/Builder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;

public static class Builder
{
[MenuItem("Tools/Build")]
public static void Execute()
{
BuilderUtility.GetArg("-buildTarget");

var options = new BuildPlayerOptions();
options.scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray();
options.target = GetBuildTarget();
options.locationPathName = GetOutputPath();
BuildPipeline.BuildPlayer(options);
}

static BuildTarget GetBuildTarget()
{
string target = BuilderUtility.GetArg("-buildTarget");

switch (target)
{
case "Android": return BuildTarget.Android;
case "iOS": return BuildTarget.iOS;
case "OSX": return BuildTarget.StandaloneOSX;
case "Win64": return BuildTarget.StandaloneWindows64;
case "Win32":
default: return BuildTarget.StandaloneWindows;
}
}

static string GetOutputPath()
{
return BuilderUtility.GetArg("-outputPath");
}
}
11 changes: 11 additions & 0 deletions AutoBuild/Assets/Editor/Builder.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions AutoBuild/Assets/Editor/BuilderUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BuilderUtility
{
public static string GetArg(string key)
{
var args = Environment.GetCommandLineArgs();
int idx = Array.LastIndexOf(args, key);

if (idx >= 0 && idx < args.Length - 1)
{
return args[idx + 1];
}

return "";
}
}
11 changes: 11 additions & 0 deletions AutoBuild/Assets/Editor/BuilderUtility.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion AutoBuild/Assets/Scenes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 39 additions & 24 deletions AutoBuild/BuildTool/build.bat
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
echo off
rem echo off
cls
set project_path=%cd%
echo Project path: '%project_path%'
ECHO [[== Load build.bat
SETLOCAL enableDelayedExpansion

cd AutoBuild/BuildTool
echo "Starting build"
echo Current path: '%cd%'
CALL %~dp0config.bat

call config.bat

echo Unity path: '%UNITY_PATH%'
SET LOG_PATH=%WORKSPACE%/log.txt
SET OUTPUT_PATH=%WORKSPACE%/AutoBuild/Test.exe

ECHO PROJECT_PATH: '%PROJECT_PATH%'
ECHO Unity path: '%UNITY_PATH%'

:loop
if [%1]==[] goto end_loop
Expand All @@ -18,8 +19,8 @@ if [%1]==[-v] goto case_version
shift & goto loop

:case_profile
set profile_name=%2
set profile_path=profiles/%profile_name%.bat
set profileName=%2
set profilePath=%BUILD_TOOL%profiles/%profileName%.bat
shift & goto loop

:case_version
Expand All @@ -28,22 +29,36 @@ shift & goto loop

:end_loop

echo Profile: %profile_name%
echo Version: %version%
echo Profile: '%profileName%'
echo Version: '%version%'
ECHO Profile path: '%profilePath%'

echo Load profile '%profile_path%'
if exist %profile_path% (
call %profile_path%
echo Load profile '%profile_path%' is succeed
if exist %profilePath% (
CALL %profilePath% :global_config config
ECHO Config: '!config!'
) else (
echo Load profile '%profile_path%' is failed
exit 0
ECHO Load profile '%profilePath%' is failed
EXIT 0
)

%UNITY_PATH% \
-quit \
-batchmode \
-projectPath %project_path%
-buildTarget Win
ECHO - Starting building process

"%UNITY_PATH%" ^
-quit ^
-batchmode ^
-projectPath "%PROJECT_PATH%" ^
-executeMethod Builder.Execute ^
-buildTarget Win32 ^
-logFile "%LOG_PATH%" ^
-outputPath "%OUTPUT_PATH%" ^
-versionCode %version% ^
%config%

ECHO - Finish build

CALL %BUILD_TOOL%utility.bat :validate_file
CALL %BUILD_TOOL%utility.bat :zip_file

ENDLOCAL

echo "Finish build"
ECHO End of build.bat ==]]
13 changes: 13 additions & 0 deletions AutoBuild/BuildTool/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export project_path=$(dirname $0)
export WKSPACES="/Users/minh.nguyen/wkspaces"
export UNITY_PATH="/Applications/Unity/Hub/Editor/2022.3.7f1/Unity.app"

echo $UNITY_PATH

$UNITY_PATH \
-quit \
-batchmode \
-projectPath $project_path \
-executeMethod Builder.Execute \
-buildTarget Win \
-logFile %WKSPACES\log.txt
15 changes: 14 additions & 1 deletion AutoBuild/BuildTool/config.bat
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
set UNITY_PATH="C:\Program Files\Unity\Hub\Editor\2022.3.7f1\Editor\Unity.exe"
ECHO.
ECHO [[== Execute config.bat
SET BUILD_TOOL=%~dp0
SET PROJECT_PATH=%~dp0..\
SET UNITY_PATH=C:\Program Files\Unity\Hub\Editor\2022.3.7f1\Editor\Unity.exe
SET WORKSPACE=C:\wkspaces

ECHO Variables in config.bat
ECHO BUILD_TOOL: '%BUILD_TOOL%'
ECHO PROJECT_PATH: '%PROJECT_PATH%'
ECHO UNITY_PATH: '%UNITY_PATH%'
ECHO WORKSPACE: '%WORKSPACE%'

ECHO End of config.bat ==]]
21 changes: 21 additions & 0 deletions AutoBuild/BuildTool/profiles/dev.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ECHO.
ECHO [[== Load dev.bat
CALL :%*
EXIT /b %errorlevel%

:global_config
ECHO - Executing :global_config
CALL :define_symbols ds
CALL :namespace ns
SET "%~1=%ds% %ns%"
GOTO :EOF

:define_symbols
ECHO - Executing :define_symbols
SET "%~1=-scriptingDefineSymbols BUILD_DEV,ENABLE_LOG"
GOTO :EOF

:namespace
ECHO - Executing :namespace
SET "%~1=-namespace com.minhnh.autobuild"
GOTO :EOF
18 changes: 18 additions & 0 deletions AutoBuild/BuildTool/utility.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ECHO.
ECHO [[== Execute utility.bat
CALL :%*
EXIT /b %errorlevel%

:zip_file
ECHO Running zip file
GOTO EOF

:validate_file
ECHO Running verify file
GOTO EOF

:EOF
ECHO End of utility.bat ==]]
ECHO.

EXIT /b 0
17 changes: 17 additions & 0 deletions AutoBuild/ProjectSettings/BurstAotSettings_StandaloneOSX.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"DebugDataKind": 1,
"EnableArmv9SecurityFeatures": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"CpuTargetsX64": 72,
"OptimizeFor": 0
}
}
4 changes: 2 additions & 2 deletions AutoBuild/ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ EditorBuildSettings:
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
guid: 2cda990e2423bbf4892e6590ba056729
path: Assets/Scenes/Home.unity
guid: a8568093651e04830994ac4b028d17dc
m_configObjects: {}
Loading

0 comments on commit f4bceb4

Please sign in to comment.