Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/Android/AndroidToolChain.cs
Jack Porter ae727f8dab Copying //UE4/Dev-Mobile to //UE4/Dev-Main (Source: //UE4/Dev-Mobile @ 3383462)
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3292174 on 2017/02/08 by Nick.Shin

	HTML5 emscripten: wasm and webgl2 support

	- Linux toolchain

	#jira UEPLAT-1437  Switch [to] web assembly

Change 3292193 on 2017/02/08 by Nick.Shin

	HTML5 emscripten: wasm and webgl2 support

	- ThirdParty libs compiled with new toolchain with wasm support

	#jira UEPLAT-1437  Switch [to] web assembly

Change 3292215 on 2017/02/08 by Nick.Shin

	HTML5 emscripten: wasm and wbegl2 support

	- emscripten toolchain

	#jira UEPLAT-1437  Switch [to] web assembly

Change 3292222 on 2017/02/08 by Nick.Shin

	HTML5 emscripten: wasm support

	- ENGINE changes (c# & cpp files)

	#jira UEPLAT-1437  Switch [to] web assembly

Change 3292223 on 2017/02/08 by Nick.Shin

	HTML5 merge ThirdParty lib build scripts from Dev-Platform to Dev-Mobile

Change 3292228 on 2017/02/08 by Nick.Shin

	HTML5 emscripten: webgl support

	- webgl patches
	- and a lot of UE4 patches to package HTML5 on LINUX
	- mostly from mozilla's jukka -- thx jukka!

	#jira  UEPLAT-828  (4.16)  Support ES3 / WebGL2 in HTML5

Change 3292285 on 2017/02/08 by Nick.Shin

	HTML5 emscripten: wasm and webgl2 support

	- Windows toolchain

	#jira UEPLAT-1437  Switch [to] web assembly

Change 3293994 on 2017/02/09 by Nick.Shin

	HTML5 emscripten: wasm and webgl2 support

	- OSX toolchain

	#jira UEPLAT-1437  Switch [to] web assembly

Change 3294391 on 2017/02/09 by Nick.Shin

	HTML5 "black box issues" revisited

	- jukka rewrote the window resize handler -- much cleaner and more straightforward

	#jira UE-36341  HTML5 - View is incorrectly drawn
	#jira UE-32311  Templates on Firefox/Chrome on HTML5 are not full screen during Launch On

Change 3296421 on 2017/02/10 by Jack.Porter

	Fix landscape spline segment splitting placing when using streaming levels

Change 3296587 on 2017/02/10 by Jack.Porter

	Additional fix for landscape spline segment splitting when using streaming levels

Change 3301241 on 2017/02/14 by Mi.Wang

	Fixed DeviceProfileEditor bug for incorrect clamp the Texture Mip LOD size. #jira UE-36237 #rb jack.porter

Change 3301387 on 2017/02/14 by Nick.Shin

	HTML5 emscripten: webgl support

	- webgl patches from mozilla's jukka
	  + hardware instancing
	  + glBlitFramebuffer
	  + GL AlaphaBlendOperation

	#jira  UEPLAT-828  (4.16)  Support ES3 / WebGL2 in HTML5

Change 3301405 on 2017/02/14 by Nick.Shin

	HTML5 plugin fix when blueprint projects are promoted to code projects automatically.

	#jira UE-41710  HTML5 - Package Failure - Failed to Produce item ProjectName-OnlineSubsystemNull.bc

Change 3302278 on 2017/02/14 by Omar.Rodriguez

	UE-36651: Mac Vulkan Android Projects crash on launch.

	* Glslang library has been built for Mac but flag was not updated
	* Set GlslangAvailable to true for Mac when building an Android project with vulkan

	#jira UE-36651

Change 3302773 on 2017/02/14 by Chris.Babcock

	Add a dropdown with some common console commands on Android (contributed by rafortis)
	#jira UE-40834
	#PR #3143
	#ue4
	#android

Change 3305604 on 2017/02/16 by Nick.Shin

	HTML5 webgl2 shader- turn on: instance static mesh vertex factory

	#jira  UEPLAT-828  (4.16)  Support ES3 / WebGL2 in HTML5

Change 3308154 on 2017/02/16 by Nick.Shin

	HTML5 GitHub PR

	#jira UE-42019  GitHub 3258 : Added suport for emscripten --pre-js and --post-js option when building for HTML5

Change 3308510 on 2017/02/16 by Nick.Shin

	HTML5 webgl2 shader fixes

	#jria UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3308971 on 2017/02/17 by Jack.Porter

	Fix for landscape painting when height<0 in the Ortho viewports

Change 3309075 on 2017/02/17 by Allan.Bentham

	Include static subject meshes when masking out modulated shadow casters.

	#jira UE-41581

Change 3309531 on 2017/02/17 by Chris.Babcock

	Handle large OBB files in APK
	#jira UE-41443
	#ue4
	#android

Change 3311320 on 2017/02/19 by Dmitriy.Dyomin

	Fixed: Particle Cutout Crashes On Mobile Devices That Don't Support Hardware Instancing (Mali-400 GPU)
	#jira UE-41970

Change 3311347 on 2017/02/20 by Dmitriy.Dyomin

	Fixed: Engine Crashes When Previewing ES3_1 With Material Using World Position Offset (Need Custom Stencil)
	#jira UE-41976

Change 3311398 on 2017/02/20 by Dmitriy.Dyomin

	Fixed: Landscapes do not render on PowerVR device
	#jira UE-35530

Change 3311428 on 2017/02/20 by Dmitriy.Dyomin

	Fixed: Exposure Is More Extreme In High-End Mobile Preview Modes
	#jira UE-42036

Change 3311448 on 2017/02/20 by Dmitriy.Dyomin

	Fixed: Packaged game Crashes on android after entering "Help" command twice
	#jira UE-41956

Change 3311587 on 2017/02/20 by Allan.Bentham

	ES2 GLSL - Silently swap all uint to ints
	#jira UE-41548

Change 3313930 on 2017/02/21 by Allan.Bentham

	Print literal uints as ints when generating ES2 code.
	#jira UE-41548

Change 3317924 on 2017/02/22 by Nick.Shin

	HTML5 emscripten: wasm & webgl2 support - RC1

	- Linux toolchain

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3317929 on 2017/02/22 by Nick.Shin

	HTML5 emscripten: wasm & webgl2 support - RC1

	- ThirdParty libs compiled with new toolchain with wasm and webgl2 support

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3317951 on 2017/02/22 by Nick.Shin

	HTML5 emscripten: wasm & webgl2 support - RC1

	- emscripten toolchain

	WARNING: emscripten/incoming/source/include/libc/bit (the file) might need to be deleted first

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3318004 on 2017/02/22 by Nick.Shin

	HTML5 emscripten: wasm & webgl2 support - RC1

	- windows toolchain

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3318669 on 2017/02/23 by Nick.Shin

	HTML5 emscripten: wasm & webgl2 support - RC1

	- OSX toolchain

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3318672 on 2017/02/23 by Nick.Shin

	HTML5 webgl2 shader fixes

	#jria UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3318819 on 2017/02/23 by Dmitriy.Dyomin

	Fixed: Rendering artifacts with bloom on iPhone7 Metal
	#jira UE-40978

Change 3319702 on 2017/02/23 by Chris.Babcock

	Disable eglSwapInterval since it can cause issues with some drivers
	#ue4
	#android

Change 3320880 on 2017/02/24 by Dmitriy.Dyomin

	Added r.Mobile.TonemapperFilm cvar which can be used to enable/disable filmic tonemapper on mobile, independently from desktop (disabled by default)
	#jira UEMOB-195

Change 3321042 on 2017/02/24 by Jack.Porter

	Fixed incorrect sizeof in Vulkan pipleine cache
	pointed out here: http://coconutlizard.co.uk/blog/ue4/ue4-its-a-size-jim/

	#code_review: rolando.caloca

Change 3322383 on 2017/02/24 by Chris.Babcock

	Fix issue with ad banner on Android 7.0 devices
	#jira UE-42390
	#ue4
	#android

Change 3322479 on 2017/02/24 by Omar.Rodriguez

	UEMOB-199 - WEX: Improved virtual keyboard for Android

	* Calculating the area covered by the virtual keyboard
	* Calling OnVirtualKeyboardShown and OnVirtualKeyboardHidden events
	* Passing the Rect of the area covered by the virtual keyboard OnVirtualKeyboardShown event

	#jira UEMOB-199

Change 3323353 on 2017/02/27 by Allan.Bentham

	Fix broken mobile scene captures when !mobileHDR and RHINeedsToSwitchVerticalAxis
	#jira UE-42191

Change 3323431 on 2017/02/27 by Allan.Bentham

	CIS fix

Change 3323687 on 2017/02/27 by Allan.Bentham

	Disable GRHINeedsUnatlasedCSMDepthsWorkaround for mobile devices.
	#jira UE-42131

Change 3324652 on 2017/02/28 by Dmitriy.Dyomin

	Fixed: Canvas elements appear darker on iOS Metal

Change 3324885 on 2017/02/28 by Jack.Porter

	Fixed "Minimum iOS Version" setting display name

	#jira UE-42270

Change 3324899 on 2017/02/28 by Jack.Porter

	GitHub 3063 : removed duplicate gc.MaxObjectsInGame setting in IOSEngine.ini
	#jira UE-40018

	#3063

Change 3324932 on 2017/02/28 by Jack.Porter

	GitHub 3257 : iPhonePackager errors in output log when opening project settings on Windows

	#jira UE-41984
	#3257
	#codereview: Peter.Sauerbrei

Change 3324956 on 2017/02/28 by Jack.Porter

	FOpenGLFrontend::GetMaxSamplers incorrect for IOS
	#jira UE-42038
	#3264

Change 3325478 on 2017/02/28 by Allan.Bentham

	PR # 3188   : Fix far distance bug with cascaded shadows on mobile (Metal) and PC mobile preview  (Contributed by ufna)

	#jira UE-41442

Change 3327300 on 2017/03/01 by Allan.Bentham

	PR #3175   : Fixes high quality reflection blending seams  (Contributed by kallehamalainen)
	#jira UE-41257

Change 3328917 on 2017/03/02 by Nick.Shin

	HTML5 project settings

	expose ini settings to edtior HTML5 project settings panel

	#jira UE-42331  Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini
	#jira UE-41584  Editor locks up when adding an element for HTML5 devices on Mac
	#jira UE-41701  Editor freezes when setting browser filepath for inserted element in project settings

Change 3329169 on 2017/03/02 by Allan.Bentham

	increase render thread timeout to 1 minute for suntemple / android.
	Prevents low end devices timing out during load.
	#jira UE-40696

Change 3330849 on 2017/03/02 by Nick.Shin

	HTML5 project settings

	expose ini settings to edtior HTML5 project settings panel

	#jira UE-42331  Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini

Change 3331078 on 2017/03/03 by Dmitriy.Dyomin

	Fixed: Device output log partial lines

	integrated from WEX (3250488)

Change 3331112 on 2017/03/03 by Dmitriy.Dyomin

	Reduced state setup for slate draw calls (saves about 4ms RT time on mobile)

	integrated from WEX (3256584)

Change 3331117 on 2017/03/03 by Dmitriy.Dyomin

	Fixed redundant blend state changes in opengl

	integrated from WEX (3256586)

Change 3331173 on 2017/03/03 by Dmitriy.Dyomin

	Slate pixel shaders will use half precision where possible on mobile

	integrated from WEX (3256656)

Change 3332865 on 2017/03/06 by Dmitriy.Dyomin

	Better MobileContentScaleFactor defaults for iOS devices
	#jira UEMOB-330

Change 3333129 on 2017/03/06 by Peter.Sauerbrei

	move to Library/Caches instead of documents for saved files
	re-enable iterative deploy on TVOS
	#jira UEMOB-284

Change 3334692 on 2017/03/06 by Jack.Porter

	Allow r.MobileContentScaleFactor to be changed at runtime on Android

	#jira UEMOB-173

Change 3336255 on 2017/03/07 by Nick.Shin

	HTML5 project settings

	marking SIMD and multithreading as experimental - these do not play nice with WASM builds currently...

	#jira UE-42331  Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini

Change 3337094 on 2017/03/08 by Nick.Shin

	HTML5 project settings

	marking SIMD and multithreading as experimental - these do not play nice with WASM builds currently...

	#jira UE-42331  Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini

Change 3338800 on 2017/03/08 by Chris.Babcock

	Update AAR handling to deal with versioning, subproject dependencies for resources, and scope
	#jira UE-42677
	#ue4
	#android

Change 3338813 on 2017/03/08 by Chris.Babcock

	Pass build configuration to UPL for access during packaging as $S(Configuration)
	#jira UE-42678
	#ue4
	#android
	#ios

Change 3339401 on 2017/03/09 by Alicia.Cano

	Android runtime permissions
	- Fix for WRITE_EXTERNAL_STORAGE if it is not granted at time of onCreate for non-shipping builds
	- Fix for Location Services
	- Fix for if target sdk is not set to 23+
	#jira UE-38512
	#android
	#rb: chris.babcock

Change 3340736 on 2017/03/09 by Chris.Babcock

	Implement support for new controllers (Xbox Wireless, SteelSeries Stratus XL, PS4) (contributed by TRS-justing)
	#jira UE-41965
	#PR #3254
	#ue4
	#android

Change 3340744 on 2017/03/09 by Jack.Porter

	Expose Custom Depth to Foliage
	#jira UE-6061

Change 3340849 on 2017/03/09 by Dmitriy.Dyomin

	Fixed: iOS movie become laggy and crashes when played in iPhone 6/6s.
	#jira UE-42351

Change 3341268 on 2017/03/10 by Alicia.Cano

	PR #2894: Initial VoiceModuleAndroid support. (Contributed by devbm)
	#jira UE-37945
	#android
	#rb: chris.babcock, jack.porter

Change 3341303 on 2017/03/10 by Allan.Bentham

	Remove optimisation that prevents full specular occulsion on mobile.
	PR #3186  : Specular can't be blocked on high-end mobile.
	#jira UE-41393

Change 3342304 on 2017/03/10 by Alicia.Cano

	build fix
	#rb: chris.babcock

Change 3343344 on 2017/03/13 by Alicia.Cano

	build fix
	#rb: chris.babcock

Change 3343591 on 2017/03/13 by Brent.Pease

	iOS multiplayer fix part 1. Correct byte ordering.

	#jira UE-34875

Change 3343669 on 2017/03/13 by Chris.Babcock

	Update carefullyredist script version
	#jira UE-42832

Change 3344212 on 2017/03/13 by Will.Fissler

	Various compile fixes for Xcode 8.3.
	These fixes must also be added to //UE4/Release-4.15.
	#jira UE-41313

Change 3344396 on 2017/03/13 by Chris.Babcock

	Fix Java 1.5 obsolete warnings
	#jira UE-42851
	#ue4
	#android

Change 3345132 on 2017/03/14 by Will.Fissler

	Added ifdef wrapper to check clang version for presentDrawable.

Change 3345336 on 2017/03/14 by Will.Fissler

	Moved #if (__clang_major__ > 8) || (__clang_major__ == 8 && __clang_minor__ >= 1) check inside of the presentDrawable method.

Change 3345460 on 2017/03/14 by Will.Fissler

	ifdef changes for presentDrawable. The last submission duped the changes, instead of merging. #rb none

Change 3346046 on 2017/03/14 by Will.Fissler

	Fixed MetalCommandBuffer.cpp [again] after last submission duped changes instead of merging.

Change 3346367 on 2017/03/14 by Chris.Babcock

	Fix issue with GoogleVR ARMv7 libraries included for other architectures in link
	#ue4
	#android

Change 3347682 on 2017/03/15 by Allan.Bentham

	Enable HW sRGB correction with retainer widget's render target.
	Use slate's gamma correction for mobile (where no such support exists)
	Render retainer box RT content with gamma correction.
	#jira UE-40967

Change 3348712 on 2017/03/15 by Nick.Shin

	HTML5 - upload to S3

	updated to AWS "signature version 4" authentication

	#jira UE-42525  HTML5 Upload to Amazon S3 fails with Incorrect Configuration error

Change 3349254 on 2017/03/16 by Jack.Porter

	Fix for crash using the mobile previewer when the LQ lightmap shader permutation is disabled.
	#jira UE-42971

Change 3349739 on 2017/03/16 by Nick.Shin

	HTML5 - upload to S3

	better error message feedback on upload failures

	#jira UE-42525  HTML5 Upload to Amazon S3 fails with Incorrect Configuration error

Change 3349765 on 2017/03/16 by Alicia.Cano

	Disable mouseover events in Mobile Previewer

	#jira UE-19903
	#mobile
	#rb: Jack.Porter

Change 3350049 on 2017/03/16 by Nick.Shin

	HTML5 - upload to S3

	folder in bucket is optional

	#jira UE-42525  HTML5 Upload to Amazon S3 fails with Incorrect Configuration error

Change 3350153 on 2017/03/16 by Nick.Shin

	HTML5 - upload to S3

	updated S3 public link generator

	#jira UE-42525  HTML5 Upload to Amazon S3 fails with Incorrect Configuration error

Change 3351582 on 2017/03/17 by Will.Fissler

	Reverting the attempted fix for Xcode 8.3: Result += " -mcpu=cortex-a9";

	Currently we cannot build arm64 for iOS with this change.

Change 3352085 on 2017/03/17 by Alicia.Cano

	iOS doesn't honor request to close the virtual keyboard leading to a crash
	#jira UE-36447
	#ios
	#rb:Peter.Sauerbrei

Change 3353313 on 2017/03/19 by Ben.Marsh

	Always allow large *.js files in Github.

Change 3354444 on 2017/03/20 by Nick.Shin

	HTML5 - upload to S3

	to help make it obvious that "upload to S3" checkbox is set/or not -- disable S3 details if checkbox for "uploading to S3" is not set

	#jira UE-42525  HTML5 Upload to Amazon S3 fails with Incorrect Configuration error

Change 3355618 on 2017/03/20 by Nick.Shin

	HTML5 Save Game System

	- ripped out HTML5 code [from Engine's SaveGameSystem.h] and placed it in HTML5Platform.cpp
	- cleaned up HTML5PlatformFile.cpp (make it match as clost to linux's version)
	- created HTML5's own PlatformFeature & SaveGameSystem files -- and updated HTML5PlatformMisc to make use of the the new HTML5 SaveGame code

	#jira UE-42081 Remove heinous HTML5 code from engine

Change 3355621 on 2017/03/20 by Nick.Shin

	remove temp debugging code

	#jira UE-42081 Remove heinous HTML5 code from engine

Change 3356937 on 2017/03/21 by Chris.Babcock

	Add "stat vulkanrhi" to new console dropdown
	#jira UE-43149
	#ue4
	#android

Change 3357652 on 2017/03/21 by Nick.Shin

	HTML5 performance speed ups

	added "use fixed timestep" setting option for HTML5 builds (this has been separated from Engine - General Settings - Framerate)
	- this is slightly different to smooth framerate and fixed framerate - thus, the timestep option was put in the HTML5 specific panel

	this option is based on the suggestions by jukka's post:
	- https://answers.unrealengine.com/questions/409629/smooth-frame-rate-and-use-fixed-frame-rate-should.html

	however, using this option will make the player "run faster" on (for example) thirdperson blueprint template -- but, it has no effect on other (for example) zen garden...

	#jira UE-30214 - Implement a warning message for fps settings

Change 3360415 on 2017/03/23 by Allan.Bentham

	Fix crash that occurs when ES3.1 preview is used with r.MobileHDR32bppMode modes.

Change 3360418 on 2017/03/23 by Allan.Bentham

	Disable filmic tonemapper if r.MobileHDR32bppMode is in use.
	#jira UE-40913

Change 3360557 on 2017/03/23 by Allan.Bentham

	Better fix for mobile CSM shadow flickering (UE-42131), now works for PC OpenGL based mobile preview.
	#jira UE-42131

Change 3362258 on 2017/03/23 by Dmitriy.Dyomin

	Fixed: Canvas texture element gamma issues on iOS Metal

Change 3362321 on 2017/03/24 by Dmitriy.Dyomin

	GitHub 3173 : MaterialAO support for mobile rendering path (contributed by kallehamalainen)

	#3173

Change 3363550 on 2017/03/24 by Alicia.Cano

	build fix for devices < Android 5.0
	#jira UE-43299
	#android
	#rb: chris.babcock

Change 3363687 on 2017/03/24 by Chris.Babcock

	Fix Android password hiding in input dialog
	#jira WEX-5159
	#ue4
	#android

Change 3365280 on 2017/03/27 by Dmitriy.Dyomin

	Fix for GL_EXT_shader_framebuffer_fetch on Zenfone5. Use UE_EXT_shader_framebuffer_fetch define on all devices to enable extension

Change 3365291 on 2017/03/27 by Dmitriy.Dyomin

	Copied form WEX CL# 3308653
	Fixed: Enabling shader cache causes crash on NVIDIA Shield

	#jira UE-41639

Change 3365293 on 2017/03/27 by Dmitriy.Dyomin

	GitHub 3411 : Fix crash in patching utils mount method (contributed by nverenik)
	#jira UE-43247
	#3411

Change 3365340 on 2017/03/27 by Dmitriy.Dyomin

	Fixed: Moving sublevel in world composition browser does not appear in Undo History
	#jira UE-35535

Change 3365564 on 2017/03/27 by Allan.Bentham

	SkyLightComponent now serializes IrradianceMap SH values.
	clicking Recapture sky button in mobile preview switches back to SM4/5 to update captures.
	Skylights that are dirty from load will trigger reflection capture update once shaders are rebuilt.
	#jira UE-42436

Change 3366282 on 2017/03/27 by Nick.Shin

	remove dead links

	these files to not exist anywhere in the make-3.81 subfolders

	#UDN-354501
	#jira none

Change 3366306 on 2017/03/27 by Nick.Shin

	HTML5 - disable multi-threading for wasm

	#jira UE-43219 - HTML5 disable multi-threading for wasm

Change 3366307 on 2017/03/27 by Nick.Shin

	HTML5 packaging Shipping builds

	big cleanup / additions to *gz file support for amazon s3

	* both, uploading to s3
	* and allowing s3 to host the games there

	#jira UE-43002 HTML5 in Shipping fails downloading symbols files
	#jria UE-43001 HTML5 Shipping Projects fail looking for compressed files when "Compress files during shipping packaging" is not selected.

Change 3367385 on 2017/03/28 by Allan.Bentham

	Display skylight serialization warning only when cooking for mobile platforms.
	#jira UE-42436

Change 3368583 on 2017/03/28 by Chris.Babcock

	Expose JAVA_HOME setting in Android SDK project settings on Mac
	#jira UE-43418
	#ue4
	#android

Change 3368803 on 2017/03/28 by Chris.Babcock

	Fix features requested in manifest for "Daydream and Cardboard" mode
	#jira UE-43314
	#ue4
	#android

Change 3369087 on 2017/03/28 by Jack.Porter

	Changed tooltip and added supported devices in paretheses for Android Mobile Deferred / ES31+AEP
	#jira UE-42438

Change 3369372 on 2017/03/29 by Allan.Bentham

	Fix disappearing meshes when r.mobile.allowdistancefieldshadows is disabled.
	#jira UE-43366

Change 3369381 on 2017/03/29 by Jack.Porter

	Show warnings when mobile shader permutations required for rendering are disbaled
	Made FReadOnlyCVARCache a singleton and added mobile CVars, used for MobileBasePassRendering.
	#jira UE-43050

Change 3369430 on 2017/03/29 by Allan.Bentham

	fix CIS build

Change 3369740 on 2017/03/29 by Allan.Bentham

	Added Android option to enable builds with hidden symbol visbility by default. (bBuildWithHiddenSymbolVisibility)
	Android links with -gc-sections to remove unused code/data
	Add JNI_METHOD for java accessible native functions, fixed up existing JNI functions to use macro.
	Add support for map file generation with android.
	Add 'bBuildWithHiddenSymbolVisibility' to AndroidPlatform.HasDefaultBuildConfig()
	bBuildWithHiddenSymbolVisibility defaults to false in BaseEngine.ini

	#jira UEMOB-168

Change 3369975 on 2017/03/29 by Nick.Shin

	HTML5 - AWS S3 shareable link for shipping builds corrected

	#jira UE-43379 Amazon S3 Shareable link does not generate correct filepath.

Change 3369998 on 2017/03/29 by Nick.Shin

	HTML5 python build scripts

	PR:
	1cb836d43c

	#jira none

Change 3370214 on 2017/03/29 by Nick.Shin

	HTML5 - default bUseFixedTimeStep to false...

	#jira UE-43380 - Default HTML5 gamespeed is faster than equivalent platforms

Change 3370762 on 2017/03/29 by Chris.Babcock

	Fixes to new keyboard for Android
	- Ensure the local scope ScreenRect passed into OnVirtualKeyboardShown in AndroidJNI is captured by value instead of by reference.
	- Moved ShowVirtualKeyboardInput's bKeyboardShowing early-out checks into the UI thread task. This allows the keyboard to continue showing when changing focus between multiple EditableTextBox widgets.
	#ue4
	#android

Change 3371344 on 2017/03/30 by Jack.Porter

	Fixed issue where Vulkan screenshot R/B channels were reversed on Android
	#jira UE-43479

Change 3372926 on 2017/03/30 by Peter.Sauerbrei

	start the process of sunsetting 32-bit and GLES2 on iOS
	#jira UE-42266

Change 3372970 on 2017/03/30 by Nick.Shin

	HTML5 - 1.37.9 emscripten: wasm & webgl2 support

	- windows toolchain

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

	#rn

Change 3372989 on 2017/03/30 by Peter.Sauerbrei

	fix for Xcode 8.3 build with 32-bit

Change 3373007 on 2017/03/30 by Peter.Sauerbrei

	fix for crash when online subsystem is disabled on IOS

Change 3373108 on 2017/03/30 by Nick.Shin

	HTML5 - 1.37.9 emscripten: wasm & webgl2 support

	- emscripten toolchain

	WARNING: emscripten/incoming/source/include/libc/bit (the file) might need to be deleted first

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

	#rn

Change 3373163 on 2017/03/30 by Nick.Shin

	HTML5 - 1.37.9 emscripten: wasm & webgl2 support

	- OSX toolchain

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

	#rn

Change 3373169 on 2017/03/30 by Nick.Shin

	HTML5 - 1.37.9 emscripten: wasm & webgl2 support

	license file updated

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

	#rnx

Change 3373287 on 2017/03/30 by Nick.Shin

	HTML5 - 1.36.11 emscripten - remove old SDK

	#jira none

	#rnx

Change 3373289 on 2017/03/30 by Nick.Shin

	HTML5 - 1.37.9 emscripten: wasm & webgl2 support

	- Linux toolchain

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

	#rn

Change 3373595 on 2017/03/30 by Chris.Babcock

	Reenable GooglePlay for ARM64 now that it doesn't crash
	#jira UE-36198
	#ue4
	#android

Change 3373606 on 2017/03/30 by Chris.Babcock

	Submitting Allan's shelved EXT_shader_framebuffer_fetch fix
	#ue4
	#android

Change 3375456 on 2017/03/31 by Chris.Babcock

	Add missing keycodes for Android keyboard (@ and #)
	#jira WEX-5777
	#ue4
	#android

Change 3376309 on 2017/04/03 by Allan.Bentham

	Fix overflow issues with mobile DoF.

Change 3377041 on 2017/04/03 by Will.Fissler

	Adding Testbed content for PlatformShowcase.

Change 3377582 on 2017/04/03 by Alicia.Cano

	adding back in GET_ACCOUNTS permission as it is required for Reset Achievements

	#jira: UE-43265
	#android
	#rb: Chris.Babcock

Change 3377643 on 2017/04/03 by Peter.Sauerbrei

	fix for memory leak in MallocBinned
	#jira UE-43008

Change 3378033 on 2017/04/04 by Nick.Shin

	HTML5 - 1.37.9 emscripten: wasm & webgl2 support

	- ThirdParty libs compiled with new toolchain with wasm and webgl2 support

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

	#rn

Change 3378034 on 2017/04/04 by Nick.Shin

	HTML5 - 1.37.9 emscripten: wasm & webgl2 support

	- ThirdParty build scripts

	#jira UEMOB-263  Switch [to] web assembly
	#jira UEMOB-201  Support ES3 / WebGL2 in HTML5

Change 3378035 on 2017/04/04 by Nick.Shin

	HTML5 - Update GameX template to make it work with trunk Emscripten

	PR
	dc2b26f452 (commitcomment-21454978)

	#jira none

	#rn

Change 3378044 on 2017/04/04 by Nick.Shin

	HTML5 harfbuzz - double checking recompiled with NO multithreading

	wasm currently does not support pthreads

	*** THIS IS STILL WIP ***
	checking in to match 3rd party libs compiled configuration

	#jira UE-28588 - Build HarfBuzz for HTML5

	#rnx

Change 3378264 on 2017/04/04 by Allan.Bentham

	Fix crash when using consolas font on android sdk 24
	#jira UE-43464

Change 3379097 on 2017/04/04 by Nick.Shin

	CIS HTML5 build warning fix

	#jria none

	#rnx

Change 3379333 on 2017/04/04 by Chris.Babcock

	Prevent inserting extra permissions into manifest multiple times
	#jira UE-43583
	#ue4
	#android

Change 3380870 on 2017/04/05 by Chris.Babcock

	Fix merge issue

Change 3380898 on 2017/04/05 by Chris.Babcock

	Fixed again

Change 3381443 on 2017/04/05 by Chris.Babcock

	Fix for GearVR non-unity build
	#ue4
	#android

Change 3381941 on 2017/04/05 by Chris.Babcock

	Fix HTTPChunkInstaller texture format checks and missing #define warning
	#jira UE-43706
	#ue4
	#android

Change 3382056 on 2017/04/05 by Chris.Babcock

	Updates to Android AARs needed for Facebook plugin

Change 3382097 on 2017/04/05 by Chris.Babcock

	Disable java console cmd receiver only in shipping builds
	#jira UE-43710
	#ue4
	#android

Change 3382497 on 2017/04/06 by Allan.Bentham

	Fix Fortnite Cooked Server crashes when joining game from lobby.
	#jira UE-43695

Change 3383227 on 2017/04/06 by Will.Fissler

	Reverted case sensitive change, from yesterday, and implemented a pragma instead.

	#jira UE-41313

[CL 3383473 by Jack Porter in Main branch]
2017-04-06 16:13:17 -04:00

1441 lines
53 KiB
C#

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Win32;
namespace UnrealBuildTool
{
class AndroidToolChain : UEToolChain, IAndroidToolChain
{
private FileReference ProjectFile;
private bool bUseLdGold;
private IReadOnlyList<string> AdditionalArches;
private IReadOnlyList<string> AdditionalGPUArches;
// the number of the clang version being used to compile
private float ClangVersionFloat = 0;
// the list of architectures we will compile for
private List<string> Arches = null;
// the list of GPU architectures we will compile for
private List<string> GPUArchitectures = null;
// a list of all architecture+GPUArchitecture names (-armv7-es2, etc)
private List<string> AllComboNames = null;
static private Dictionary<string, string[]> AllArchNames = new Dictionary<string, string[]> {
{ "-armv7", new string[] { "armv7", "armeabi-v7a", } },
{ "-arm64", new string[] { "arm64", "arm64-v8a", } },
{ "-x86", new string[] { "x86", } },
{ "-x64", new string[] { "x64", "x86_64", } },
};
static private Dictionary<string, string[]> LibrariesToSkip = new Dictionary<string, string[]> {
{ "-armv7", new string[] { } },
{ "-arm64", new string[] { "nvToolsExt", "nvToolsExtStub", "oculus", "vrapi", "ovrkernel", "systemutils", "openglloader", } },
{ "-x86", new string[] { "nvToolsExt", "nvToolsExtStub", "oculus", "vrapi", "ovrkernel", "systemutils", "openglloader", "opus", "speex_resampler", } },
{ "-x64", new string[] { "nvToolsExt", "nvToolsExtStub", "oculus", "vrapi", "ovrkernel", "systemutils", "openglloader", "gpg", } },
};
static private Dictionary<string, string[]> ModulesToSkip = new Dictionary<string, string[]> {
{ "-armv7", new string[] { } },
{ "-arm64", new string[] { } },
{ "-x86", new string[] { } },
{ "-x64", new string[] { "OnlineSubsystemGooglePlay", } },
};
public AndroidToolChain(FileReference InProjectFile, bool bInUseLdGold, IReadOnlyList<string> InAdditionalArches, IReadOnlyList<string> InAdditionalGPUArches)
: base(CppPlatform.Android)
{
ProjectFile = InProjectFile;
bUseLdGold = bInUseLdGold;
AdditionalArches = InAdditionalArches;
AdditionalGPUArches = InAdditionalGPUArches;
string NDKPath = Environment.GetEnvironmentVariable("NDKROOT");
// don't register if we don't have an NDKROOT specified
if (String.IsNullOrEmpty(NDKPath))
{
throw new BuildException("NDKROOT is not specified; cannot use Android toolchain.");
}
NDKPath = NDKPath.Replace("\"", "");
string ClangVersion = "";
string GccVersion = "";
string ArchitecturePath = "";
string ArchitecturePathWindows32 = @"prebuilt/windows";
string ArchitecturePathWindows64 = @"prebuilt/windows-x86_64";
string ArchitecturePathMac = @"prebuilt/darwin-x86_64";
string ArchitecturePathLinux = @"prebuilt/linux-x86_64";
string ExeExtension = ".exe";
if (Directory.Exists(Path.Combine(NDKPath, ArchitecturePathWindows64)))
{
Log.TraceVerbose(" Found Windows 64 bit versions of toolchain");
ArchitecturePath = ArchitecturePathWindows64;
}
else if (Directory.Exists(Path.Combine(NDKPath, ArchitecturePathWindows32)))
{
Log.TraceVerbose(" Found Windows 32 bit versions of toolchain");
ArchitecturePath = ArchitecturePathWindows32;
}
else if (Directory.Exists(Path.Combine(NDKPath, ArchitecturePathMac)))
{
Log.TraceVerbose(" Found Mac versions of toolchain");
ArchitecturePath = ArchitecturePathMac;
ExeExtension = "";
}
else if (Directory.Exists(Path.Combine(NDKPath, ArchitecturePathLinux)))
{
Log.TraceVerbose(" Found Linux versions of toolchain");
ArchitecturePath = ArchitecturePathLinux;
ExeExtension = "";
}
else
{
throw new BuildException("Couldn't find 32-bit or 64-bit versions of the Android toolchain");
}
// prefer clang 3.6, but fall back if needed for now
if (Directory.Exists(Path.Combine(NDKPath, @"toolchains/llvm-3.6")))
{
ClangVersionFloat = 3.6f;
ClangVersion = "-3.6";
GccVersion = "4.9";
}
else if (Directory.Exists(Path.Combine(NDKPath, @"toolchains/llvm-3.5")))
{
ClangVersionFloat = 3.5f;
ClangVersion = "-3.5";
GccVersion = "4.9";
}
else if (Directory.Exists(Path.Combine(NDKPath, @"toolchains/llvm-3.3")))
{
ClangVersionFloat = 3.3f;
ClangVersion = "-3.3";
GccVersion = "4.8";
}
else if (Directory.Exists(Path.Combine(NDKPath, @"toolchains/llvm-3.1")))
{
ClangVersionFloat = 3.1f;
ClangVersion = "-3.1";
GccVersion = "4.6";
}
else if (Directory.Exists(Path.Combine(NDKPath, @"toolchains/llvm")))
{
// look for version in AndroidVersion.txt (fail if not found)
string VersionFilename = Path.Combine(NDKPath, @"toolchains/llvm/", ArchitecturePath, @"AndroidVersion.txt");
if (!File.Exists(VersionFilename))
{
throw new BuildException("Cannot find supported Android toolchain");
}
string[] VersionFile = File.ReadAllLines(VersionFilename);
string[] VersionParts = VersionFile[0].Split('.');
ClangVersionFloat = float.Parse(VersionParts[0] + "." + VersionParts[1], System.Globalization.CultureInfo.InvariantCulture);
ClangVersion = "";
GccVersion = "4.9";
}
else
{
throw new BuildException("Cannot find supported Android toolchain");
}
// set up the path to our toolchains
ClangPath = Path.Combine(NDKPath, @"toolchains/llvm" + ClangVersion, ArchitecturePath, @"bin/clang++" + ExeExtension);
ArPathArm = Path.Combine(NDKPath, @"toolchains/arm-linux-androideabi-" + GccVersion, ArchitecturePath, @"bin/arm-linux-androideabi-ar" + ExeExtension); //@todo android: use llvm-ar.exe instead?
ArPathArm64 = Path.Combine(NDKPath, @"toolchains/aarch64-linux-android-" + GccVersion, ArchitecturePath, @"bin/aarch64-linux-android-ar" + ExeExtension); //@todo android: use llvm-ar.exe instead?
ArPathx86 = Path.Combine(NDKPath, @"toolchains/x86-" + GccVersion, ArchitecturePath, @"bin/i686-linux-android-ar" + ExeExtension); //@todo android: verify x86 toolchain
ArPathx64 = Path.Combine(NDKPath, @"toolchains/x86_64-" + GccVersion, ArchitecturePath, @"bin/x86_64-linux-android-ar" + ExeExtension); //@todo android: verify x64 toolchain
// NDK setup (use no less than 21 for 64-bit targets)
int NDKApiLevelInt = GetNdkApiLevelInt();
string NDKApiLevel32Bit = GetNdkApiLevel();
string NDKApiLevel64Bit = NDKApiLevel32Bit;
if (NDKApiLevelInt < 21)
{
NDKApiLevel64Bit = "android-21";
}
// toolchain params
ToolchainParamsArm = " -target armv7-none-linux-androideabi" +
" --sysroot=\"" + Path.Combine(NDKPath, "platforms", NDKApiLevel32Bit, "arch-arm") + "\"" +
" -gcc-toolchain \"" + Path.Combine(NDKPath, @"toolchains/arm-linux-androideabi-" + GccVersion, ArchitecturePath) + "\"";
ToolchainParamsArm64 = " -target aarch64-none-linux-android" +
" --sysroot=\"" + Path.Combine(NDKPath, "platforms", NDKApiLevel64Bit, "arch-arm64") + "\"" +
" -gcc-toolchain \"" + Path.Combine(NDKPath, @"toolchains/aarch64-linux-android-" + GccVersion, ArchitecturePath) + "\"";
ToolchainParamsx86 = " -target i686-none-linux-android" +
" --sysroot=\"" + Path.Combine(NDKPath, "platforms", NDKApiLevel32Bit, "arch-x86") + "\"" +
" -gcc-toolchain \"" + Path.Combine(NDKPath, @"toolchains/x86-" + GccVersion, ArchitecturePath) + "\"";
ToolchainParamsx64 = " -target x86_64-none-linux-android" +
" --sysroot=\"" + Path.Combine(NDKPath, "platforms", NDKApiLevel64Bit, "arch-x86_64") + "\"" +
" -gcc-toolchain \"" + Path.Combine(NDKPath, @"toolchains\x86_64-" + GccVersion, ArchitecturePath) + "\"";
}
public void ParseArchitectures()
{
// look in ini settings for what platforms to compile for
ConfigHierarchy Ini = ConfigCache.ReadHierarchy(ConfigHierarchyType.Engine, DirectoryReference.FromFile(ProjectFile), UnrealTargetPlatform.Android);
Arches = new List<string>();
bool bBuild = true;
if (Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bBuildForArmV7", out bBuild) && bBuild
|| (AdditionalArches != null && AdditionalArches.Contains("armv7", StringComparer.OrdinalIgnoreCase)))
{
Arches.Add("-armv7");
}
if (Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bBuildForArm64", out bBuild) && bBuild
|| (AdditionalArches != null && AdditionalArches.Contains("arm64", StringComparer.OrdinalIgnoreCase)))
{
Arches.Add("-arm64");
}
if (Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bBuildForx86", out bBuild) && bBuild
|| (AdditionalArches != null && AdditionalArches.Contains("x86", StringComparer.OrdinalIgnoreCase)))
{
Arches.Add("-x86");
}
if (Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bBuildForx8664", out bBuild) && bBuild
|| (AdditionalArches != null && AdditionalArches.Contains("x64", StringComparer.OrdinalIgnoreCase)))
{
Arches.Add("-x64");
}
// force armv7 if something went wrong
if (Arches.Count == 0)
{
Arches.Add("-armv7");
}
// Parse selected GPU architectures
GPUArchitectures = new List<string>();
if (Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bBuildForES2", out bBuild) && bBuild
|| (AdditionalGPUArches != null && AdditionalGPUArches.Contains("es2", StringComparer.OrdinalIgnoreCase)))
{
GPUArchitectures.Add("-es2");
}
if (Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bBuildForESDeferred", out bBuild) && bBuild
|| (AdditionalGPUArches != null && AdditionalGPUArches.Contains("esdeferred", StringComparer.OrdinalIgnoreCase)))
{
GPUArchitectures.Add("-esdeferred");
}
if (GPUArchitectures.Count == 0)
{
GPUArchitectures.Add("-es2");
}
AllComboNames = (from Arch in Arches
from GPUArch in GPUArchitectures
select Arch + GPUArch).ToList();
}
static public string GetGLESVersionFromGPUArch(string GPUArch, bool bES30Minimum)
{
GPUArch = GPUArch.Substring(1); // drop the '-' from the start
string GLESversion = "";
switch (GPUArch)
{
case "es2":
GLESversion = "0x00020000";
break;
case "esdeferred":
GLESversion = "0x00030001";
break;
default:
GLESversion = "0x00020000";
break;
}
if (bES30Minimum && (GLESversion[6] < '3'))
{
GLESversion = "0x00030000";
}
return GLESversion;
}
private bool BuildWithHiddenSymbolVisibility(CppCompileEnvironment CompileEnvironment)
{
ConfigHierarchy Ini = ConfigCache.ReadHierarchy(ConfigHierarchyType.Engine, DirectoryReference.FromFile(ProjectFile), UnrealTargetPlatform.Android);
bool bBuild = false;
return CompileEnvironment.Configuration == CppConfiguration.Shipping && (Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bBuildWithHiddenSymbolVisibility", out bBuild) && bBuild);
}
public override void SetUpGlobalEnvironment(ReadOnlyTargetRules Target)
{
base.SetUpGlobalEnvironment(Target);
ParseArchitectures();
}
public List<string> GetAllArchitectures()
{
if (Arches == null)
{
ParseArchitectures();
}
return Arches;
}
public List<string> GetAllGPUArchitectures()
{
if (GPUArchitectures == null)
{
ParseArchitectures();
}
return GPUArchitectures;
}
public int GetNdkApiLevelInt(int MinNdk = 19)
{
string NDKVersion = GetNdkApiLevel();
int NDKVersionInt = MinNdk;
if (NDKVersion.Contains("-"))
{
int Version;
if (int.TryParse(NDKVersion.Substring(NDKVersion.LastIndexOf('-') + 1), out Version))
{
if (Version > NDKVersionInt)
NDKVersionInt = Version;
}
}
return NDKVersionInt;
}
public string GetNdkApiLevel()
{
// ask the .ini system for what version to use
ConfigHierarchy Ini = ConfigCache.ReadHierarchy(ConfigHierarchyType.Engine, DirectoryReference.FromFile(ProjectFile), UnrealTargetPlatform.Android);
string NDKLevel;
Ini.GetString("/Script/AndroidPlatformEditor.AndroidSDKSettings", "NDKAPILevel", out NDKLevel);
if (NDKLevel == "latest")
{
// get a list of NDK platforms
string PlatformsDir = Environment.ExpandEnvironmentVariables("%NDKROOT%/platforms");
if (!Directory.Exists(PlatformsDir))
{
throw new BuildException("No platforms found in {0}", PlatformsDir);
}
// return the largest of them
NDKLevel = GetLargestApiLevel(Directory.GetDirectories(PlatformsDir));
}
return NDKLevel;
}
public string GetLargestApiLevel(string[] ApiLevels)
{
int LargestLevel = 0;
string LargestString = null;
// look for largest integer
foreach (string Level in ApiLevels)
{
string LocalLevel = Path.GetFileName(Level);
string[] Tokens = LocalLevel.Split("-".ToCharArray());
if (Tokens.Length >= 2)
{
try
{
int ParsedLevel = int.Parse(Tokens[1]);
// bigger? remember it
if (ParsedLevel > LargestLevel)
{
LargestLevel = ParsedLevel;
LargestString = LocalLevel;
}
}
catch (Exception)
{
// ignore poorly formed string
}
}
}
return LargestString;
}
string GetCLArguments_Global(CppCompileEnvironment CompileEnvironment, string Architecture)
{
string Result = "";
switch (Architecture)
{
case "-armv7": Result += ToolchainParamsArm; break;
case "-arm64": Result += ToolchainParamsArm64; break;
case "-x86": Result += ToolchainParamsx86; break;
case "-x64": Result += ToolchainParamsx64; break;
default: Result += ToolchainParamsArm; break;
}
// build up the commandline common to C and C++
Result += " -c";
Result += " -fdiagnostics-format=msvc";
Result += " -Wall";
Result += " -Wno-unused-variable";
// this will hide the warnings about static functions in headers that aren't used in every single .cpp file
Result += " -Wno-unused-function";
// this hides the "enumeration value 'XXXXX' not handled in switch [-Wswitch]" warnings - we should maybe remove this at some point and add UE_LOG(, Fatal, ) to default cases
Result += " -Wno-switch";
// this hides the "warning : comparison of unsigned expression < 0 is always false" type warnings due to constant comparisons, which are possible with template arguments
Result += " -Wno-tautological-compare";
//This will prevent the issue of warnings for unused private variables.
Result += " -Wno-unused-private-field";
Result += " -Wno-local-type-template-args"; // engine triggers this
Result += " -Wno-return-type-c-linkage"; // needed for PhysX
Result += " -Wno-reorder"; // member initialization order
Result += " -Wno-unknown-pragmas"; // probably should kill this one, sign of another issue in PhysX?
Result += " -Wno-invalid-offsetof"; // needed to suppress warnings about using offsetof on non-POD types.
Result += " -Wno-logical-op-parentheses"; // needed for external headers we can't change
if (BuildWithHiddenSymbolVisibility(CompileEnvironment))
{
Result += " -fvisibility=hidden -fvisibility-inlines-hidden"; // Symbols default to hidden.
}
if (CompileEnvironment.bEnableShadowVariableWarnings)
{
Result += " -Wshadow -Wno-error=shadow";
}
if (CompileEnvironment.bEnableUndefinedIdentifierWarnings)
{
Result += " -Wundef" + (CompileEnvironment.bUndefinedIdentifierWarningsAsErrors ? "" : " -Wno-error=undef");
}
// new for clang4.5 warnings:
if (ClangVersionFloat >= 3.5f)
{
Result += " -Wno-undefined-bool-conversion"; // 'this' pointer cannot be null in well-defined C++ code; pointer may be assumed to always convert to true (if (this))
// we use this feature to allow static FNames.
Result += " -Wno-gnu-string-literal-operator-template";
}
if (ClangVersionFloat >= 3.6f)
{
Result += " -Wno-unused-local-typedef"; // clang is being overly strict here? PhysX headers trigger this.
Result += " -Wno-inconsistent-missing-override"; // these have to be suppressed for UE 4.8, should be fixed later.
}
// shipping builds will cause this warning with "ensure", so disable only in those case
if (CompileEnvironment.Configuration == CppConfiguration.Shipping)
{
Result += " -Wno-unused-value";
}
// debug info
if (CompileEnvironment.bCreateDebugInfo)
{
Result += " -g2 -gdwarf-4";
}
// optimization level
if (!CompileEnvironment.bOptimizeCode)
{
Result += " -O0";
}
else
{
if (CompileEnvironment.bOptimizeForSize)
{
Result += " -Oz";
}
else
{
Result += " -O3";
}
}
// Optionally enable exception handling (off by default since it generates extra code needed to propagate exceptions)
if (CompileEnvironment.bEnableExceptions)
{
Result += " -fexceptions";
}
else
{
Result += " -fno-exceptions";
}
// Conditionally enable (default disabled) generation of information about every class with virtual functions for use by the C++ runtime type identification features
// (`dynamic_cast' and `typeid'). If you don't use those parts of the language, you can save some space by using -fno-rtti.
// Note that exception handling uses the same information, but it will generate it as needed.
if (CompileEnvironment.bUseRTTI)
{
Result += " -frtti";
}
else
{
Result += " -fno-rtti";
}
//@todo android: these are copied verbatim from UE3 and probably need adjustment
if (Architecture == "-armv7")
{
// Result += " -mthumb-interwork"; // Generates code which supports calling between ARM and Thumb instructions, w/o it you can't reliability use both together
Result += " -funwind-tables"; // Just generates any needed static data, affects no code
Result += " -fstack-protector"; // Emits extra code to check for buffer overflows
// Result += " -mlong-calls"; // Perform function calls by first loading the address of the function into a reg and then performing the subroutine call
Result += " -fno-strict-aliasing"; // Prevents unwanted or invalid optimizations that could produce incorrect code
Result += " -fpic"; // Generates position-independent code (PIC) suitable for use in a shared library
Result += " -fno-short-enums"; // Do not allocate to an enum type only as many bytes as it needs for the declared range of possible values
// Result += " -finline-limit=64"; // GCC limits the size of functions that can be inlined, this flag allows coarse control of this limit
// Result += " -Wno-psabi"; // Warn when G++ generates code that is probably not compatible with the vendor-neutral C++ ABI
Result += " -march=armv7-a";
Result += " -mfloat-abi=softfp";
Result += " -mfpu=vfpv3-d16"; //@todo android: UE3 was just vfp. arm7a should all support v3 with 16 registers
// Add flags for on-device debugging
if (CompileEnvironment.Configuration == CppConfiguration.Debug)
{
Result += " -fno-omit-frame-pointer"; // Disable removing the save/restore frame pointer for better debugging
if (ClangVersionFloat >= 3.6f)
{
Result += " -fno-function-sections"; // Improve breakpoint location
}
}
// Some switches interfere with on-device debugging
if (CompileEnvironment.Configuration != CppConfiguration.Debug)
{
Result += " -ffunction-sections"; // Places each function in its own section of the output file, linker may be able to perform opts to improve locality of reference
Result += " -fdata-sections"; // Places each data item in its own section of the output file, linker may be able to perform opts to improve locality of reference
}
Result += " -fsigned-char"; // Treat chars as signed //@todo android: any concerns about ABI compatibility with libs here?
}
else if (Architecture == "-arm64")
{
Result += " -funwind-tables"; // Just generates any needed static data, affects no code
Result += " -fstack-protector"; // Emits extra code to check for buffer overflows
Result += " -fno-strict-aliasing"; // Prevents unwanted or invalid optimizations that could produce incorrect code
Result += " -fpic"; // Generates position-independent code (PIC) suitable for use in a shared library
Result += " -fno-short-enums"; // Do not allocate to an enum type only as many bytes as it needs for the declared range of possible values
Result += " -D__arm64__"; // for some reason this isn't defined and needed for PhysX
Result += " -march=armv8-a";
//Result += " -mfloat-abi=softfp";
//Result += " -mfpu=vfpv3-d16"; //@todo android: UE3 was just vfp. arm7a should all support v3 with 16 registers
// Some switches interfere with on-device debugging
if (CompileEnvironment.Configuration != CppConfiguration.Debug)
{
Result += " -ffunction-sections"; // Places each function in its own section of the output file, linker may be able to perform opts to improve locality of reference
}
Result += " -fsigned-char"; // Treat chars as signed //@todo android: any concerns about ABI compatibility with libs here?
}
else if (Architecture == "-x86")
{
Result += " -fstrict-aliasing";
Result += " -fno-omit-frame-pointer";
Result += " -fno-strict-aliasing";
Result += " -fno-short-enums";
Result += " -march=atom";
}
else if (Architecture == "-x64")
{
Result += " -fstrict-aliasing";
Result += " -fno-omit-frame-pointer";
Result += " -fno-strict-aliasing";
Result += " -fno-short-enums";
Result += " -march=atom";
}
return Result;
}
static string GetCompileArguments_CPP(bool bDisableOptimizations)
{
string Result = "";
Result += " -x c++";
Result += " -std=c++14";
// optimization level
if (bDisableOptimizations)
{
Result += " -O0";
}
else
{
Result += " -O3";
}
return Result;
}
static string GetCompileArguments_C(bool bDisableOptimizations)
{
string Result = "";
Result += " -x c";
// optimization level
if (bDisableOptimizations)
{
Result += " -O0";
}
else
{
Result += " -O3";
}
return Result;
}
static string GetCompileArguments_PCH(bool bDisableOptimizations)
{
string Result = "";
Result += " -x c++-header";
Result += " -std=c++14";
// optimization level
if (bDisableOptimizations)
{
Result += " -O0";
}
else
{
Result += " -O3";
}
return Result;
}
string GetLinkArguments(LinkEnvironment LinkEnvironment, string Architecture)
{
string Result = "";
Result += " -nostdlib";
Result += " -Wl,-shared,-Bsymbolic";
Result += " -Wl,--no-undefined";
Result += " -Wl,-gc-sections"; // Enable garbage collection of unused input sections. works best with -ffunction-sections, -fdata-sections
if (Architecture == "-arm64")
{
Result += ToolchainParamsArm64;
Result += " -march=armv8-a";
}
else if (Architecture == "-x86")
{
Result += ToolchainParamsx86;
Result += " -march=atom";
}
else if (Architecture == "-x64")
{
Result += ToolchainParamsx64;
Result += " -march=atom";
}
else // if (Architecture == "-armv7")
{
Result += ToolchainParamsArm;
Result += " -march=armv7-a";
Result += " -Wl,--fix-cortex-a8"; // required to route around a CPU bug in some Cortex-A8 implementations
}
if (bUseLdGold && ClangVersionFloat >= 3.6f && ClangVersionFloat < 3.8f)
{
Result += " -fuse-ld=gold"; // ld.gold is available in r10e (clang 3.6)
}
// make sure the DT_SONAME field is set properly (or we can a warning toast at startup on new Android)
Result += " -Wl,-soname,libUE4.so";
// verbose output from the linker
// Result += " -v";
return Result;
}
static string GetArArguments(LinkEnvironment LinkEnvironment)
{
string Result = "";
Result += " -r";
return Result;
}
static bool IsDirectoryForArch(string Dir, string Arch)
{
// make sure paths use one particular slash
Dir = Dir.Replace("\\", "/").ToLowerInvariant();
// look for other architectures in the Dir path, and fail if it finds it
foreach (var Pair in AllArchNames)
{
if (Pair.Key != Arch)
{
foreach (var ArchName in Pair.Value)
{
// if there's a directory in the path with a bad architecture name, reject it
if (Regex.IsMatch(Dir, "/" + ArchName + "$") || Regex.IsMatch(Dir, "/" + ArchName + "/"))
{
return false;
}
}
}
}
// if nothing was found, we are okay
return true;
}
static bool ShouldSkipModule(string ModuleName, string Arch)
{
foreach (var ModName in ModulesToSkip[Arch])
{
if (ModName == ModuleName)
{
return true;
}
}
// if nothing was found, we are okay
return false;
}
bool ShouldSkipLib(string Lib, string Arch, string GPUArchitecture)
{
// reject any libs we outright don't want to link with
foreach (var LibName in LibrariesToSkip[Arch])
{
if (LibName == Lib)
{
return true;
}
}
// if another architecture is in the filename, reject it
foreach (string ComboName in AllComboNames)
{
if (ComboName != Arch + GPUArchitecture)
{
if (Path.GetFileNameWithoutExtension(Lib).EndsWith(ComboName))
{
return true;
}
}
}
// if nothing was found, we are okay
return false;
}
static private string GetNativeGluePath()
{
return Environment.GetEnvironmentVariable("NDKROOT") + "/sources/android/native_app_glue/android_native_app_glue.c";
}
static void ConditionallyAddNDKSourceFiles(List<FileItem> SourceFiles, string ModuleName)
{
// We need to add the extra glue and cpu code only to Launch module.
if (ModuleName.Equals("Launch"))
{
SourceFiles.Add(FileItem.GetItemByPath( GetNativeGluePath() ));
// Newer NDK cpu_features.c uses getauxval() which causes a SIGSEGV in libhoudini.so (ARM on Intel translator) in older versions of Houdini
// so we patch the file to use alternative methods of detecting CPU features if libhoudini.so is detected
// The basis for this patch is from here: https://android-review.googlesource.com/#/c/110650/
string CpuFeaturesPath = Environment.GetEnvironmentVariable("NDKROOT") + "/sources/android/cpufeatures/";
string CpuFeaturesPatchedFile = CpuFeaturesPath + "cpu-features-patched.c";
if (!File.Exists(CpuFeaturesPatchedFile))
{
// Either make a copy or patch it
string[] CpuFeaturesLines = File.ReadAllLines(CpuFeaturesPath + "cpu-features.c");
// Look for get_elf_hwcap_from_getauxval in the file
bool NeedsPatch = false;
int LineIndex;
for (LineIndex = 0; LineIndex < CpuFeaturesLines.Length; ++LineIndex)
{
if (CpuFeaturesLines[LineIndex].Contains("get_elf_hwcap_from_getauxval"))
{
NeedsPatch = true;
// Make sure it doesn't already have the patch (r10c and 10d have it already, but removed in 10e)
for (int LineIndex2 = LineIndex; LineIndex2 < CpuFeaturesLines.Length; ++LineIndex2)
{
if (CpuFeaturesLines[LineIndex2].Contains("has_houdini_binary_translator(void)"))
{
NeedsPatch = false;
break;
}
}
break;
}
}
// Apply patch or write unchanged
if (NeedsPatch)
{
List<string> CpuFeaturesList = new List<string>(CpuFeaturesLines);
// Skip down to section to add Houdini check function for arm
while (!CpuFeaturesList[++LineIndex].StartsWith("#if defined(__arm__)")) ;
CpuFeaturesList.Insert(++LineIndex, "/* Check Houdini Binary Translator is installed on the system.");
CpuFeaturesList.Insert(++LineIndex, " *");
CpuFeaturesList.Insert(++LineIndex, " * If this function returns 1, get_elf_hwcap_from_getauxval() function");
CpuFeaturesList.Insert(++LineIndex, " * will causes SIGSEGV while calling getauxval() function.");
CpuFeaturesList.Insert(++LineIndex, " */");
CpuFeaturesList.Insert(++LineIndex, "static int");
CpuFeaturesList.Insert(++LineIndex, "has_houdini_binary_translator(void) {");
CpuFeaturesList.Insert(++LineIndex, " int found = 0;");
CpuFeaturesList.Insert(++LineIndex, " if (access(\"/system/lib/libhoudini.so\", F_OK) != -1) {");
CpuFeaturesList.Insert(++LineIndex, " D(\"Found Houdini binary translator\\n\");");
CpuFeaturesList.Insert(++LineIndex, " found = 1;");
CpuFeaturesList.Insert(++LineIndex, " }");
CpuFeaturesList.Insert(++LineIndex, " return found;");
CpuFeaturesList.Insert(++LineIndex, "}");
CpuFeaturesList.Insert(++LineIndex, "");
// Add the Houdini check call
while (!CpuFeaturesList[++LineIndex].Contains("/* Extract the list of CPU features from ELF hwcaps */")) ;
CpuFeaturesList.Insert(LineIndex++, " /* Check Houdini binary translator is installed */");
CpuFeaturesList.Insert(LineIndex++, " int has_houdini = has_houdini_binary_translator();");
CpuFeaturesList.Insert(LineIndex++, "");
// Make the get_elf_hwcap_from_getauxval() calls conditional
while (!CpuFeaturesList[++LineIndex].Contains("hwcaps = get_elf_hwcap_from_getauxval(AT_HWCAP);")) ;
CpuFeaturesList.Insert(LineIndex++, " if (!has_houdini) {");
CpuFeaturesList.Insert(++LineIndex, " }");
while (!CpuFeaturesList[++LineIndex].Contains("hwcaps2 = get_elf_hwcap_from_getauxval(AT_HWCAP2);")) ;
CpuFeaturesList.Insert(LineIndex++, " if (!has_houdini) {");
CpuFeaturesList.Insert(++LineIndex, " }");
File.WriteAllLines(CpuFeaturesPatchedFile, CpuFeaturesList.ToArray());
}
else
{
File.WriteAllLines(CpuFeaturesPatchedFile, CpuFeaturesLines);
}
}
SourceFiles.Add(FileItem.GetItemByPath(CpuFeaturesPatchedFile));
}
}
void GenerateEmptyLinkFunctionsForRemovedModules(List<FileItem> SourceFiles, string ModuleName, DirectoryReference OutputDirectory)
{
// Only add to UELinkerFixups module
if (!ModuleName.Equals("Launch"))
{
return;
}
string LinkerExceptionsName = "../UELinkerExceptions";
FileReference LinkerExceptionsCPPFilename = FileReference.Combine(OutputDirectory, LinkerExceptionsName + ".cpp");
// Create the cpp filename
if (!FileReference.Exists(LinkerExceptionsCPPFilename))
{
// Create a dummy file in case it doesn't exist yet so that the module does not complain it's not there
ResponseFile.Create(LinkerExceptionsCPPFilename, new List<string>());
}
var Result = new List<string>();
Result.Add("#include \"CoreTypes.h\"");
Result.Add("");
foreach (string Arch in Arches)
{
switch (Arch)
{
case "-armv7": Result.Add("#if PLATFORM_ANDROID_ARM"); break;
case "-arm64": Result.Add("#if PLATFORM_ANDROID_ARM64"); break;
case "-x86": Result.Add("#if PLATFORM_ANDROID_X86"); break;
case "-x64": Result.Add("#if PLATFORM_ANDROID_X64"); break;
default: Result.Add("#if PLATFORM_ANDROID_ARM"); break;
}
foreach (var ModName in ModulesToSkip[Arch])
{
Result.Add(" void EmptyLinkFunctionForStaticInitialization" + ModName + "(){}");
}
Result.Add("#endif");
}
// Determine if the file changed. Write it if it either doesn't exist or the contents are different.
bool bShouldWriteFile = true;
if (FileReference.Exists(LinkerExceptionsCPPFilename))
{
string[] ExistingExceptionText = File.ReadAllLines(LinkerExceptionsCPPFilename.FullName);
string JoinedNewContents = string.Join("", Result.ToArray());
string JoinedOldContents = string.Join("", ExistingExceptionText);
bShouldWriteFile = (JoinedNewContents != JoinedOldContents);
}
// If we determined that we should write the file, write it now.
if (bShouldWriteFile)
{
ResponseFile.Create(LinkerExceptionsCPPFilename, Result);
}
SourceFiles.Add(FileItem.GetItemByFileReference(LinkerExceptionsCPPFilename));
}
// cache the location of NDK tools
static string ClangPath;
static string ToolchainParamsArm;
static string ToolchainParamsArm64;
static string ToolchainParamsx86;
static string ToolchainParamsx64;
static string ArPathArm;
static string ArPathArm64;
static string ArPathx86;
static string ArPathx64;
static public string GetStripExecutablePath(string UE4Arch)
{
string StripPath;
switch (UE4Arch)
{
case "-armv7": StripPath = ArPathArm; break;
case "-arm64": StripPath = ArPathArm64; break;
case "-x86": StripPath = ArPathx86; break;
case "-x64": StripPath = ArPathx64; break;
default: StripPath = ArPathArm; break;
}
return StripPath.Replace("-ar", "-strip");
}
static private bool bHasPrintedApiLevel = false;
public override CPPOutput CompileCPPFiles(CppCompileEnvironment CompileEnvironment, List<FileItem> SourceFiles, string ModuleName, ActionGraph ActionGraph)
{
if (Arches.Count == 0)
{
throw new BuildException("At least one architecture (armv7, x86, etc) needs to be selected in the project settings to build");
}
if (!bHasPrintedApiLevel)
{
Console.WriteLine("Compiling Native code with NDK API '{0}'", GetNdkApiLevel());
bHasPrintedApiLevel = true;
}
string BaseArguments = "";
if (CompileEnvironment.PrecompiledHeaderAction != PrecompiledHeaderAction.Create)
{
BaseArguments += " -Werror";
}
// Directly added NDK files for NDK extensions
ConditionallyAddNDKSourceFiles(SourceFiles, ModuleName);
string NativeGluePath = Path.GetFullPath(GetNativeGluePath());
// Deal with dynamic modules removed by architecture
GenerateEmptyLinkFunctionsForRemovedModules(SourceFiles, ModuleName, CompileEnvironment.OutputDirectory);
// Add preprocessor definitions to the argument list.
foreach (string Definition in CompileEnvironment.Definitions)
{
BaseArguments += string.Format(" -D \"{0}\"", Definition);
}
var NDKRoot = Environment.GetEnvironmentVariable("NDKROOT").Replace("\\", "/");
string BasePCHName = "";
var PCHExtension = UEBuildPlatform.GetBuildPlatform(UnrealTargetPlatform.Android).GetBinaryExtension(UEBuildBinaryType.PrecompiledHeader);
if (CompileEnvironment.PrecompiledHeaderAction == PrecompiledHeaderAction.Include)
{
BasePCHName = RemoveArchName(CompileEnvironment.PrecompiledHeaderFile.AbsolutePath).Replace(PCHExtension, "");
}
// Create a compile action for each source file.
CPPOutput Result = new CPPOutput();
foreach (string Arch in Arches)
{
if (ShouldSkipModule(ModuleName, Arch))
{
continue;
}
foreach (string GPUArchitecture in GPUArchitectures)
{
// which toolchain to use
string Arguments = GetCLArguments_Global(CompileEnvironment, Arch) + BaseArguments;
switch (Arch)
{
case "-armv7": Arguments += " -DPLATFORM_64BITS=0 -DPLATFORM_ANDROID_ARM=1"; break;
case "-arm64": Arguments += " -DPLATFORM_64BITS=1 -DPLATFORM_ANDROID_ARM64=1"; break;
case "-x86": Arguments += " -DPLATFORM_64BITS=0 -DPLATFORM_ANDROID_X86=1"; break;
case "-x64": Arguments += " -DPLATFORM_64BITS=1 -DPLATFORM_ANDROID_X64=1"; break;
default: Arguments += " -DPLATFORM_64BITS=0 -DPLATFORM_ANDROID_ARM=1"; break;
}
if (GPUArchitecture == "-esdeferred")
{
Arguments += " -DPLATFORM_ANDROIDESDEFERRED=1";
}
// which PCH file to include
string PCHArguments = "";
if (CompileEnvironment.PrecompiledHeaderAction == PrecompiledHeaderAction.Include)
{
// Add the precompiled header file's path to the include path so Clang can find it.
// This needs to be before the other include paths to ensure Clang uses it instead of the source header file.
PCHArguments += string.Format(" -include \"{0}\"", InlineArchName(BasePCHName, Arch, GPUArchitecture));
}
foreach(FileReference ForceIncludeFile in CompileEnvironment.ForceIncludeFiles)
{
PCHArguments += string.Format(" -include \"{0}\"", ForceIncludeFile.FullName);
}
// Add include paths to the argument list (filtered by architecture)
foreach (string IncludePath in CompileEnvironment.IncludePaths.SystemIncludePaths)
{
if (IsDirectoryForArch(IncludePath, Arch))
{
Arguments += string.Format(" -I\"{0}\"", IncludePath);
}
}
foreach (string IncludePath in CompileEnvironment.IncludePaths.UserIncludePaths)
{
if (IsDirectoryForArch(IncludePath, Arch))
{
Arguments += string.Format(" -I\"{0}\"", IncludePath);
}
}
foreach (FileItem SourceFile in SourceFiles)
{
Action CompileAction = ActionGraph.Add(ActionType.Compile);
string FileArguments = "";
bool bIsPlainCFile = Path.GetExtension(SourceFile.AbsolutePath).ToUpperInvariant() == ".C";
bool bDisableShadowWarning = false;
// should we disable optimizations on this file?
// @todo android - We wouldn't need this if we could disable optimizations per function (via pragma)
bool bDisableOptimizations = false;// SourceFile.AbsolutePath.ToUpperInvariant().IndexOf("\\SLATE\\") != -1;
if (bDisableOptimizations && CompileEnvironment.bOptimizeCode)
{
Log.TraceWarning("Disabling optimizations on {0}", SourceFile.AbsolutePath);
}
bDisableOptimizations = bDisableOptimizations || !CompileEnvironment.bOptimizeCode;
// Add C or C++ specific compiler arguments.
if (CompileEnvironment.PrecompiledHeaderAction == PrecompiledHeaderAction.Create)
{
FileArguments += GetCompileArguments_PCH(bDisableOptimizations);
}
else if (bIsPlainCFile)
{
FileArguments += GetCompileArguments_C(bDisableOptimizations);
// remove shadow variable warnings for NDK files
if (SourceFile.AbsolutePath.Replace("\\", "/").StartsWith(NDKRoot))
{
bDisableShadowWarning = true;
}
}
else
{
FileArguments += GetCompileArguments_CPP(bDisableOptimizations);
// only use PCH for .cpp files
FileArguments += PCHArguments;
}
// Add the C++ source file and its included files to the prerequisite item list.
AddPrerequisiteSourceFile(CompileEnvironment, SourceFile, CompileAction.PrerequisiteItems);
if (CompileEnvironment.PrecompiledHeaderAction == PrecompiledHeaderAction.Create)
{
// Add the precompiled header file to the produced item list.
FileItem PrecompiledHeaderFile = FileItem.GetItemByFileReference(
FileReference.Combine(
CompileEnvironment.OutputDirectory,
Path.GetFileName(InlineArchName(SourceFile.AbsolutePath, Arch, GPUArchitecture) + PCHExtension)
)
);
CompileAction.ProducedItems.Add(PrecompiledHeaderFile);
Result.PrecompiledHeaderFile = PrecompiledHeaderFile;
// Add the parameters needed to compile the precompiled header file to the command-line.
FileArguments += string.Format(" -o \"{0}\"", PrecompiledHeaderFile.AbsolutePath);
}
else
{
if (CompileEnvironment.PrecompiledHeaderAction == PrecompiledHeaderAction.Include)
{
CompileAction.bIsUsingPCH = true;
FileItem ArchPrecompiledHeaderFile = FileItem.GetItemByPath(InlineArchName(BasePCHName, Arch, GPUArchitecture) + PCHExtension);
CompileAction.PrerequisiteItems.Add(ArchPrecompiledHeaderFile);
}
var ObjectFileExtension = UEBuildPlatform.GetBuildPlatform(UnrealTargetPlatform.Android).GetBinaryExtension(UEBuildBinaryType.Object);
// Add the object file to the produced item list.
FileItem ObjectFile = FileItem.GetItemByFileReference(
FileReference.Combine(
CompileEnvironment.OutputDirectory,
InlineArchName(Path.GetFileName(SourceFile.AbsolutePath) + ObjectFileExtension, Arch, GPUArchitecture)
)
);
CompileAction.ProducedItems.Add(ObjectFile);
Result.ObjectFiles.Add(ObjectFile);
FileArguments += string.Format(" -o \"{0}\"", ObjectFile.AbsolutePath);
}
// Add the source file path to the command-line.
FileArguments += string.Format(" \"{0}\"", SourceFile.AbsolutePath);
// Build a full argument list
string AllArguments = Arguments + FileArguments + CompileEnvironment.AdditionalArguments;
if (SourceFile.AbsolutePath.Equals(NativeGluePath))
{
// Remove visibility settings for android native glue. Since it doesn't decorate with visibility attributes.
AllArguments = AllArguments.Replace("-fvisibility=hidden -fvisibility-inlines-hidden", "");
}
AllArguments = ActionThread.ExpandEnvironmentVariables(AllArguments);
AllArguments = AllArguments.Replace("\\", "/");
// Remove shadow warning for this file if requested
if (bDisableShadowWarning)
{
int WarningIndex = AllArguments.IndexOf(" -Wshadow");
if (WarningIndex > 0)
{
AllArguments = AllArguments.Remove(WarningIndex, 9);
}
}
// Create the response file
FileReference ResponseFileName = CompileAction.ProducedItems[0].Reference + "_" + AllArguments.GetHashCode().ToString("X") + ".response";
string ResponseArgument = string.Format("@\"{0}\"", ResponseFile.Create(ResponseFileName, new List<string> { AllArguments }).FullName);
CompileAction.WorkingDirectory = UnrealBuildTool.EngineSourceDirectory.FullName;
CompileAction.CommandPath = ClangPath;
CompileAction.CommandArguments = ResponseArgument;
CompileAction.StatusDescription = string.Format("{0} [{1}-{2}]", Path.GetFileName(SourceFile.AbsolutePath), Arch.Replace("-", ""), GPUArchitecture.Replace("-", ""));
// VC++ always outputs the source file name being compiled, so we don't need to emit this ourselves
CompileAction.bShouldOutputStatusDescription = true;
// Don't farm out creation of pre-compiled headers as it is the critical path task.
CompileAction.bCanExecuteRemotely =
CompileEnvironment.PrecompiledHeaderAction != PrecompiledHeaderAction.Create ||
CompileEnvironment.bAllowRemotelyCompiledPCHs;
}
}
}
return Result;
}
public override FileItem LinkFiles(LinkEnvironment LinkEnvironment, bool bBuildImportLibraryOnly, ActionGraph ActionGraph)
{
return null;
}
static public string InlineArchName(string Pathname, string Arch, string GPUArchitecture)
{
return Path.Combine(Path.GetDirectoryName(Pathname), Path.GetFileNameWithoutExtension(Pathname) + Arch + GPUArchitecture + Path.GetExtension(Pathname));
}
public string RemoveArchName(string Pathname)
{
// remove all architecture names
foreach (string Arch in GetAllArchitectures())
{
foreach (string GPUArchitecture in GetAllGPUArchitectures())
{
Pathname = Path.Combine(Path.GetDirectoryName(Pathname), Path.GetFileName(Pathname).Replace(Arch + GPUArchitecture, ""));
}
}
return Pathname;
}
public override FileItem[] LinkAllFiles(LinkEnvironment LinkEnvironment, bool bBuildImportLibraryOnly, ActionGraph ActionGraph)
{
List<FileItem> Outputs = new List<FileItem>();
var NDKRoot = Environment.GetEnvironmentVariable("NDKROOT").Replace("\\", "/");
int NDKApiLevelInt = GetNdkApiLevelInt();
string OptionalLinkArguments;
for (int ArchIndex = 0; ArchIndex < Arches.Count; ArchIndex++)
{
string Arch = Arches[ArchIndex];
// 32-bit ABI may need fixup for removed bsd_signal in NDK11 for android-21+
OptionalLinkArguments = "";
if (NDKApiLevelInt >= 21)
{
// this file was added in NDK11 so use existence to detect (RELEASE.TXT no longer present)
if (File.Exists(Path.Combine(NDKRoot, "source.properties")))
{
switch (Arch)
{
case "-armv7":
OptionalLinkArguments = string.Format(" \"{0}\"", Path.Combine(UnrealBuildTool.EngineDirectory.FullName, "Build/Android/Prebuilt/bsdsignal/lib/armeabi-v7a/libbsdsignal.a"));
break;
case "-x86":
OptionalLinkArguments = string.Format(" \"{0}\"", Path.Combine(UnrealBuildTool.EngineDirectory.FullName, "Build/Android/Prebuilt/bsdsignal/lib/x86/libbsdsignal.a"));
break;
}
}
}
for (int GPUArchIndex = 0; GPUArchIndex < GPUArchitectures.Count; GPUArchIndex++)
{
string GPUArchitecture = GPUArchitectures[GPUArchIndex];
int OutputPathIndex = ArchIndex * GPUArchitectures.Count + GPUArchIndex;
// Android will have an array of outputs
if (LinkEnvironment.OutputFilePaths.Count < OutputPathIndex ||
!LinkEnvironment.OutputFilePaths[OutputPathIndex].GetFileNameWithoutExtension().EndsWith(Arch + GPUArchitecture))
{
throw new BuildException("The OutputFilePaths array didn't match the Arches array in AndroidToolChain.LinkAllFiles");
}
// Create an action that invokes the linker.
Action LinkAction = ActionGraph.Add(ActionType.Link);
LinkAction.WorkingDirectory = UnrealBuildTool.EngineSourceDirectory.FullName;
if (LinkEnvironment.bIsBuildingLibrary)
{
switch (Arch)
{
case "-armv7": LinkAction.CommandPath = ArPathArm; break;
case "-arm64": LinkAction.CommandPath = ArPathArm64; break;
case "-x86": LinkAction.CommandPath = ArPathx86; ; break;
case "-x64": LinkAction.CommandPath = ArPathx64; ; break;
default: LinkAction.CommandPath = ArPathArm; ; break;
}
}
else
{
LinkAction.CommandPath = ClangPath;
}
string LinkerPath = LinkAction.WorkingDirectory;
LinkAction.WorkingDirectory = LinkEnvironment.IntermediateDirectory.FullName;
// Get link arguments.
LinkAction.CommandArguments = LinkEnvironment.bIsBuildingLibrary ? GetArArguments(LinkEnvironment) : GetLinkArguments(LinkEnvironment, Arch);
// Add the output file as a production of the link action.
FileItem OutputFile;
OutputFile = FileItem.GetItemByFileReference(LinkEnvironment.OutputFilePaths[OutputPathIndex]);
Outputs.Add(OutputFile);
LinkAction.ProducedItems.Add(OutputFile);
LinkAction.StatusDescription = string.Format("{0}", Path.GetFileName(OutputFile.AbsolutePath));
// LinkAction.bPrintDebugInfo = true;
// Add the output file to the command-line.
if (LinkEnvironment.bIsBuildingLibrary)
{
LinkAction.CommandArguments += string.Format(" \"{0}\"", OutputFile.AbsolutePath);
}
else
{
LinkAction.CommandArguments += string.Format(" -o \"{0}\"", OutputFile.AbsolutePath);
}
// Add the input files to a response file, and pass the response file on the command-line.
List<string> InputFileNames = new List<string>();
foreach (FileItem InputFile in LinkEnvironment.InputFiles)
{
// make sure it's for current Arch
if (Path.GetFileNameWithoutExtension(InputFile.AbsolutePath).EndsWith(Arch + GPUArchitecture))
{
string AbsolutePath = InputFile.AbsolutePath.Replace("\\", "/");
AbsolutePath = AbsolutePath.Replace(LinkEnvironment.IntermediateDirectory.FullName.Replace("\\", "/"), "");
AbsolutePath = AbsolutePath.TrimStart(new char[] { '/' });
InputFileNames.Add(string.Format("\"{0}\"", AbsolutePath));
LinkAction.PrerequisiteItems.Add(InputFile);
}
}
FileReference ResponseFileName = GetResponseFileName(LinkEnvironment, OutputFile);
LinkAction.CommandArguments += string.Format(" @\"{0}\"", ResponseFile.Create(ResponseFileName, InputFileNames));
// libs don't link in other libs
if (!LinkEnvironment.bIsBuildingLibrary)
{
// Add the library paths to the argument list.
foreach (string LibraryPath in LinkEnvironment.LibraryPaths)
{
// LinkerPaths could be relative or absolute
string AbsoluteLibraryPath = ActionThread.ExpandEnvironmentVariables(LibraryPath);
if (IsDirectoryForArch(AbsoluteLibraryPath, Arch))
{
// environment variables aren't expanded when using the $( style
if (Path.IsPathRooted(AbsoluteLibraryPath) == false)
{
AbsoluteLibraryPath = Path.Combine(LinkerPath, AbsoluteLibraryPath);
}
LinkAction.CommandArguments += string.Format(" -L\"{0}\"", AbsoluteLibraryPath);
}
}
// add libraries in a library group
LinkAction.CommandArguments += string.Format(" -Wl,--start-group");
foreach (string AdditionalLibrary in LinkEnvironment.AdditionalLibraries)
{
if (!ShouldSkipLib(AdditionalLibrary, Arch, GPUArchitecture))
{
if (String.IsNullOrEmpty(Path.GetDirectoryName(AdditionalLibrary)))
{
LinkAction.CommandArguments += string.Format(" \"-l{0}\"", AdditionalLibrary);
}
else
{
// full pathed libs are compiled by us, so we depend on linking them
LinkAction.CommandArguments += string.Format(" \"{0}\"", Path.GetFullPath(AdditionalLibrary));
LinkAction.PrerequisiteItems.Add(FileItem.GetItemByPath(AdditionalLibrary));
}
}
}
LinkAction.CommandArguments += OptionalLinkArguments;
LinkAction.CommandArguments += string.Format(" -Wl,--end-group");
// Write the MAP file to the output directory.
if (LinkEnvironment.bCreateMapFile)
{
FileReference MAPFilePath = FileReference.Combine(LinkEnvironment.OutputDirectory, Path.GetFileNameWithoutExtension(OutputFile.AbsolutePath) + ".map");
FileItem MAPFile = FileItem.GetItemByFileReference(MAPFilePath);
LinkAction.CommandArguments += String.Format(" -Wl,-Map,{0}", MAPFilePath);
LinkAction.ProducedItems.Add(MAPFile);
// Export a list of object file paths, so we can locate the object files referenced by the map file
ExportObjectFilePaths(LinkEnvironment, Path.ChangeExtension(MAPFilePath.FullName, ".objpaths"));
}
}
// Add the additional arguments specified by the environment.
LinkAction.CommandArguments += LinkEnvironment.AdditionalArguments;
LinkAction.CommandArguments = LinkAction.CommandArguments.Replace("\\", "/");
// Only execute linking on the local PC.
LinkAction.bCanExecuteRemotely = false;
}
}
return Outputs.ToArray();
}
private void ExportObjectFilePaths(LinkEnvironment LinkEnvironment, string FileName)
{
// Write the list of object file directories
HashSet<DirectoryReference> ObjectFileDirectories = new HashSet<DirectoryReference>();
foreach (FileItem InputFile in LinkEnvironment.InputFiles)
{
ObjectFileDirectories.Add(InputFile.Reference.Directory);
}
foreach (FileItem InputLibrary in LinkEnvironment.InputLibraries)
{
ObjectFileDirectories.Add(InputLibrary.Reference.Directory);
}
foreach (string AdditionalLibrary in LinkEnvironment.AdditionalLibraries.Where(x => Path.IsPathRooted(x)))
{
ObjectFileDirectories.Add(new FileReference(AdditionalLibrary).Directory);
}
foreach (string LibraryPath in LinkEnvironment.LibraryPaths)
{
ObjectFileDirectories.Add(new DirectoryReference(LibraryPath));
}
foreach (string LibraryPath in (Environment.GetEnvironmentVariable("LIB") ?? "").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
ObjectFileDirectories.Add(new DirectoryReference(LibraryPath));
}
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
File.WriteAllLines(FileName, ObjectFileDirectories.Select(x => x.FullName).OrderBy(x => x).ToArray());
}
public override void ModifyBuildProducts(ReadOnlyTargetRules Target, UEBuildBinary Binary, List<string> Libraries, List<UEBuildBundleResource> BundleResources, Dictionary<FileReference, BuildProductType> BuildProducts)
{
// the binary will have all of the .so's in the output files, we need to trim down to the shared apk (which is what needs to go into the manifest)
if (Binary.Config.Type != UEBuildBinaryType.StaticLibrary)
{
foreach (FileReference BinaryPath in Binary.Config.OutputFilePaths)
{
FileReference ApkFile = BinaryPath.ChangeExtension(".apk");
BuildProducts.Add(ApkFile, BuildProductType.Executable);
}
}
}
public override void CompileCSharpProject(CSharpEnvironment CompileEnvironment, FileReference ProjectFileName, FileReference DestinationFile, ActionGraph ActionGraph)
{
throw new BuildException("Android cannot compile C# files");
}
public static void OutputReceivedDataEventHandler(Object Sender, DataReceivedEventArgs Line)
{
if ((Line != null) && (Line.Data != null))
{
Log.TraceInformation(Line.Data);
}
}
public void StripSymbols(FileReference SourceFile, FileReference TargetFile)
{
if (SourceFile != TargetFile)
{
// Strip command only works in place so we need to copy original if target is different
File.Copy(SourceFile.FullName, TargetFile.FullName, true);
}
ProcessStartInfo StartInfo = new ProcessStartInfo();
if (SourceFile.FullName.Contains("-armv7"))
{
StartInfo.FileName = ArPathArm;
}
else
if (SourceFile.FullName.Contains("-arm64"))
{
StartInfo.FileName = ArPathArm64;
}
else
if (SourceFile.FullName.Contains("-x86"))
{
StartInfo.FileName = ArPathx86;
}
else
if (SourceFile.FullName.Contains("-x64"))
{
StartInfo.FileName = ArPathx64;
}
else
{
throw new BuildException("Couldn't determine Android architecture to strip symbols from {0}", SourceFile.FullName);
}
// fix the executable (replace the last -ar with -strip and keep any extension)
int ArIndex = StartInfo.FileName.LastIndexOf("-ar");
StartInfo.FileName = StartInfo.FileName.Substring(0, ArIndex) + "-strip" + StartInfo.FileName.Substring(ArIndex + 3);
StartInfo.Arguments = "--strip-debug " + TargetFile.FullName;
StartInfo.UseShellExecute = false;
StartInfo.CreateNoWindow = true;
Utils.RunLocalProcessAndLogOutput(StartInfo);
}
};
}