Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/Configuration/TestTargetRules.cs
chris constantinescu 8c968941f9 UBT TestMode that allows building a test executable for an associated target.
- Each module can now have a Tests folder at its root containing low level tests written with Catch2
- Used like this: UnrealBuildTool.exe -Mode=Test TargetName Platform Configuration
- It creates a test executable that's associated with the specified build Target and it includes all the tests for the Target AND all its dependencies as well
- When building without -Mode=Test it will omit the Tests folder contents from compilation: in theory we never allowed folders named Tests at the root of modules, but there might be isolated exceptions where we didn't validate folder names - in this case we will need to move that Tests folder one level up for example
- Code paths for test and non-test builds are entirely separated

#jira UE-135280
#rb Jerome.Delattre
#preflight 61e839d5276892ce10759205

[CL 18663474 by chris constantinescu in ue5-main branch]
2022-01-19 15:00:37 -05:00

101 lines
3.1 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using EpicGames.Core;
using System.IO;
namespace UnrealBuildTool
{
/// <summary>
/// TargetRules extension for low level tests.
/// </summary>
public class TestTargetRules : TargetRules
{
/// <summary>
/// Associated tested target of this test target.
/// </summary>
public TargetRules TestedTarget { get; private set; }
/// <summary>
/// TestTargetRules is setup as a program and is linked monolithically .
/// It removes a lot of default compilation behavior in order to produce a minimal test environment.
/// </summary>
public TestTargetRules(TargetRules TestedTarget, TargetInfo Target) : base(Target)
{
if (TestedTarget is TestTargetRules)
{
throw new BuildException("TestedTarget can't be of type TestTargetRules.");
}
this.TestedTarget = TestedTarget;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExeBinariesSubFolder = Name = TestedTarget.Name + "Tests";
TargetSourceFile = File = FileReference.Combine(UnrealBuildTool.EngineSourceDirectory, "UnrealBuildTool", "Configuration", "TestTargetRules.cs");
LaunchModuleName = TestedTarget.LaunchModuleName + "Tests";
WindowsPlatform = TestedTarget.WindowsPlatform;
Type = TargetType.Program;
LinkType = TargetLinkType.Monolithic;
bBuildInSolutionByDefault = false;
bDeployAfterCompile = false;
bIsBuildingConsoleApplication = true;
// Disabling default true flags that aren't necessary for tests
// Lean and Mean mode
bBuildDeveloperTools = false;
// No localization
bCompileICU = false;
// No need for shaders by default
bForceBuildShaderFormats = false;
// Do not link against the engine, no Chromium Embedded Framework etc.
bCompileAgainstEngine = false;
bCompileCEF3 = false;
bCompileAgainstCoreUObject = false;
bCompileAgainstApplicationCore = false;
bUseLoggingInShipping = true;
bool bDebugOrDevelopment = Target.Configuration == UnrealTargetConfiguration.Debug || Target.Configuration == UnrealTargetConfiguration.Development;
bBuildWithEditorOnlyData = Target.Platform.IsInGroup(UnrealPlatformGroup.Desktop) && bDebugOrDevelopment;
// Disable malloc profiling in tests
bUseMallocProfiler = false;
// Useful for debugging test failures
if (Target.Configuration == UnrealTargetConfiguration.Debug)
{
bDebugBuildsActuallyUseDebugCRT = true;
}
GlobalDefinitions.AddRange(TestedTarget.GlobalDefinitions);
GlobalDefinitions.Add("STATS=0");
// Platform specific setup
if (Target.Platform == UnrealTargetPlatform.Android)
{
UndecoratedConfiguration = Target.Configuration;
string VersionScriptFile = Path.Combine(Directory.GetCurrentDirectory(), @"Developer\LowLevelTestsRunner\Private\Platform\Android\HideSymbols.ldscript");
AdditionalLinkerArguments = " -Wl,--version-script=" + VersionScriptFile;
GlobalDefinitions.Add("USE_ANDROID_INPUT=0");
GlobalDefinitions.Add("USE_ANDROID_OPENGL=0");
GlobalDefinitions.Add("USE_ANDROID_LAUNCH=0");
GlobalDefinitions.Add("USE_ANDROID_JNI=0");
}
else if (Target.Platform == UnrealTargetPlatform.IOS)
{
GlobalDefinitions.Add("HAS_METAL=0");
}
}
}
}