图解最终构建的项目是以什么形式在UBT内存中保存的?UnrealBuildTool功能流程解析-Unreal4源码拆解

Unreal4源码拆解

UnrealBuildTool功能流程解析

TargetDescriptor构建对象描述类

知乎专栏:UBT源码解析

概述

  • TargetDescriptor 构建目标的描述信息
  • 保存了构建一个UEBuildTarget所需要的所有信息

创建方式:

  1. 用于该项目依赖的项目,
    1. 这些项目需要在主项目之前编译时候进行编译
    2. 会为这些需要提前编译的项目创建TargetDescriptor
    3. 调用public static TargetDescriptor FromTargetInfo(TargetInfo Info)
  2. 通过解析命令行参数,进行为每一个构建目标创建TargetDescriptor
    1. 调用public static void ParseSingleCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile, List<TargetDescriptor> TargetDescriptors)

成员变量

ProjectFile

  • 定义:public FileReference ProjectFile
  • 功能:存储对项目的.uproject文件的引用。

Name;

  • 定义:public string Name
  • 功能:其实就是TargetName 构建项目名

Platform;

  • 定义:public UnrealTargetPlatform Platform
  • 功能:构建的目标平台独特字符串和ID

Configuration;

  • 定义:public UnrealTargetConfiguration Configuration;
  • 功能:构建配置类型
	public enum UnrealTargetConfiguration
	{
		/// <summary>
		/// Unknown
		/// </summary>
		Unknown,

		/// <summary>
		/// Debug configuration
		/// </summary>
		Debug,

		/// <summary>
		/// DebugGame configuration; equivalent to development, but with optimization disabled for game modules
		/// </summary>
		DebugGame,

		/// <summary>
		/// Development configuration
		/// </summary>
		Development,

		/// <summary>
		/// Shipping configuration
		/// </summary>
		Shipping,

		/// <summary>
		/// Test configuration
		/// </summary>
		Test,
	}

Architecture;

  • 定义:public string Architecture;
  • 功能:存储使用到的aarch64-unknown-linux-gnueabi或者x86_64-unknown-linux-gnu等等一些交叉编译工具

AdditionalArguments;

  • 定义:public CommandLineArguments AdditionalArguments;
  • 功能:
    • 如果在新建TargetDescriptor实例中,
    • 把自己实例里面的参数赋值到变量中以后,
    • 剩下的如果还有命令行参数就加到AdditionalArguments中

ForeignPlugin -Plugin=

  • 定义:public FileReference ForeignPlugin = null;
  • Meta:[CommandLine("-Plugin=")]
  • 功能:拆解命令行参数,额外配置的需要一起编译的插件

OnlyModuleNames -Module=

  • 定义:public HashSet OnlyModuleNames = new HashSet(StringComparer.OrdinalIgnoreCase);
  • Meta:[CommandLine("-Module=")]
  • 功能:拆解命令行参数,需要一起编译的模块

SpecificFilesToCompile -SingleFile=

  • 定义:public List SpecificFilesToCompile = new List();
  • Meta:[CommandLine("-SingleFile=")]
  • 功能:拆解命令行参数,需要单独编译的文件

HotReloadMode

  • 定义:public HotReloadMode HotReloadMode = HotReloadMode.Default;
  • Meta:
    • [CommandLine("-NoHotReload", Value = nameof(HotReloadMode.Disabled))]
    • [CommandLine("-ForceHotReload", Value = nameof(HotReloadMode.FromIDE))]
    • [CommandLine("-LiveCoding", Value = nameof(HotReloadMode.LiveCoding))]
  • 功能:拆解命令行参数,编译时候的热重载类型

HotReloadModuleNameToSuffix -ModuleWithSuffix=

  • 定义:public Dictionary<string, int> HotReloadModuleNameToSuffix = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
  • 命令行参数:热重载模块的后缀-ModuleWithSuffix=
  • 功能:拆解命令行参数,编译时候的热重载类型

WriteActionFiles -WriteActions=

  • 定义:public List WriteActionFiles = new List();
  • Meta:[CommandLine("-WriteActions=")]-WriteActions=xxx文件
  • 功能:会把我们的编译操作相关内容以json的方式导出到某个文件中
		{
			"Type": "Compile",
			"WorkingDirectory": "D:\\UE4SourceCode\\UnrealEngine-4.27.1-release\\Engine\\Source",
			"CommandPath": "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.18362.0\\x64\\rc.exe",
			"CommandArguments": "/nologo /D_WIN64 /l 0x409 /I \"D:\\UE4SourceCode\\UnrealEngine-4.27.1-release\\Engine\\Source\" /I \"D:\\SoftWare\\VS\\IDE\\VC\\Tools\\MSVC\\14.29.30133\\INCLUDE\" /I \"C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.2\\include\\um\" /I \"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\" /I \"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\shared\" /I \"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\um\" /I \"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\winrt\" /DIS_PROGRAM=0 /DUE_GAME=1 /DENABLE_PGO_PROFILE=0 /DUSE_VORBIS_FOR_STREAMING=1 /DUSE_XMA2_FOR_STREAMING=1 /DWITH_DEV_AUTOMATION_TESTS=1 /DWITH_PERF_AUTOMATION_TESTS=1 /DUNICODE /D_UNICODE /D__UNREAL__ /DIS_MONOLITHIC=1 /DWITH_ENGINE=1 /DWITH_UNREAL_DEVELOPER_TOOLS=1 /DWITH_APPLICATION_CORE=1 /DWITH_COREUOBJECT=1 /DUSE_STATS_WITHOUT_ENGINE=0 /DWITH_PLUGIN_SUPPORT=0 /DWITH_ACCESSIBILITY=1 /DWITH_PERFCOUNTERS=0 /DUSE_LOGGING_IN_SHIPPING=0 /DWITH_LOGGING_TO_MEMORY=0 /DUSE_CACHE_FREED_OS_ALLOCS=1 /DUSE_CHECKS_IN_SHIPPING=0 /DUSE_ESTIMATED_UTCNOW=0 /DWITH_EDITOR=0 /DWITH_EDITORONLY_DATA=0 /DWITH_SERVER_CODE=1 /DWITH_PUSH_MODEL=0 /DWITH_CEF3=1 /DWITH_LIVE_CODING=1 /DUE_LIVE_CODING_ENGINE_DIR=\"D:\\\\UE4SourceCode\\\\UnrealEngine-4.27.1-release\\\\Engine\" /DUE_LIVE_CODING_PROJECT=\"D:\\\\UnrealProject\\\\ZeroUE4Project\\\\ZeroUE4Project.uproject\" /DUBT_MODULE_MANIFEST=\"ZeroUE4Project-Win64-Debug.modules\" /DUBT_MODULE_MANIFEST_DEBUGGAME=\"ZeroUE4Project-Win64-DebugGame.modules\" /DUBT_COMPILED_PLATFORM=Win64 /DUBT_COMPILED_TARGET=Game /DUE_APP_NAME=\"ZeroUE4Project\" /DUE_ENGINE_DIRECTORY=\"../../../../UE4SourceCode/UnrealEngine-4.27.1-release/Engine/\" /DNDIS_MINIPORT_MAJOR_VERSION=0 /DWIN32=1 /D_WIN32_WINNT=0x0601 /DWINVER=0x0601 /DPLATFORM_WINDOWS=1 /DPLATFORM_MICROSOFT=1 /DOVERRIDE_PLATFORM_HEADER_NAME=Windows /DRHI_RAYTRACING=1 /DNDEBUG=1 /DUE_BUILD_DEBUG=1 /DORIGINAL_FILE_NAME=\"ZeroUE4Project-Win64-Debug.exe\" /DBUILD_ICON_FILE_NAME=\"\\\"D:\\\\UE4SourceCode\\\\UnrealEngine-4.27.1-release\\\\Engine\\\\Build\\\\Windows\\\\Resources\\\\Default.ico\\\"\" /DPROJECT_COPYRIGHT_STRING=\"Fill out your copyright notice in the Description page of Project Settings.\" /DPROJECT_PRODUCT_NAME=\"Third Person Game Template\" /DPROJECT_PRODUCT_IDENTIFIER=ZeroUE4Project /fo \"D:\\UnrealProject\\ZeroUE4Project\\Intermediate\\Build\\Win64\\ZeroUE4Project\\Debug\\Launch\\PCLaunch.rc.res\"  \"D:\\UE4SourceCode\\UnrealEngine-4.27.1-release\\Engine\\Source\\Runtime\\Launch\\Resources\\Windows\\PCLaunch.rc\"",
			"CommandVersion": "0",
			"CommandDescription": "Resource",
			"StatusDescription": "PCLaunch.rc",
			"bPrintDebugInfo": false,
			"bCanExecuteRemotely": true,
			"bCanExecuteRemotelyWithSNDBS": false,
			"bIsGCCCompiler": false,
			"bShouldOutputStatusDescription": true,
			"bProducesImportLibrary": false,
			"PrerequisiteItems": [
				"D:\\UE4SourceCode\\UnrealEngine-4.27.1-release\\Engine\\Build\\Windows\\Resources\\Default.ico",
				"D:\\UE4SourceCode\\UnrealEngine-4.27.1-release\\Engine\\Source\\Runtime\\Launch\\Resources\\Windows\\PCLaunch.rc"
			],
			"ProducedItems": [
				"D:\\UnrealProject\\ZeroUE4Project\\Intermediate\\Build\\Win64\\ZeroUE4Project\\Debug\\Launch\\PCLaunch.rc.res"
			],
			"DeleteItems": [
			]
		},

LiveCodingModules

  • 定义:public FileReference LiveCodingModules = null;
  • Meta:[CommandLine("-LiveCodingModules=")]
  • 功能:需要实时编码的模块名,和热重载有关

LiveCodingManifest

  • 定义:public FileReference LiveCodingManifest = null;
  • Meta:[CommandLine("-LiveCodingManifest=")]
  • 功能:需要实时编码的Manifest文件,和热重载有关

bQuiet

  • 定义:public bool bQuiet;
  • Meta:[CommandLine("-Quiet")]
  • 功能:是否使用静默模式

成员函数

FromTargetInfo(TargetInfo Info)

  • 定义:public static TargetDescriptor FromTargetInfo(TargetInfo Info)
  • 功能:通过TargetInfo创建TargetDescriptor实例

ParseCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile)

  • 定义:public static List ParseCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile)
  • 功能:调用ParseCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile, List TargetDescriptors)

ParseCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile, List TargetDescriptors)

  • 定义:public static void ParseCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile, List TargetDescriptors)
  • 功能:通过递归调用自己,拆解-Target参数和-Targetlist,拆解完后对每一个以-Target拆解结果+其他命令行参数调用ParseSingleCommandLine

ParseSingleCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile, List TargetDescriptors)

  • 定义:public static void ParseSingleCommandLine(CommandLineArguments Arguments, bool bUsePrecompiled, bool bSkipRulesCompile, List TargetDescriptors)

  • 功能:根据已有信息,创建多个TargetDescriptor实例

  • 具体解析流程如图:
    在这里插入图片描述

  • 假设有命令行参数解析出2个UnrealTargetPlatform,3个Architecture,2个UnrealTargetConfiguration,可以创建出2*3*2个TargetDescriptor实例

  • 如下图:
    在这里插入图片描述

TryParseProjectFileArgument(CommandLineArguments Arguments, out FileReference ProjectFile)

  • 定义:public static bool TryParseProjectFileArgument(CommandLineArguments Arguments, out FileReference ProjectFile)
  • 功能:从输入参数值中或者Engine\Build\InstalledProjectBuild.txt中解析出.uproject文件
    • 找到文件返回True
    • 没找到返回False

ParseArgumentValue(string Argument, string Prefix, out string Value)

  • 定义:private static bool ParseArgumentValue(string Argument, string Prefix, out string Value)
  • 功能:输入一个命令行参数,拆解出前缀和值

ToString()

  • 定义:public override string ToString()
  • 功能:把TargetDescriptor输出为字符串
		public override string ToString()
		{
			StringBuilder Result = new StringBuilder();
			Result.AppendFormat("{0} {1} {2}", Name, Platform, Configuration);
			if(!String.IsNullOrEmpty(Architecture))
			{
				Result.AppendFormat(" -Architecture={0}", Architecture);
			}
			if(ProjectFile != null)
			{
				Result.AppendFormat(" -Project={0}", Utils.MakePathSafeToUseWithCommandLine(ProjectFile));
			}
			if(AdditionalArguments != null && AdditionalArguments.Count > 0)
			{
				Result.AppendFormat(" {0}", AdditionalArguments);
			}
			return Result.ToString();
		}

GetHashCode()

  • 定义:public override int GetHashCode()
  • 功能:获取当前TargetDescriptor的哈希值:直接看源代码
		public override int GetHashCode()
		{
			return ProjectFile.GetHashCode() + 
				Name.GetHashCode() + 
				Platform.GetHashCode() + 
				Configuration.GetHashCode() + 
				Architecture.GetHashCode();
		}

Equals(object Obj)

  • 定义:public override bool Equals(object Obj)
  • 功能:判断两个TargetDescriptor是否相同
		public override bool Equals(object Obj) 
		{
			TargetDescriptor Other = Obj as TargetDescriptor;
			if (Other != null)
			{
				return
					ProjectFile == Other.ProjectFile &&
					Name == Other.Name &&
					Platform == Other.Platform &&
					Configuration == Other.Configuration &&
					Architecture == Other.Architecture;
			}
			return false;
		}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值