예제 #1
0
        /// <summary>
        /// Optionally compiles and loads target rules assembly.
        /// </summary>
        /// <param name="Properties"></param>
        /// <param name="TargetsDllFilename"></param>
        /// <param name="DoNotCompile"></param>
        /// <param name="TargetScripts"></param>
        private static void CompileAndLoadTargetsAssembly(ProjectProperties Properties, FileReference TargetsDllFilename, bool DoNotCompile, List <FileReference> TargetScripts)
        {
            CommandUtils.LogVerbose("Compiling targets DLL: {0}", TargetsDllFilename);

            var ReferencedAssemblies = new List <string>()
            {
                "System.dll",
                "System.Core.dll",
                "System.Xml.dll",
                typeof(UnrealBuildTool.PlatformExports).Assembly.Location
            };
            List <string> PreprocessorDefinitions = RulesAssembly.GetPreprocessorDefinitions();
            var           TargetsDLL       = DynamicCompilation.CompileAndLoadAssembly(TargetsDllFilename, TargetScripts, ReferencedAssemblies, PreprocessorDefinitions, DoNotCompile);
            var           AllCompiledTypes = TargetsDLL.GetTypes();

            foreach (Type TargetType in AllCompiledTypes)
            {
                // Find TargetRules but skip all "UE4Editor", "UE4Game" targets.
                if (typeof(TargetRules).IsAssignableFrom(TargetType))
                {
                    string TargetName = GetTargetName(TargetType);

                    ReadOnlyBuildVersion Version         = new ReadOnlyBuildVersion(BuildVersion.ReadDefault());
                    TargetInfo           DummyTargetInfo = new TargetInfo(TargetName, BuildHostPlatform.Current.Platform, UnrealTargetConfiguration.Development, "", Properties.RawProjectPath, Version);

                    // Create an instance of this type
                    CommandUtils.LogVerbose("Creating target rules object: {0}", TargetType.Name);
                    TargetRules Rules = Activator.CreateInstance(TargetType, DummyTargetInfo) as TargetRules;
                    CommandUtils.LogVerbose("Adding target: {0} ({1})", TargetType.Name, Rules.Type);

                    SingleTargetProperties TargetData;
                    TargetData.TargetName = GetTargetName(TargetType);
                    TargetData.Rules      = Rules;
                    if (Rules.Type == global::UnrealBuildTool.TargetType.Program)
                    {
                        Properties.Programs.Add(TargetData);
                    }
                    else
                    {
                        Properties.Targets.Add(Rules.Type, TargetData);
                    }
                }
            }
        }