| 1 |
{ |
| 2 |
Copyright 2014-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Build and package tool for Castle Game Engine programs. |
| 17 |
Call with --help for detailed usage instructions. |
| 18 |
} |
| 19 |
|
| 20 |
{$I castleconf.inc} |
| 21 |
|
| 22 |
{ This adds icons and version info for Windows, |
| 23 |
automatically created by "castle-engine compile". } |
| 24 |
{$ifdef CASTLE_AUTO_GENERATED_RESOURCES} {$R castle-auto-generated-resources.res} {$endif} |
| 25 |
|
| 26 |
uses SysUtils, |
| 27 |
ToolDisableDynamicLibraries, //< use this unit early, before any other CGE unit |
| 28 |
CastleUtils, CastleParameters, CastleFindFiles, CastleLog, |
| 29 |
CastleFilesUtils, CastleUriUtils, CastleStringUtils, |
| 30 |
CastleApplicationProperties, |
| 31 |
ToolPackageFormat, ToolProject, ToolCompile, ToolIOS, ToolAndroid, ToolManifest, |
| 32 |
ToolNintendoSwitch, ToolCommonUtils, ToolArchitectures, ToolUtils, ToolProcess, |
| 33 |
ToolCache, ToolCompilerInfo; |
| 34 |
|
| 35 |
var |
| 36 |
Target: TTarget; |
| 37 |
OS: TOS; |
| 38 |
CPU: TCPU; |
| 39 |
Mode: TCompilationMode = cmRelease; |
| 40 |
AssumeCompiled: boolean = false; |
| 41 |
Fast: boolean = false; |
| 42 |
CompilerExtraOptions: TCastleStringList; |
| 43 |
PackageFormat: TPackageFormat = pfDefault; |
| 44 |
PackageNameIncludeVersion: Boolean = true; |
| 45 |
UpdateOnlyCode: Boolean = false; |
| 46 |
CleanAll: Boolean = false; |
| 47 |
WaitForProcessId: TProcessId = 0; |
| 48 |
GuiErrors: Boolean = false; |
| 49 |
OverrideCompiler: TCompiler = DefaultCompiler; |
| 50 |
GuidFromName: Boolean = false; |
| 51 |
ProjectTemplate: String = 'empty'; |
| 52 |
ProjectParentDir: String = ''; |
| 53 |
ProjectCaption: String = ''; |
| 54 |
ProjectMainView: String = 'Main'; |
| 55 |
|
| 56 |
const |
| 57 |
Options: array [0..28] of TOption = |
| 58 |
( |
| 59 |
(Short: 'h'; Long: 'help'; Argument: oaNone), |
| 60 |
(Short: 'v'; Long: 'version'; Argument: oaNone), |
| 61 |
(Short: #0 ; Long: 'target'; Argument: oaRequired), |
| 62 |
(Short: #0 ; Long: 'os'; Argument: oaRequired), |
| 63 |
(Short: #0 ; Long: 'cpu'; Argument: oaRequired), |
| 64 |
(Short: 'V'; Long: 'verbose'; Argument: oaNone), |
| 65 |
(Short: #0 ; Long: 'mode'; Argument: oaRequired), |
| 66 |
(Short: #0 ; Long: 'assume-compiled'; Argument: oaNone), |
| 67 |
(Short: #0 ; Long: 'fast'; Argument: oaNone), |
| 68 |
(Short: #0 ; Long: 'plugin'; Argument: oaNone), |
| 69 |
(Short: #0 ; Long: 'fpc-version-iphone-simulator'; Argument: oaRequired), |
| 70 |
(Short: #0 ; Long: 'compiler-option'; Argument: oaRequired), |
| 71 |
(Short: #0 ; Long: 'output'; Argument: oaRequired), |
| 72 |
(Short: #0 ; Long: 'project'; Argument: oaRequired), |
| 73 |
(Short: #0 ; Long: 'package-format'; Argument: oaRequired), |
| 74 |
(Short: #0 ; Long: 'package-name-no-version'; Argument: oaNone), |
| 75 |
(Short: #0 ; Long: 'update-only-code'; Argument: oaNone), |
| 76 |
(Short: #0 ; Long: 'ios-simulator'; Argument: oaNone), |
| 77 |
(Short: #0 ; Long: 'all'; Argument: oaNone), |
| 78 |
(Short: #0 ; Long: 'manifest-name'; Argument: oaRequired), |
| 79 |
(Short: #0 ; Long: 'wait-for-process-exit'; Argument: oaRequired), |
| 80 |
(Short: #0 ; Long: 'gui-errors'; Argument: oaNone), |
| 81 |
(Short: #0 ; Long: 'compiler'; Argument: oaRequired), |
| 82 |
(Short: #0 ; Long: 'guid-from-name'; Argument: oaNone), |
| 83 |
(Short: #0 ; Long: 'windows-robust-pipes'; Argument: oaNone), |
| 84 |
(Short: #0 ; Long: 'project-template'; Argument: oaRequired), |
| 85 |
(Short: #0 ; Long: 'project-parent-dir'; Argument: oaRequired), |
| 86 |
(Short: #0 ; Long: 'project-caption'; Argument: oaRequired), |
| 87 |
(Short: #0 ; Long: 'project-main-view'; Argument: oaRequired) |
| 88 |
); |
| 89 |
|
| 90 |
procedure OptionProc(OptionNum: Integer; HasArgument: boolean; |
| 91 |
const Argument: string; const SeparateArgs: TSeparateArgs; Data: Pointer); |
| 92 |
|
| 93 |
{ Call SetCurrentDir to open project within specified directory. } |
| 94 |
procedure ChangeProjectDir(const DirOrManifestFile: String); |
| 95 |
var |
| 96 |
Dir: String; |
| 97 |
begin |
| 98 |
if ExtractFileName(DirOrManifestFile) = ManifestName then |
| 99 |
Dir := ExtractFilePath(DirOrManifestFile) |
| 100 |
else |
| 101 |
Dir := DirOrManifestFile; |
| 102 |
if not SetCurrentDir(Dir) then |
| 103 |
raise EInvalidParams.CreateFmt('Cannot enter project directory "%s"', [Dir]); |
| 104 |
end; |
| 105 |
|
| 106 |
begin |
| 107 |
case OptionNum of |
| 108 |
0 : begin |
| 109 |
Writeln( |
| 110 |
'castle-engine: Build and package Castle Game Engine programs.' +NL+ |
| 111 |
NL+ |
| 112 |
'Call with the current directory set to your project, like this:' +NL+ |
| 113 |
' castle-engine [OPTIONS]... COMMAND' +NL+ |
| 114 |
NL+ |
| 115 |
'Possible commands:' +NL+ |
| 116 |
NL+ |
| 117 |
'create PROJECT-NAME' +NL+ |
| 118 |
' Create a new project, based on one of the existing templates.' + NL + |
| 119 |
' Subdirectory PROJECT-NAME will be created in directory provided' + NL + |
| 120 |
' as --project-parent-dir), by default in the current directory.' +NL+ |
| 121 |
NL+ |
| 122 |
'compile' +NL+ |
| 123 |
' Compile project.' +NL+ |
| 124 |
' By default compiles for the current OS / current CPU (' + OSToString(DefaultOS) + ' / ' + CPUToString(DefaultCPU) + ').' +NL+ |
| 125 |
' You can use --os / --cpu options to compile to some other OS / CPU.' +NL+ |
| 126 |
' You can use --target to compile for a collection of OS / CPU' +NL+ |
| 127 |
' combination (like "iOS" or "Android").' +NL+ |
| 128 |
NL+ |
| 129 |
'package' +NL+ |
| 130 |
' Package the application into the best archive format for given' +NL+ |
| 131 |
' operating system (OS) / processor (CPU) / target.' +NL+ |
| 132 |
' The OS, CPU and "target" can be changed just like at "compile".' +NL+ |
| 133 |
NL+ |
| 134 |
'install' +NL+ |
| 135 |
' Install the application created by previous "package" call.' +NL+ |
| 136 |
' Useful when OS is "android", it installs' +NL+ |
| 137 |
' the apk package created by previous "package" call' +NL+ |
| 138 |
' for Android. Useful for quick testing of your app on a device' +NL+ |
| 139 |
' connected through USB.' +NL+ |
| 140 |
NL+ |
| 141 |
'run' +NL+ |
| 142 |
' Run the application. ' +NL+ |
| 143 |
' On some platforms, it requires installing the application first' +NL+ |
| 144 |
' (e.g. on Android, where we install and run on a device' +NL+ |
| 145 |
' connected through USB). So run the "install" command before.' +NL+ |
| 146 |
' On other platforms (e.g. standalone Windows, Linux, macOS...),' +NL+ |
| 147 |
' it simply runs the last compiled application.' +NL+ |
| 148 |
' So just "compile" the application first.' +NL+ |
| 149 |
NL+ |
| 150 |
'package-source' +NL+ |
| 151 |
' Package the source code of the application.' +NL+ |
| 152 |
NL + |
| 153 |
'clean' +NL+ |
| 154 |
' Clean leftover files from compilation and packaging.' +NL+ |
| 155 |
' Does not remove final packaging output.' +NL+ |
| 156 |
NL+ |
| 157 |
'simple-compile' +NL+ |
| 158 |
' Compile the Object Pascal file (unit/program/library) given' +NL+ |
| 159 |
' as a parameter. This does not handle the Castle Game Engine projects' +NL+ |
| 160 |
' defined by CastleEngineManifest.xml files.' +NL+ |
| 161 |
' It merely calls "fpc" with proper command-line options for' +NL+ |
| 162 |
' units/programs/libraries using our engine.' +NL+ |
| 163 |
' Use this instead of "compile" only if there''s some good reason' +NL+ |
| 164 |
' you don''t want to use CastleEngineManifest.xml to your project.' +NL+ |
| 165 |
NL+ |
| 166 |
'auto-generate-textures' +NL+ |
| 167 |
' Create GPU-compressed versions of textures,' +NL+ |
| 168 |
' for the textures mentioned in <auto_compressed_textures>' +NL+ |
| 169 |
' inside the file data/material_properties.xml.' +NL+ |
| 170 |
NL+ |
| 171 |
'auto-generate-clean' +NL+ |
| 172 |
' Clear "auto_compressed" subdirectories, that should contain only' +NL+ |
| 173 |
' the output created by "auto-generate-textures" target.' +NL+ |
| 174 |
NL+ |
| 175 |
'generate-program' +NL+ |
| 176 |
' Generate files to edit and run this project in Lazarus: lpr, lpi, castleautogenerated unit.' +NL+ |
| 177 |
' Depends on game_units being defined in the CastleEngineManifest.xml.' +NL+ |
| 178 |
NL+ |
| 179 |
'editor' +NL+ |
| 180 |
' Run Castle Game Engine Editor within this project, with possible' +NL+ |
| 181 |
' project-specific components.' +NL+ |
| 182 |
NL+ |
| 183 |
'editor-rebuild-if-needed' +NL+ |
| 184 |
' Internal. 1st part of "editor" command.' + NL + |
| 185 |
NL+ |
| 186 |
'editor-run [--wait-for-process-exit PROCESS-ID]' +NL+ |
| 187 |
' Internal. 2nd part of "editor" command.' + NL + |
| 188 |
NL+ |
| 189 |
'output' +NL+ |
| 190 |
' Output some project information (from the manifest).' + NL + |
| 191 |
' Next parameter determines the information:' + NL + |
| 192 |
' executable-name' + NL + |
| 193 |
' name' + NL + |
| 194 |
' pascal-name' + NL + |
| 195 |
' search-paths' + NL + |
| 196 |
' version' + NL + |
| 197 |
' version-code' + NL + |
| 198 |
NL+ |
| 199 |
'output-environment' +NL+ |
| 200 |
' Output some environment information (independent of any project).' + NL + |
| 201 |
' Next parameter determines the information:' + NL + |
| 202 |
' fpc-exe' + NL + |
| 203 |
' fpc-standard-units-path' + NL + |
| 204 |
NL+ |
| 205 |
'cache' +NL+ |
| 206 |
' Create cache to speed up future compilations.' + NL + |
| 207 |
NL+ |
| 208 |
'cache-clean' +NL+ |
| 209 |
' Remove the cache directory.' + NL + |
| 210 |
NL+ |
| 211 |
'create-manifest' +NL+ |
| 212 |
' (Deprecated) Creates simple CastleEngineManifest.xml with guessed values.' +NL+ |
| 213 |
NL+ |
| 214 |
'Available options are:' +NL+ |
| 215 |
OptionDescription('-h / --help', 'Print this help message and exit.') + NL + |
| 216 |
OptionDescription('-v / --version', 'Print the version number and exit.') + NL + |
| 217 |
OptionDescription('-V / --verbose', |
| 218 |
'Verbose mode, output contains e.g. list of packaged files.') +NL+ |
| 219 |
OptionDescription('--mode=debug|release', |
| 220 |
'Compilation mode, used by "compile" and "package" commands. Also packaging mode on some platforms (right now, Android). By default "release".') +NL+ |
| 221 |
OptionDescription('--assume-compiled', |
| 222 |
'Do not automatically do "clean" and "compile" before "package". Instead assume that compiled executable for given OS/CPU/mode is already present in the package directory.') +NL+ |
| 223 |
OptionDescription('--fast', |
| 224 |
'Do not "clean" before "package". Recompile only what changed. This is faster for development, but cannot guarantee that everything is recompiled in a release mode.') +NL+ |
| 225 |
OptionDescription('--plugin', |
| 226 |
'Compile/package/install a browser NPAPI plugin. DEPRECATED.') +NL+ |
| 227 |
OptionDescription('--fpc-version-iphone-simulator VERSION', |
| 228 |
'When compiling for iPhone Simulator, we pass -V<VERSION> to the "fpc" command-line. This is necessary if you use the official "FPC for iOS" package (see the "Getting Started - iOS.rtf" inside the "FPC for iOS" dmg for explanation). You can set this to "auto" (this is the default) to auto-detect this based on regular FPC version. Or you can set this to a particular version, like "3.0.5". Or you can set this to empty "" to avoid passing any -V<VERSION> (suitable for FPC 3.1.1).') +NL+ |
| 229 |
OptionDescription('--compiler-option=PARAM', |
| 230 |
'Extra parameter for "fpc" command line. For example --compiler-option=-dUSE_MOUSE will add -dUSE_MOUSE. You can use this parameter multiple times.') +NL+ |
| 231 |
OptionDescription('--output=DIR', |
| 232 |
'Where to place the output executables, packages, and the "castle-engine-output" directory with temporary generated files.') +NL+ |
| 233 |
OptionDescription('--project=DIR', |
| 234 |
'Where to search for the project (CastleEngineManifest.xml file). By default we search in the current directory. The argument can either be a directory, or a filename of CastleEngineManifest.xml file.') +NL+ |
| 235 |
OptionDescription('--package-format=FORMAT', |
| 236 |
'Use with "package" command to customize the result.' + NL + |
| 237 |
'Available FORMAT values: ' +NL+ |
| 238 |
NL + |
| 239 |
'- default (platform specific; on most platforms creates a zip/tar.gz archive; on Android creates APK; on iOS creates Xcode project)' +NL+ |
| 240 |
'- zip (pack all files into zip)' +NL+ |
| 241 |
'- tar.gz (pack all files into tar.gz)' +NL+ |
| 242 |
'- directory (put all files into a new subdirectory)' +NL+ |
| 243 |
'- android-apk (only on Android: create APK)' +NL+ |
| 244 |
'- android-app-bundle (only on Android: create AAB)' +NL+ |
| 245 |
'- ios-archive-ad-hoc (only on iOS: archive using "ad-hoc" method to IPA file)' +NL+ |
| 246 |
'- ios-archive-development (only on iOS: archive using "development" method)' +NL+ |
| 247 |
'- ios-archive-app-store (only on iOS: distributes the application to the TestFlight and the AppStore)' +NL+ |
| 248 |
'') + NL + |
| 249 |
OptionDescription('--package-name-no-version', |
| 250 |
'Use with "package" command. The resulting file/directory name will not contain the version number.') + NL + |
| 251 |
OptionDescription('--update-only-code', |
| 252 |
'Use with "package" command. Makes the packaging faster, as you guarantee that only the Pascal code have changed since last packaging (so you did not change e.g. data/ or CastleEngineManifest.xml).') + NL + |
| 253 |
OptionDescription('--ios-simulator', |
| 254 |
'Use with "package" command when --target=iOS. Allows to run the project on iOS simulator.') + NL + |
| 255 |
OptionDescription('--all', |
| 256 |
'Use with "auto-generate-clean" command. Indicates to clean everything auto-generated. By default we only clean unused files from "auto_generated" directories.') +NL+ |
| 257 |
OptionDescription('--manifest-name=AlternativeManifest.xml', |
| 258 |
'Search and use given "AlternativeManifest.xml" file instead of standard "CastleEngineManifest.xml". Useful if you need to maintain completely different project configurations for any reason.') +NL+ |
| 259 |
OptionDescription('--wait-for-process-exit=PROCESS-ID', |
| 260 |
'Internal, useful with "editor-run".') +NL+ |
| 261 |
OptionDescription('--gui-errors', |
| 262 |
'Show errors as GUI boxes. On Unix, requires "zenity" installed.') +NL+ |
| 263 |
OptionDescription('--compiler=COMPILER', |
| 264 |
'Select compiler: "autodetect", "fpc", "delphi".') +NL+ |
| 265 |
OptionDescription('--guid-from-name', |
| 266 |
'Use with "generate-program" command. Will generate stable GUID (in Delphi DPROJ) from project''s qualified name.') +NL+ |
| 267 |
OptionDescription('--windows-robust-pipes', |
| 268 |
'Only on Windows (ignored on other systems): Force using less performant, but more robust, way to run child processes with "passthrough", like for "castle-engine run". Useful to run "castle-engine run" from PowerShell, outside of CGE editor.') + NL + |
| 269 |
TargetOptionHelp + |
| 270 |
NL + |
| 271 |
OSOptionHelp + |
| 272 |
NL + |
| 273 |
CPUOptionHelp + |
| 274 |
NL + |
| 275 |
'Defaults:' + NL + |
| 276 |
' android.compile_sdk_version = ' + IntToStr(TCastleManifest.DefaultAndroidCompileSdkVersion) + NL + |
| 277 |
' android.min_sdk_version = ' + IntToStr(TCastleManifest.DefaultAndroidMinSdkVersion) + NL + |
| 278 |
' android.target_sdk_version = ' + IntToStr(TCastleManifest.DefaultAndroidTargetSdkVersion) + NL + |
| 279 |
NL+ |
| 280 |
'Full documentation on' + NL + |
| 281 |
'https://castle-engine.io/build_tool' + NL + |
| 282 |
NL+ |
| 283 |
ApplicationProperties.Description); |
| 284 |
Halt; |
| 285 |
end; |
| 286 |
1 : begin |
| 287 |
// include ApplicationName in version, good for help2man |
| 288 |
Writeln(ApplicationName + ' ' + ApplicationProperties.Version); |
| 289 |
Halt; |
| 290 |
end; |
| 291 |
2 : Target := StringToTarget(Argument); |
| 292 |
3 : OS := StringToOS(Argument); |
| 293 |
4 : CPU := StringToCPU(Argument); |
| 294 |
5 : Verbose := true; |
| 295 |
6 : Mode := StringToMode(Argument); |
| 296 |
7 : AssumeCompiled := true; |
| 297 |
8 : Fast := true; |
| 298 |
9 : WritelnWarning('NPAPI plugin is no longer available, ignoring --plugin'); |
| 299 |
10: FPCVersionForIPhoneSimulator := Argument; |
| 300 |
11: CompilerExtraOptions.Add(Argument); |
| 301 |
12: OutputPathBase := Argument; |
| 302 |
13: ChangeProjectDir(Argument); |
| 303 |
14: PackageFormat := StringToPackageFormat(Argument); |
| 304 |
15: PackageNameIncludeVersion := false; |
| 305 |
16: UpdateOnlyCode := true; |
| 306 |
17: IosSimulatorSupport := true; |
| 307 |
18: CleanAll := true; |
| 308 |
19: ManifestName := Argument; |
| 309 |
20: WaitForProcessId := StrToInt64(Argument); |
| 310 |
21: GuiErrors := true; |
| 311 |
22: OverrideCompiler := StringToCompiler(Argument); |
| 312 |
23: GuidFromName := true; |
| 313 |
24: {$ifdef MSWINDOWS} ForcePipesPassthrough := true {$endif}; |
| 314 |
25: ProjectTemplate := Argument; |
| 315 |
26: ProjectParentDir := Argument; |
| 316 |
27: ProjectCaption := Argument; |
| 317 |
28: ProjectMainView := Argument; |
| 318 |
else raise EInternalError.Create('OptionProc'); |
| 319 |
end; |
| 320 |
end; |
| 321 |
|
| 322 |
{ For some operations (like creating an Android project), the tool uses |
| 323 |
ApplicationData files. So make sure that ApplicationData is correct. |
| 324 |
We can use CastleEnginePath (that uses various detection methods) for this. } |
| 325 |
procedure AdjustApplicationData; |
| 326 |
var |
| 327 |
DataPath: string; |
| 328 |
begin |
| 329 |
if CastleEnginePath <> '' then |
| 330 |
begin |
| 331 |
DataPath := CastleEnginePath + |
| 332 |
'tools' + PathDelim + 'build-tool' + PathDelim + 'data' + PathDelim; |
| 333 |
if DirectoryExists(DataPath) then |
| 334 |
ApplicationDataOverride := FilenameToUriSafe(DataPath); |
| 335 |
|
| 336 |
{ We do not complain when CastleEnginePath is empty or doesn't contain |
| 337 |
valid data, because CastleEnginePath already did that. } |
| 338 |
end; |
| 339 |
end; |
| 340 |
|
| 341 |
procedure Run; |
| 342 |
var |
| 343 |
Command, S, FileName: string; |
| 344 |
Project: TCastleProject; |
| 345 |
RestOfParameters: TCastleStringList; |
| 346 |
SimpleCompileOptions: TCompilerOptions; // used only when command is "simple-compile" |
| 347 |
|
| 348 |
function CreateRunParameters: TCastleStringList; |
| 349 |
begin |
| 350 |
Result := TCastleStringList.Create; |
| 351 |
Result.Text := Parameters.Text; |
| 352 |
Result.Delete(0); // remove our own name |
| 353 |
Assert(SameText(Result[0], 'run') or SameText(Result[0], 'compile-run')); |
| 354 |
Result.Delete(0); // remove "run" |
| 355 |
end; |
| 356 |
|
| 357 |
begin |
| 358 |
ApplicationProperties.ApplicationName := 'castle-engine'; |
| 359 |
ApplicationProperties.Version := CastleEngineVersion; |
| 360 |
ApplicationProperties.OnWarning.Add(@ApplicationProperties.WriteWarningOnConsole); |
| 361 |
|
| 362 |
OS := DefaultOS; |
| 363 |
CPU := DefaultCPU; |
| 364 |
CompilerExtraOptions := TCastleStringList.Create(); |
| 365 |
|
| 366 |
{ parse parameters } |
| 367 |
Parameters.Parse(Options, @OptionProc, nil); |
| 368 |
if Parameters.High < 1 then |
| 369 |
raise EInvalidParams.Create('Not enough command-line parameters, expected a COMMAND to perform. Use --help to get usage information') else |
| 370 |
Command := Parameters[1]; |
| 371 |
|
| 372 |
{ check OS, CPU } |
| 373 |
if not OSCPUSupported[OS, CPU] then |
| 374 |
begin |
| 375 |
S := Format('The combination of operating system "%s" and processor "%s" is not possible (or not supported by FPC)', |
| 376 |
[OSToString(OS), CPUToString(CPU)]); |
| 377 |
if OS in AllWindowsOSes then |
| 378 |
S += '. Note: in case of Windows 64-bit, remember to specify both OS and CPU like this: "--os=win64 --cpu=x86_64"'; |
| 379 |
raise EInvalidParams.Create(S); |
| 380 |
end; |
| 381 |
|
| 382 |
AdjustApplicationData; |
| 383 |
|
| 384 |
if Command = 'simple-compile' then |
| 385 |
begin |
| 386 |
Parameters.CheckHigh(2); |
| 387 |
FileName := Parameters[2]; |
| 388 |
{ use GetCurrentDir as WorkingDir, |
| 389 |
so calling "castle-engine simple-compile somesubdir/myunit.pas" works. |
| 390 |
Working dir for FPC must be equal to our own working dir. } |
| 391 |
SimpleCompileOptions := TCompilerOptions.Create; |
| 392 |
try |
| 393 |
SimpleCompileOptions.OS := OS; |
| 394 |
SimpleCompileOptions.CPU := CPU; |
| 395 |
SimpleCompileOptions.DetectMemoryLeaks := false; |
| 396 |
SimpleCompileOptions.Mode := Mode; |
| 397 |
SimpleCompileOptions.ExtraOptions.AddRange(CompilerExtraOptions); |
| 398 |
case Target of |
| 399 |
targetCustom : Compile(OverrideCompiler, GetCurrentDir, FileName, SimpleCompileOptions); |
| 400 |
targetAndroid : CompileAndroid(OverrideCompiler, nil, GetCurrentDir, FileName, SimpleCompileOptions); |
| 401 |
targetIOS : CompileIOS(OverrideCompiler, GetCurrentDir, FileName, SimpleCompileOptions); |
| 402 |
targetNintendoSwitch: CompileNintendoSwitch(GetCurrentDir, FileName, SimpleCompileOptions); |
| 403 |
{$ifndef COMPILER_CASE_ANALYSIS} |
| 404 |
else raise EInternalError.Create('Operation not implemented for this target'); |
| 405 |
{$endif} |
| 406 |
end; |
| 407 |
finally FreeAndNil(SimpleCompileOptions) end; |
| 408 |
end else |
| 409 |
if Command = 'cache' then |
| 410 |
begin |
| 411 |
Parameters.CheckHigh(1); |
| 412 |
CacheCreate(OverrideCompiler, Target, OS, CPU); |
| 413 |
end else |
| 414 |
if Command = 'cache-clean' then |
| 415 |
begin |
| 416 |
Parameters.CheckHigh(1); |
| 417 |
CacheClean; |
| 418 |
end else |
| 419 |
if Command = 'output-environment' then |
| 420 |
begin |
| 421 |
Parameters.CheckHigh(2); |
| 422 |
DoOutputEnvironment(Parameters[2]); |
| 423 |
end else |
| 424 |
if Command = 'create' then |
| 425 |
begin |
| 426 |
Parameters.CheckHigh(2); |
| 427 |
if ProjectParentDir = '' then |
| 428 |
ProjectParentDir := GetCurrentDir; |
| 429 |
if ProjectCaption = '' then |
| 430 |
ProjectCaption := Parameters[2]; |
| 431 |
Project := TCastleProject.CreateNewProject(ProjectParentDir, Parameters[2], |
| 432 |
ProjectTemplate, ProjectCaption, ProjectMainView); |
| 433 |
FreeAndNil(Project); |
| 434 |
end else |
| 435 |
begin |
| 436 |
if (Command <> 'run') and // allows any number of params |
| 437 |
(Command <> 'compile-run') and // allows any number of params |
| 438 |
(Command <> 'output') then // check params count by Parameters.CheckHigh on its own |
| 439 |
Parameters.CheckHigh(1); |
| 440 |
Project := TCastleProject.Create; |
| 441 |
try |
| 442 |
if Command = 'create-manifest' then |
| 443 |
Project.DoCreateManifest |
| 444 |
else |
| 445 |
if Command = 'compile' then |
| 446 |
Project.DoCompile(OverrideCompiler, Target, OS, CPU, Mode, CompilerExtraOptions) |
| 447 |
else |
| 448 |
if Command = 'package' then |
| 449 |
begin |
| 450 |
if not AssumeCompiled then |
| 451 |
begin |
| 452 |
if not Fast then |
| 453 |
Project.DoClean; |
| 454 |
Project.DoCompile(OverrideCompiler, Target, OS, CPU, Mode, CompilerExtraOptions); |
| 455 |
end; |
| 456 |
Project.DoPackage(Target, OS, CPU, Mode, PackageFormat, PackageNameIncludeVersion, UpdateOnlyCode); |
| 457 |
end else |
| 458 |
if Command = 'install' then |
| 459 |
Project.DoInstall(Target, OS, CPU, Mode, PackageFormat, PackageNameIncludeVersion) |
| 460 |
else |
| 461 |
if Command = 'run' then |
| 462 |
begin |
| 463 |
RestOfParameters := CreateRunParameters; |
| 464 |
try |
| 465 |
Project.DoRun(Target, OS, CPU, RestOfParameters); |
| 466 |
finally FreeAndNil(RestOfParameters) end; |
| 467 |
end else |
| 468 |
if Command = 'compile-run' then |
| 469 |
begin |
| 470 |
Project.DoCompile(OverrideCompiler, Target, OS, CPU, Mode, CompilerExtraOptions); |
| 471 |
RestOfParameters := CreateRunParameters; |
| 472 |
try |
| 473 |
Project.DoRun(Target, OS, CPU, RestOfParameters); |
| 474 |
finally FreeAndNil(RestOfParameters) end; |
| 475 |
end |
| 476 |
else |
| 477 |
if Command = 'package-source' then |
| 478 |
begin |
| 479 |
Project.DoClean; |
| 480 |
Project.DoPackageSource(PackageFormat, PackageNameIncludeVersion); |
| 481 |
end else |
| 482 |
if Command = 'clean' then |
| 483 |
Project.DoClean |
| 484 |
else |
| 485 |
if Command = 'auto-generate-textures' then |
| 486 |
Project.DoAutoGenerateTextures |
| 487 |
else |
| 488 |
if Command = 'auto-generate-clean' then |
| 489 |
Project.DoAutoGenerateClean(CleanAll) |
| 490 |
else |
| 491 |
if Command = 'generate-program' then |
| 492 |
Project.DoGenerateProgram(GuidFromName) |
| 493 |
else |
| 494 |
if Command = 'editor' then |
| 495 |
Project.DoEditor |
| 496 |
else |
| 497 |
if Command = 'editor-rebuild-if-needed' then |
| 498 |
Project.DoEditorRebuildIfNeeded |
| 499 |
else |
| 500 |
if Command = 'editor-run' then |
| 501 |
Project.DoEditorRun(WaitForProcessId) |
| 502 |
else |
| 503 |
if Command = 'output' then |
| 504 |
begin |
| 505 |
Parameters.CheckHigh(2); |
| 506 |
Project.DoOutput(Parameters[2]); |
| 507 |
end else |
| 508 |
raise EInvalidParams.CreateFmt('Invalid COMMAND to perform: "%s". Use --help to get usage information', [Command]); |
| 509 |
finally FreeAndNil(Project) end; |
| 510 |
end; |
| 511 |
|
| 512 |
FreeAndNil(CompilerExtraOptions); |
| 513 |
end; |
| 514 |
|
| 515 |
begin |
| 516 |
try |
| 517 |
Run; |
| 518 |
except |
| 519 |
on E: TObject do |
| 520 |
begin |
| 521 |
{ In case of exception, write nice message and exit with non-zero status, |
| 522 |
without dumping any stack trace (because it's normal for build tool to |
| 523 |
exit with exception in case of project/environment error, not a bug). } |
| 524 |
if GuiErrors then |
| 525 |
ErrorBox(ExceptMessage(E)) |
| 526 |
else |
| 527 |
Writeln(ErrOutput, ExceptMessage(E)); |
| 528 |
Halt(1); |
| 529 |
end; |
| 530 |
end; |
| 531 |
end. |