/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <param name="TargetType"></param> /// <param name="bBuildDeveloperTools"></param> /// <param name="bBuildEditor"></param> /// <param name="bBuildRequiresCookedData"></param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginDescriptorRequiredForProject(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform, TargetType TargetType, bool bBuildDeveloperTools, bool bBuildEditor, bool bBuildRequiresCookedData) { // Check if it's referenced by name from the project descriptor. If it is, we'll need the plugin to be included with the project regardless of whether it has // any platform-specific modules or content, just so the runtime can make the call. if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, Plugin.Name, true) == 0) { return(PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTarget(TargetType)); } } } // If the plugin contains content, it should be included for all platforms if (Plugin.Descriptor.bCanContainContent) { return(true); } // Check if the plugin has any modules for the given target foreach (ModuleDescriptor Module in Plugin.Descriptor.Modules) { if (Module.IsCompiledInConfiguration(Platform, TargetType, bBuildDeveloperTools, bBuildEditor, bBuildRequiresCookedData)) { return(true); } } return(false); }
/// <summary> /// Creates a plugin descriptor from a file on disk /// </summary> /// <param name="FileName">The filename to read</param> /// <returns>New plugin descriptor</returns> public static ProjectDescriptor FromFile(string FileName) { JsonObject RawObject = JsonObject.Read(FileName); try { ProjectDescriptor Descriptor = new ProjectDescriptor(); // Read the version if (!RawObject.TryGetIntegerField("FileVersion", out Descriptor.FileVersion)) { if (!RawObject.TryGetIntegerField("ProjectFileVersion", out Descriptor.FileVersion)) { throw new BuildException("Project descriptor '{0}' does not contain a valid FileVersion entry", FileName); } } // Check it's not newer than the latest version we can parse if (Descriptor.FileVersion > (int)PluginDescriptorVersion.Latest) { throw new BuildException("Project descriptor '{0}' appears to be in a newer version ({1}) of the file format that we can load (max version: {2}).", FileName, Descriptor.FileVersion, (int)ProjectDescriptorVersion.Latest); } // Read simple fields RawObject.TryGetStringField("EngineAssociation", out Descriptor.EngineAssociation); RawObject.TryGetStringField("Category", out Descriptor.Category); RawObject.TryGetStringField("Description", out Descriptor.Description); // Read the modules JsonObject[] ModulesArray; if (RawObject.TryGetObjectArrayField("Modules", out ModulesArray)) { Descriptor.Modules = Array.ConvertAll(ModulesArray, x => ModuleDescriptor.FromJsonObject(x)); } // Read the plugins JsonObject[] PluginsArray; if (RawObject.TryGetObjectArrayField("Plugins", out PluginsArray)) { Descriptor.Plugins = Array.ConvertAll(PluginsArray, x => PluginReferenceDescriptor.FromJsonObject(x)); } // Read the target platforms RawObject.TryGetStringArrayField("TargetPlatforms", out Descriptor.TargetPlatforms); // Get the sample name hash RawObject.TryGetUnsignedIntegerField("EpicSampleNameHash", out Descriptor.EpicSampleNameHash); // Read the pre and post-build steps CustomBuildSteps.TryRead(RawObject, "PreBuildSteps", out Descriptor.PreBuildSteps); CustomBuildSteps.TryRead(RawObject, "PostBuildSteps", out Descriptor.PostBuildSteps); return(Descriptor); } catch (JsonParseException ParseException) { throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName); } }
/// <summary> /// Creates a rules assembly with the given parameters. /// </summary> /// <param name="ProjectFileName">The project file to create rules for. Null for the engine.</param> /// <param name="bUsePrecompiled">Whether to use a precompiled engine</param> /// <param name="bSkipCompile">Whether to skip compilation for this assembly</param> /// <returns>New rules assembly</returns> public static RulesAssembly CreateProjectRulesAssembly(FileReference ProjectFileName, bool bUsePrecompiled, bool bSkipCompile) { // Check if there's an existing assembly for this project RulesAssembly ProjectRulesAssembly; if (!LoadedAssemblyMap.TryGetValue(ProjectFileName, out ProjectRulesAssembly)) { ProjectDescriptor Project = ProjectDescriptor.FromFile(ProjectFileName); // Create the parent assembly RulesAssembly Parent; if (Project.IsEnterpriseProject) { Parent = CreateEnterpriseRulesAssembly(bUsePrecompiled, bSkipCompile); } else { Parent = CreateEngineRulesAssembly(bUsePrecompiled, bSkipCompile); } // Find all the rules under the project source directory DirectoryReference ProjectDirectory = ProjectFileName.Directory; DirectoryReference ProjectSourceDirectory = DirectoryReference.Combine(ProjectDirectory, "Source"); List <FileReference> ModuleFiles = new List <FileReference>(FindAllRulesFiles(ProjectSourceDirectory, RulesFileType.Module)); List <FileReference> TargetFiles = new List <FileReference>(FindAllRulesFiles(ProjectSourceDirectory, RulesFileType.Target)); // Find all the project plugins List <PluginInfo> ProjectPlugins = new List <PluginInfo>(Plugins.ReadProjectPlugins(ProjectFileName.Directory)); // Add the project's additional plugin directories plugins too if (Project.AdditionalPluginDirectories != null) { foreach (string AdditionalPluginDirectory in Project.AdditionalPluginDirectories) { ProjectPlugins.AddRange(Plugins.ReadAdditionalPlugins(DirectoryReference.Combine(ProjectFileName.Directory, AdditionalPluginDirectory))); } } // Find all the plugin module rules Dictionary <FileReference, PluginInfo> ModuleFileToPluginInfo = new Dictionary <FileReference, PluginInfo>(); FindModuleRulesForPlugins(ProjectPlugins, ModuleFiles, ModuleFileToPluginInfo); // Add the games project's intermediate source folder DirectoryReference ProjectIntermediateSourceDirectory = DirectoryReference.Combine(ProjectDirectory, "Intermediate", "Source"); if (DirectoryReference.Exists(ProjectIntermediateSourceDirectory)) { ModuleFiles.AddRange(FindAllRulesFiles(ProjectIntermediateSourceDirectory, RulesFileType.Module)); TargetFiles.AddRange(FindAllRulesFiles(ProjectIntermediateSourceDirectory, RulesFileType.Target)); } // Compile the assembly FileReference AssemblyFileName = FileReference.Combine(ProjectDirectory, "Intermediate", "Build", "BuildRules", ProjectFileName.GetFileNameWithoutExtension() + "ModuleRules" + FrameworkAssemblyExtension); ProjectRulesAssembly = new RulesAssembly(ProjectDirectory, ProjectPlugins, ModuleFiles, TargetFiles, ModuleFileToPluginInfo, AssemblyFileName, bContainsEngineModules: false, bUseBackwardsCompatibleDefaults: true, bReadOnly: UnrealBuildTool.IsProjectInstalled(), bSkipCompile: bSkipCompile, Parent: Parent); LoadedAssemblyMap.Add(ProjectFileName, ProjectRulesAssembly); } return(ProjectRulesAssembly); }
/// <summary> /// Creates a plugin descriptor from a file on disk /// </summary> /// <param name="FileName">The filename to read</param> /// <returns>New plugin descriptor</returns> public static ProjectDescriptor FromFile(string FileName) { JsonObject RawObject = JsonObject.FromFile(FileName); try { ProjectDescriptor Descriptor = new ProjectDescriptor(); // Read the version if(!RawObject.TryGetIntegerField("FileVersion", out Descriptor.FileVersion)) { if(!RawObject.TryGetIntegerField("ProjectFileVersion", out Descriptor.FileVersion)) { throw new BuildException("Project descriptor '{0}' does not contain a valid FileVersion entry", FileName); } } // Check it's not newer than the latest version we can parse if(Descriptor.FileVersion > (int)PluginDescriptorVersion.Latest) { throw new BuildException("Project descriptor '{0}' appears to be in a newer version ({1}) of the file format that we can load (max version: {2}).", FileName, Descriptor.FileVersion, (int)ProjectDescriptorVersion.Latest); } // Read simple fields RawObject.TryGetStringField("EngineAssociation", out Descriptor.EngineAssociation); RawObject.TryGetStringField("Category", out Descriptor.Category); RawObject.TryGetStringField("Description", out Descriptor.Description); // Read the modules JsonObject[] ModulesArray; if(RawObject.TryGetObjectArrayField("Modules", out ModulesArray)) { Descriptor.Modules = Array.ConvertAll(ModulesArray, x => ModuleDescriptor.FromJsonObject(x)); } // Read the plugins JsonObject[] PluginsArray; if(RawObject.TryGetObjectArrayField("Plugins", out PluginsArray)) { Descriptor.Plugins = Array.ConvertAll(PluginsArray, x => PluginReferenceDescriptor.FromJsonObject(x)); } // Read the target platforms RawObject.TryGetStringArrayField("TargetPlatforms", out Descriptor.TargetPlatforms); // Get the sample name hash RawObject.TryGetUnsignedIntegerField("EpicSampleNameHash", out Descriptor.EpicSampleNameHash); return Descriptor; } catch(JsonParseException ParseException) { throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName); } }
/// <summary> /// Creates a rules assembly with the given parameters. /// </summary> /// <param name="ProjectFileName">The project file to create rules for. Null for the engine.</param> /// <returns>New rules assembly</returns> public static RulesAssembly CreateProjectRulesAssembly(FileReference ProjectFileName) { // Check if there's an existing assembly for this project RulesAssembly ProjectRulesAssembly; if (!LoadedAssemblyMap.TryGetValue(ProjectFileName, out ProjectRulesAssembly)) { ProjectDescriptor Project = ProjectDescriptor.FromFile(ProjectFileName.FullName); // Create the parent assembly RulesAssembly Parent; if (Project.IsEnterpriseProject) { Parent = CreateEnterpriseRulesAssembly(); } else { Parent = CreateEngineRulesAssembly(); } // Find all the rules under the project source directory DirectoryReference ProjectDirectory = ProjectFileName.Directory; DirectoryReference ProjectSourceDirectory = DirectoryReference.Combine(ProjectDirectory, "Source"); List <FileReference> ModuleFiles = new List <FileReference>(FindAllRulesFiles(ProjectSourceDirectory, RulesFileType.Module)); List <FileReference> TargetFiles = new List <FileReference>(FindAllRulesFiles(ProjectSourceDirectory, RulesFileType.Target)); // Find all the project plugins List <PluginInfo> ProjectPlugins = new List <PluginInfo>(Plugins.ReadProjectPlugins(ProjectFileName.Directory)); // Add the project's additional plugin directories plugins too ProjectPlugins.AddRange(Plugins.ReadAdditionalPlugins(Project.AdditionalPluginDirectories)); Dictionary <FileReference, PluginInfo> ModuleFileToPluginInfo = new Dictionary <FileReference, PluginInfo>(); FindModuleRulesForPlugins(ProjectPlugins, ModuleFiles, ModuleFileToPluginInfo); // Add the games project's intermediate source folder DirectoryReference ProjectIntermediateSourceDirectory = DirectoryReference.Combine(ProjectDirectory, "Intermediate", "Source"); if (DirectoryReference.Exists(ProjectIntermediateSourceDirectory)) { TargetFiles.AddRange(FindAllRulesFiles(ProjectIntermediateSourceDirectory, RulesFileType.Target)); } // Compile the assembly FileReference AssemblyFileName = FileReference.Combine(ProjectDirectory, "Intermediate", "Build", "BuildRules", ProjectFileName.GetFileNameWithoutExtension() + "ModuleRules.dll"); ProjectRulesAssembly = new RulesAssembly(ProjectPlugins, ModuleFiles, TargetFiles, ModuleFileToPluginInfo, AssemblyFileName, Parent); LoadedAssemblyMap.Add(ProjectFileName, ProjectRulesAssembly); } return(ProjectRulesAssembly); }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <param name="Target"></param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginEnabledForProject(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform, TargetType Target) { bool bEnabled = Plugin.EnabledByDefault; if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, Plugin.Name, true) == 0 && !PluginReference.bOptional) { bEnabled = PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTarget(Target); } } } return(bEnabled); }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginEnabledForProject(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform, TargetRules.TargetType Target) { bool bEnabled = Plugin.Descriptor.bEnabledByDefault || Plugin.LoadedFrom == PluginLoadedFrom.GameProject; if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, Plugin.Name, true) == 0) { bEnabled = PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTarget(Target); } } } return(bEnabled); }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="PluginName">Name of the plugin to check</param> /// <param name="Platform">The target platform</param> /// <param name="TargetConfiguration">The target configuration</param> /// <param name="Target"></param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginEnabledForProject(string PluginName, ProjectDescriptor Project, UnrealTargetPlatform Platform, UnrealTargetConfiguration TargetConfiguration, TargetType Target) { bool bEnabled = false; if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, PluginName, true) == 0) { bEnabled = PluginReference.bEnabled && PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTargetConfiguration(TargetConfiguration) && PluginReference.IsEnabledForTarget(Target); break; } } } return(bEnabled); }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check. May be null.</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <param name="Configuration">The target configuration</param> /// <param name="TargetType">The type of target being built</param> /// <param name="bRequiresCookedData">Whether the target requires cooked data</param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginCompiledForTarget(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, TargetType TargetType, bool bRequiresCookedData) { bool bCompiledForTarget = false; if (IsPluginEnabledForTarget(Plugin, Project, Platform, Configuration, TargetType) && Plugin.Descriptor.Modules != null) { bool bBuildDeveloperTools = (TargetType == TargetType.Editor || TargetType == TargetType.Program || (Configuration != UnrealTargetConfiguration.Test && Configuration != UnrealTargetConfiguration.Shipping)); foreach (ModuleDescriptor Module in Plugin.Descriptor.Modules) { if (Module.IsCompiledInConfiguration(Platform, Configuration, "", TargetType, bBuildDeveloperTools, bRequiresCookedData)) { bCompiledForTarget = true; break; } } } return(bCompiledForTarget); }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="PluginName">Name of the plugin to check</param> /// <param name="Platform">The target platform</param> /// <param name="Target"></param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginEnabledForProject(string PluginName, ProjectDescriptor Project, UnrealTargetPlatform Platform, TargetType Target) { bool bEnabled = false; if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, PluginName, true) == 0) { // start with whether it's enabled by default bEnabled = PluginReference.bEnabled; bEnabled = PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTarget(Target); break; } } } return(bEnabled); }
/// <summary> /// Creates a plugin descriptor from a file on disk /// </summary> /// <param name="FileName">The filename to read</param> /// <returns>New plugin descriptor</returns> public static ProjectDescriptor FromFile(FileReference FileName) { JsonObject RawObject = JsonObject.Read(FileName); try { ProjectDescriptor Descriptor = new ProjectDescriptor(RawObject); if (Descriptor.Modules != null) { foreach (ModuleDescriptor Module in Descriptor.Modules) { Module.Validate(FileName); } } return(Descriptor); } catch (JsonParseException ParseException) { throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName); } }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check. May be null.</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <param name="Configuration">The target configuration</param> /// <param name="TargetType">The type of target being built</param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginEnabledForTarget(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, TargetType TargetType) { if (!Plugin.Descriptor.SupportsTargetPlatform(Platform)) { return(false); } bool bAllowEnginePluginsEnabledByDefault = (Project == null ? true : !Project.DisableEnginePluginsByDefault); bool bEnabled = Plugin.IsEnabledByDefault(bAllowEnginePluginsEnabledByDefault); if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, Plugin.Name, true) == 0 && !PluginReference.bOptional) { bEnabled = PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTargetConfiguration(Configuration) && PluginReference.IsEnabledForTarget(TargetType); } } } return(bEnabled); }
/// <summary> /// Creates a rules assembly with the given parameters. /// </summary> /// <param name="ProjectFileName">The project file to create rules for. Null for the engine.</param> /// <param name="bUsePrecompiled">Whether to use a precompiled engine</param> /// <param name="bSkipCompile">Whether to skip compilation for this assembly</param> /// <returns>New rules assembly</returns> public static RulesAssembly CreateProjectRulesAssembly(FileReference ProjectFileName, bool bUsePrecompiled, bool bSkipCompile) { // Check if there's an existing assembly for this project RulesAssembly ProjectRulesAssembly; if (!LoadedAssemblyMap.TryGetValue(ProjectFileName, out ProjectRulesAssembly)) { ProjectDescriptor Project = ProjectDescriptor.FromFile(ProjectFileName); // Create the parent assembly RulesAssembly Parent; if (Project.IsEnterpriseProject) { Parent = CreateEnterpriseRulesAssembly(bUsePrecompiled, bSkipCompile); } else { Parent = CreateEngineRulesAssembly(bUsePrecompiled, bSkipCompile); } DirectoryReference MainProjectDirectory = ProjectFileName.Directory; //DirectoryReference MainProjectSourceDirectory = DirectoryReference.Combine(MainProjectDirectory, "Source"); // Create a scope for things in this assembly RulesScope Scope = new RulesScope("Project", Parent.Scope); // Create a new context for modules created by this assembly ModuleRulesContext DefaultModuleContext = new ModuleRulesContext(Scope, MainProjectDirectory); DefaultModuleContext.bCanBuildDebugGame = true; DefaultModuleContext.bCanHotReload = true; DefaultModuleContext.bClassifyAsGameModuleForUHT = true; DefaultModuleContext.bCanUseForSharedPCH = false; // gather modules from project and platforms Dictionary <FileReference, ModuleRulesContext> ModuleFiles = new Dictionary <FileReference, ModuleRulesContext>(); List <FileReference> TargetFiles = new List <FileReference>(); // Find all the project directories List <DirectoryReference> ProjectDirectories = new List <DirectoryReference>(UnrealBuildTool.GetAllProjectDirectories(ProjectFileName)); if (Project.AdditionalRootDirectories != null) { ProjectDirectories.AddRange(Project.AdditionalRootDirectories); } // Find all the rules/plugins under the project source directories foreach (DirectoryReference ProjectDirectory in ProjectDirectories) { DirectoryReference ProjectSourceDirectory = DirectoryReference.Combine(ProjectDirectory, "Source"); AddModuleRulesWithContext(ProjectSourceDirectory, DefaultModuleContext, ModuleFiles); TargetFiles.AddRange(FindAllRulesFiles(ProjectSourceDirectory, RulesFileType.Target)); } // Find all the project plugins List <PluginInfo> ProjectPlugins = new List <PluginInfo>(); ProjectPlugins.AddRange(Plugins.ReadProjectPlugins(MainProjectDirectory)); // Add the project's additional plugin directories plugins too if (Project.AdditionalPluginDirectories != null) { foreach (DirectoryReference AdditionalPluginDirectory in Project.AdditionalPluginDirectories) { ProjectPlugins.AddRange(Plugins.ReadAdditionalPlugins(AdditionalPluginDirectory)); } } // Find all the plugin module rules FindModuleRulesForPlugins(ProjectPlugins, DefaultModuleContext, ModuleFiles); // Add the games project's intermediate source folder DirectoryReference ProjectIntermediateSourceDirectory = DirectoryReference.Combine(MainProjectDirectory, "Intermediate", "Source"); if (DirectoryReference.Exists(ProjectIntermediateSourceDirectory)) { AddModuleRulesWithContext(ProjectIntermediateSourceDirectory, DefaultModuleContext, ModuleFiles); TargetFiles.AddRange(FindAllRulesFiles(ProjectIntermediateSourceDirectory, RulesFileType.Target)); } // Compile the assembly. If there are no module or target files, just use the parent assembly. FileReference AssemblyFileName = FileReference.Combine(MainProjectDirectory, "Intermediate", "Build", "BuildRules", ProjectFileName.GetFileNameWithoutExtension() + "ModuleRules" + FrameworkAssemblyExtension); if (ModuleFiles.Count == 0 && TargetFiles.Count == 0) { ProjectRulesAssembly = Parent; } else { ProjectRulesAssembly = new RulesAssembly(Scope, new List <DirectoryReference> { MainProjectDirectory }, ProjectPlugins, ModuleFiles, TargetFiles, AssemblyFileName, bContainsEngineModules: false, DefaultBuildSettings: null, bReadOnly: UnrealBuildTool.IsProjectInstalled(), bSkipCompile: bSkipCompile, Parent: Parent); } LoadedAssemblyMap.Add(ProjectFileName, ProjectRulesAssembly); } return(ProjectRulesAssembly); }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginDescriptorRequiredForProject(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform, TargetRules.TargetType TargetType, bool bBuildDeveloperTools, bool bBuildEditor) { // Check if it's referenced by name from the project descriptor. If it is, we'll need the plugin to be included with the project regardless of whether it has // any platform-specific modules or content, just so the runtime can make the call. if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, Plugin.Name, true) == 0) { return PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTarget(TargetType); } } } // If the plugin contains content, it should be included for all platforms if(Plugin.Descriptor.bCanContainContent) { return true; } // Check if the plugin has any modules for the given target foreach (ModuleDescriptor Module in Plugin.Descriptor.Modules) { if(Module.IsCompiledInConfiguration(Platform, TargetType, bBuildDeveloperTools, bBuildEditor)) { return true; } } return false; }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginEnabledForProject(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform, TargetRules.TargetType Target) { bool bEnabled = Plugin.Descriptor.bEnabledByDefault; if (Project != null && Project.Plugins != null) { foreach (PluginReferenceDescriptor PluginReference in Project.Plugins) { if (String.Compare(PluginReference.Name, Plugin.Name, true) == 0) { bEnabled = PluginReference.IsEnabledForPlatform(Platform) && PluginReference.IsEnabledForTarget(Target); } } } return bEnabled; }
/// <summary> /// Creates a plugin descriptor from a file on disk /// </summary> /// <param name="FileName">The filename to read</param> /// <returns>New plugin descriptor</returns> public static ProjectDescriptor FromFile(string FileName) { JsonObject RawObject = JsonObject.Read(FileName); try { ProjectDescriptor Descriptor = new ProjectDescriptor(); // Read the version if (!RawObject.TryGetIntegerField("FileVersion", out Descriptor.FileVersion)) { if (!RawObject.TryGetIntegerField("ProjectFileVersion", out Descriptor.FileVersion)) { throw new BuildException("Project descriptor '{0}' does not contain a valid FileVersion entry", FileName); } } // Check it's not newer than the latest version we can parse if (Descriptor.FileVersion > (int)PluginDescriptorVersion.Latest) { throw new BuildException("Project descriptor '{0}' appears to be in a newer version ({1}) of the file format that we can load (max version: {2}).", FileName, Descriptor.FileVersion, (int)ProjectDescriptorVersion.Latest); } // Read simple fields RawObject.TryGetStringField("EngineAssociation", out Descriptor.EngineAssociation); RawObject.TryGetStringField("Category", out Descriptor.Category); RawObject.TryGetStringField("Description", out Descriptor.Description); // Read the modules JsonObject[] ModulesArray; if (RawObject.TryGetObjectArrayField("Modules", out ModulesArray)) { Descriptor.Modules = Array.ConvertAll(ModulesArray, x => ModuleDescriptor.FromJsonObject(x)); } // Read the plugins JsonObject[] PluginsArray; if (RawObject.TryGetObjectArrayField("Plugins", out PluginsArray)) { Descriptor.Plugins = Array.ConvertAll(PluginsArray, x => PluginReferenceDescriptor.FromJsonObject(x)); } string[] Dirs; Descriptor.AdditionalPluginDirectories = new List<DirectoryReference>(); // Read the additional plugin directories if (RawObject.TryGetStringArrayField("AdditionalPluginDirectories", out Dirs)) { for (int Index = 0; Index < Dirs.Length; Index++) { if (Path.IsPathRooted(Dirs[Index])) { // Absolute path so create in place Descriptor.AdditionalPluginDirectories.Add(new DirectoryReference(Dirs[Index])); Log.TraceVerbose("Project ({0}) : Added additional absolute plugin directory ({1})", FileName, Dirs[Index]); } else { // This path is relative to the project path so build that out string RelativePath = Path.Combine(Path.GetDirectoryName(FileName), Dirs[Index]); Descriptor.AdditionalPluginDirectories.Add(new DirectoryReference(RelativePath)); Log.TraceVerbose("Project ({0}) : Added additional relative plugin directory ({1})", FileName, Dirs[Index]); } } } // Read the target platforms RawObject.TryGetStringArrayField("TargetPlatforms", out Descriptor.TargetPlatforms); // Get the sample name hash RawObject.TryGetUnsignedIntegerField("EpicSampleNameHash", out Descriptor.EpicSampleNameHash); // Read the pre and post-build steps CustomBuildSteps.TryRead(RawObject, "PreBuildSteps", out Descriptor.PreBuildSteps); CustomBuildSteps.TryRead(RawObject, "PostBuildSteps", out Descriptor.PostBuildSteps); return Descriptor; } catch (JsonParseException ParseException) { throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName); } }
/// <summary> /// Determine if a plugin is enabled for a given project /// </summary> /// <param name="Project">The project to check</param> /// <param name="Plugin">Information about the plugin</param> /// <param name="Platform">The target platform</param> /// <returns>True if the plugin should be enabled for this project</returns> public static bool IsPluginEnabledForProject(PluginInfo Plugin, ProjectDescriptor Project, UnrealTargetPlatform Platform) { bool bEnabled = Plugin.Descriptor.bEnabledByDefault || Plugin.LoadedFrom == PluginLoadedFrom.GameProject; if(Project != null && Project.Plugins != null) { foreach(PluginReferenceDescriptor PluginReference in Project.Plugins) { if(String.Compare(PluginReference.Name, Plugin.Name, true) == 0) { bEnabled = PluginReference.IsEnabledForPlatform(Platform); } } } return bEnabled; }
/// <summary> /// Creates a plugin descriptor from a file on disk /// </summary> /// <param name="FileName">The filename to read</param> /// <returns>New plugin descriptor</returns> public static ProjectDescriptor FromFile(string FileName) { JsonObject RawObject = JsonObject.Read(FileName); try { ProjectDescriptor Descriptor = new ProjectDescriptor(); // Read the version if (!RawObject.TryGetIntegerField("FileVersion", out Descriptor.FileVersion)) { if (!RawObject.TryGetIntegerField("ProjectFileVersion", out Descriptor.FileVersion)) { throw new BuildException("Project descriptor '{0}' does not contain a valid FileVersion entry", FileName); } } // Check it's not newer than the latest version we can parse if (Descriptor.FileVersion > (int)PluginDescriptorVersion.Latest) { throw new BuildException("Project descriptor '{0}' appears to be in a newer version ({1}) of the file format that we can load (max version: {2}).", FileName, Descriptor.FileVersion, (int)ProjectDescriptorVersion.Latest); } // Read simple fields RawObject.TryGetStringField("EngineAssociation", out Descriptor.EngineAssociation); RawObject.TryGetStringField("Category", out Descriptor.Category); RawObject.TryGetStringField("Description", out Descriptor.Description); // Read the modules JsonObject[] ModulesArray; if (RawObject.TryGetObjectArrayField("Modules", out ModulesArray)) { Descriptor.Modules = Array.ConvertAll(ModulesArray, x => ModuleDescriptor.FromJsonObject(x)); } // Read the plugins JsonObject[] PluginsArray; if (RawObject.TryGetObjectArrayField("Plugins", out PluginsArray)) { Descriptor.Plugins = Array.ConvertAll(PluginsArray, x => PluginReferenceDescriptor.FromJsonObject(x)); } string[] Dirs; Descriptor.AdditionalPluginDirectories = new List <DirectoryReference>(); // Read the additional plugin directories if (RawObject.TryGetStringArrayField("AdditionalPluginDirectories", out Dirs)) { for (int Index = 0; Index < Dirs.Length; Index++) { if (Path.IsPathRooted(Dirs[Index])) { // Absolute path so create in place Descriptor.AdditionalPluginDirectories.Add(new DirectoryReference(Dirs[Index])); Log.TraceVerbose("Project ({0}) : Added additional absolute plugin directory ({1})", FileName, Dirs[Index]); } else { // This path is relative to the project path so build that out string RelativePath = Path.Combine(Path.GetDirectoryName(FileName), Dirs[Index]); Descriptor.AdditionalPluginDirectories.Add(new DirectoryReference(RelativePath)); Log.TraceVerbose("Project ({0}) : Added additional relative plugin directory ({1})", FileName, Dirs[Index]); } } } // Read the target platforms RawObject.TryGetStringArrayField("TargetPlatforms", out Descriptor.TargetPlatforms); // Get the sample name hash RawObject.TryGetUnsignedIntegerField("EpicSampleNameHash", out Descriptor.EpicSampleNameHash); // Read the pre and post-build steps CustomBuildSteps.TryRead(RawObject, "PreBuildSteps", out Descriptor.PreBuildSteps); CustomBuildSteps.TryRead(RawObject, "PostBuildSteps", out Descriptor.PostBuildSteps); return(Descriptor); } catch (JsonParseException ParseException) { throw new JsonParseException("{0} (in {1})", ParseException.Message, FileName); } }