示例#1
0
        /// <summary>
        /// Construct an instance of the given target rules
        /// </summary>
        /// <param name="TypeName">Type name of the target rules</param>
        /// <param name="TargetInfo">Target configuration information to pass to the constructor</param>
        /// <param name="Arguments">Command line arguments for this target</param>
        /// <returns>Instance of the corresponding TargetRules</returns>
        protected TargetRules CreateTargetRulesInstance(string TypeName, TargetInfo TargetInfo, string[] Arguments)
        {
            // The build module must define a type named '<TargetName>Target' that derives from our 'TargetRules' type.
            Type RulesType = CompiledAssembly.GetType(TypeName);

            if (RulesType == null)
            {
                throw new BuildException("Expecting to find a type to be declared in a target rules named '{0}'.  This type must derive from the 'TargetRules' type defined by Unreal Build Tool.", TypeName);
            }

            // Create an instance of the module's rules object, and set some defaults before calling the constructor.
            TargetRules Rules = (TargetRules)FormatterServices.GetUninitializedObject(RulesType);

            Rules.bUseBackwardsCompatibleDefaults = bUseBackwardsCompatibleDefaults;

            // Find the constructor
            ConstructorInfo Constructor = RulesType.GetConstructor(new Type[] { typeof(TargetInfo) });

            if (Constructor == null)
            {
                throw new BuildException("No constructor found on {0} which takes an argument of type TargetInfo.", RulesType.Name);
            }

            // Invoke the regular constructor
            try
            {
                Constructor.Invoke(Rules, new object[] { TargetInfo });
            }
            catch (Exception Ex)
            {
                throw new BuildException(Ex, "Unable to instantiate instance of '{0}' object type from compiled assembly '{1}'.  Unreal Build Tool creates an instance of your module's 'Rules' object in order to find out about your module's requirements.  The CLR exception details may provide more information:  {2}", TypeName, Path.GetFileNameWithoutExtension(CompiledAssembly.Location), Ex.ToString());
            }

            // Set the default overriddes for the configured target type
            Rules.SetOverridesForTargetType();

            // Parse any additional command-line arguments. These override default settings specified in config files or the .target.cs files.
            if (Arguments != null)
            {
                foreach (object ConfigurableObject in Rules.GetConfigurableObjects())
                {
                    CommandLine.ParseArguments(Arguments, ConfigurableObject);
                }
            }

            // Set the final value for the link type in the target rules
            if (Rules.LinkType == TargetLinkType.Default)
            {
                throw new BuildException("TargetRules.LinkType should be inferred from TargetType");
            }

            // Set the default value for whether to use the shared build environment
            if (Rules.BuildEnvironment == TargetBuildEnvironment.Default)
            {
                if (Rules.Type == TargetType.Program && TargetInfo.ProjectFile != null && TargetNameToTargetFile[Rules.Name].IsUnderDirectory(TargetInfo.ProjectFile.Directory))
                {
                    Rules.BuildEnvironment = TargetBuildEnvironment.Unique;
                }
                else if (UnrealBuildTool.IsEngineInstalled() || Rules.LinkType != TargetLinkType.Monolithic)
                {
                    Rules.BuildEnvironment = TargetBuildEnvironment.Shared;
                }
                else
                {
                    Rules.BuildEnvironment = TargetBuildEnvironment.Unique;
                }
            }

            // Lean and mean means no Editor and other frills.
            if (Rules.bCompileLeanAndMeanUE)
            {
                Rules.bBuildEditor         = false;
                Rules.bBuildDeveloperTools = Rules.bBuildDeveloperTools ?? false;
                Rules.bCompileSimplygon    = false;
                Rules.bCompileSimplygonSSF = false;
                Rules.bCompileSpeedTree    = false;
            }

            // if the bBuildDeveloperTools switch hasn't been defined, default it to the bCompileAgainstEngine switch.
            if (!Rules.bBuildDeveloperTools.HasValue)
            {
                Rules.bBuildDeveloperTools = Rules.bCompileAgainstEngine;
            }

            // Automatically include CoreUObject
            if (Rules.bCompileAgainstEngine)
            {
                Rules.bCompileAgainstCoreUObject = true;
            }

            // Must have editor only data if building the editor.
            if (Rules.bBuildEditor)
            {
                Rules.bBuildWithEditorOnlyData = true;
            }

            // Apply the override to force debug info to be enabled
            if (Rules.bForceDebugInfo)
            {
                Rules.bDisableDebugInfo             = false;
                Rules.bOmitPCDebugInfoInDevelopment = false;
            }

            // Setup the malloc profiler
            if (Rules.bUseMallocProfiler)
            {
                Rules.bOmitFramePointers = false;
                Rules.GlobalDefinitions.Add("USE_MALLOC_PROFILER=1");
            }

            // Set a macro if we allow using generated inis
            if (!Rules.bAllowGeneratedIniWhenCooked)
            {
                Rules.GlobalDefinitions.Add("DISABLE_GENERATED_INI_WHEN_COOKED=1");
            }

            return(Rules);
        }
        /// <summary>
        /// Construct an instance of the given target rules
        /// </summary>
        /// <param name="TypeName">Type name of the target rules</param>
        /// <param name="TargetInfo">Target configuration information to pass to the constructor</param>
        /// <param name="Arguments">Command line arguments for this target</param>
        /// <returns>Instance of the corresponding TargetRules</returns>
        protected TargetRules CreateTargetRulesInstance(string TypeName, TargetInfo TargetInfo, CommandLineArguments Arguments)
        {
            // The build module must define a type named '<TargetName>Target' that derives from our 'TargetRules' type.
            Type RulesType = CompiledAssembly.GetType(TypeName);

            if (RulesType == null)
            {
                throw new BuildException("Expecting to find a type to be declared in a target rules named '{0}'.  This type must derive from the 'TargetRules' type defined by Unreal Build Tool.", TypeName);
            }

            // Create an instance of the module's rules object, and set some defaults before calling the constructor.
            TargetRules Rules = (TargetRules)FormatterServices.GetUninitializedObject(RulesType);

            Rules.bUseBackwardsCompatibleDefaults = bUseBackwardsCompatibleDefaults;

            // Find the constructor
            ConstructorInfo Constructor = RulesType.GetConstructor(new Type[] { typeof(TargetInfo) });

            if (Constructor == null)
            {
                throw new BuildException("No constructor found on {0} which takes an argument of type TargetInfo.", RulesType.Name);
            }

            // Invoke the regular constructor
            try
            {
                Constructor.Invoke(Rules, new object[] { TargetInfo });
            }
            catch (Exception Ex)
            {
                throw new BuildException(Ex, "Unable to instantiate instance of '{0}' object type from compiled assembly '{1}'.  Unreal Build Tool creates an instance of your module's 'Rules' object in order to find out about your module's requirements.  The CLR exception details may provide more information:  {2}", TypeName, Path.GetFileNameWithoutExtension(CompiledAssembly.Location), Ex.ToString());
            }

            // Return the target file name to the caller
            Rules.File = TargetNameToTargetFile[TargetInfo.Name];

            // Set the default overriddes for the configured target type
            Rules.SetOverridesForTargetType();

            // Parse any additional command-line arguments. These override default settings specified in config files or the .target.cs files.
            if (Arguments != null)
            {
                foreach (object ConfigurableObject in Rules.GetConfigurableObjects())
                {
                    Arguments.ApplyTo(ConfigurableObject);
                }
            }

            // Set the final value for the link type in the target rules
            if (Rules.LinkType == TargetLinkType.Default)
            {
                throw new BuildException("TargetRules.LinkType should be inferred from TargetType");
            }

            // Set the default value for whether to use the shared build environment
            if (Rules.BuildEnvironment == TargetBuildEnvironment.Unique && UnrealBuildTool.IsEngineInstalled())
            {
                throw new BuildException("Targets with a unique build environment cannot be built an installed engine.");
            }

            // Automatically include CoreUObject
            if (Rules.bCompileAgainstEngine)
            {
                Rules.bCompileAgainstCoreUObject = true;
            }

            // Must have editor only data if building the editor.
            if (Rules.bBuildEditor)
            {
                Rules.bBuildWithEditorOnlyData = true;
            }

            // Apply the override to force debug info to be enabled
            if (Rules.bForceDebugInfo)
            {
                Rules.bDisableDebugInfo             = false;
                Rules.bOmitPCDebugInfoInDevelopment = false;
            }

            // Setup the malloc profiler
            if (Rules.bUseMallocProfiler)
            {
                Rules.bOmitFramePointers = false;
                Rules.GlobalDefinitions.Add("USE_MALLOC_PROFILER=1");
            }

            // Set a macro if we allow using generated inis
            if (!Rules.bAllowGeneratedIniWhenCooked)
            {
                Rules.GlobalDefinitions.Add("DISABLE_GENERATED_INI_WHEN_COOKED=1");
            }

            if (!Rules.bAllowNonUFSIniWhenCooked)
            {
                Rules.GlobalDefinitions.Add("DISABLE_NONUFS_INI_WHEN_COOKED=1");
            }

            if (Rules.bDisableUnverifiedCertificates)
            {
                Rules.GlobalDefinitions.Add("DISABLE_UNVERIFIED_CERTIFICATE_LOADING=1");
            }

            // Allow the platform to finalize the settings
            UEBuildPlatform Platform = UEBuildPlatform.GetBuildPlatform(Rules.Platform);

            Platform.ValidateTarget(Rules);

            // Some platforms may *require* monolithic compilation...
            if (Rules.LinkType != TargetLinkType.Monolithic && UEBuildPlatform.PlatformRequiresMonolithicBuilds(Rules.Platform, Rules.Configuration))
            {
                throw new BuildException(String.Format("{0}: {1} does not support modular builds", Rules.Name, Rules.Platform));
            }

            return(Rules);
        }