Exemplo n.º 1
0
 /// <summary>
 /// Determines whether a directory is part of the engine
 /// </summary>
 /// <param name="InDirectory"></param>
 /// <returns>true if the directory is under of the engine directories, false if not</returns>
 static public bool IsUnderAnEngineDirectory(DirectoryReference InDirectory)
 {
     // Enterprise modules are considered as engine modules
     return(InDirectory.IsUnderDirectory(UnrealBuildTool.EngineDirectory) ||
            InDirectory.IsUnderDirectory(UnrealBuildTool.EnterpriseSourceDirectory) ||
            InDirectory.IsUnderDirectory(UnrealBuildTool.EnterprisePluginsDirectory) ||
            InDirectory.IsUnderDirectory(UnrealBuildTool.EnterpriseIntermediateDirectory));
 }
Exemplo n.º 2
0
        static bool TryCreateGitWorkingSet(DirectoryReference RootDir, DirectoryReference ProjectDir, out GitSourceFileWorkingSet OutWorkingSet)
        {
            GitSourceFileWorkingSet WorkingSet = null;

            // Create the working set for the engine directory
            if (DirectoryReference.Exists(DirectoryReference.Combine(RootDir, ".git")))
            {
                WorkingSet = new GitSourceFileWorkingSet(GitPath, RootDir, WorkingSet);
            }

            // Try to create a working set for the project directory
            if (ProjectDir != null)
            {
                if (WorkingSet == null || !ProjectDir.IsUnderDirectory(RootDir))
                {
                    if (DirectoryReference.Exists(DirectoryReference.Combine(ProjectDir, ".git")))
                    {
                        WorkingSet = new GitSourceFileWorkingSet(GitPath, ProjectDir, WorkingSet);
                    }
                    else if (DirectoryReference.Exists(DirectoryReference.Combine(ProjectDir.ParentDirectory, ".git")))
                    {
                        WorkingSet = new GitSourceFileWorkingSet(GitPath, ProjectDir.ParentDirectory, WorkingSet);
                    }
                }
            }

            // Set the output value
            OutWorkingSet = WorkingSet;
            return(WorkingSet != null);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get the list of directories that can contain non-foreign projects.
 /// </summary>
 /// <returns>List of directories that can contain non-foreign projects</returns>
 static List <DirectoryReference> GetNonForeignProjectBaseDirs()
 {
     if (NonForeignProjectBaseDirs == null)
     {
         lock (LockObject)
         {
             HashSet <DirectoryReference> BaseDirs = new HashSet <DirectoryReference>();
             foreach (FileReference ProjectDirsFile in DirectoryReference.EnumerateFiles(UnrealBuildTool.RootDirectory, "*.uprojectdirs", SearchOption.TopDirectoryOnly))
             {
                 foreach (string Line in File.ReadAllLines(ProjectDirsFile.FullName))
                 {
                     string TrimLine = Line.Trim();
                     if (!TrimLine.StartsWith(";"))
                     {
                         DirectoryReference BaseProjectDir = DirectoryReference.Combine(UnrealBuildTool.RootDirectory, TrimLine);
                         if (BaseProjectDir.IsUnderDirectory(UnrealBuildTool.RootDirectory))
                         {
                             BaseDirs.Add(BaseProjectDir);
                         }
                         else
                         {
                             Log.TraceWarning("Project search path '{0}' referenced by '{1}' is not under '{2}', ignoring.", TrimLine, ProjectDirsFile, UnrealBuildTool.RootDirectory);
                         }
                     }
                 }
             }
             NonForeignProjectBaseDirs = BaseDirs.ToList();
         }
     }
     return(NonForeignProjectBaseDirs);
 }
        private static string PerformFinalExpansions(string InString, string PlatformName, DirectoryReference ProjectDir)
        {
            string PlatformExtensionEngineConfigDir = DirectoryReference.Combine(UnrealBuildTool.EngineDirectory, "Platforms", PlatformName).FullName;

            string OutString = InString.Replace("{ENGINE}", UnrealBuildTool.EngineDirectory.FullName);

            OutString = OutString.Replace("{EXTENGINE}", PlatformExtensionEngineConfigDir);
            OutString = OutString.Replace("{PLATFORM}", PlatformName);

            if (ProjectDir != null)
            {
                DirectoryReference NFLDir;
                DirectoryReference NRDir;
                if (ProjectDir.IsUnderDirectory(UnrealBuildTool.EngineDirectory))
                {
                    string RelativeDir = ProjectDir.MakeRelativeTo(UnrealBuildTool.EngineDirectory);
                    NFLDir = DirectoryReference.Combine(UnrealBuildTool.EngineDirectory, "Restricted/NotForLicensees", RelativeDir);
                    NRDir  = DirectoryReference.Combine(UnrealBuildTool.EngineDirectory, "Restricted/NoRedist", RelativeDir);
                }
                else
                {
                    NFLDir = DirectoryReference.Combine(ProjectDir, "Restricted/NotForLicensees");
                    NRDir  = DirectoryReference.Combine(ProjectDir, "Restricted/NoRedist");
                }
                string PlatformExtensionProjectConfigDir = DirectoryReference.Combine(ProjectDir, "Platforms", PlatformName).FullName;

                OutString = OutString.Replace("{PROJECT}", ProjectDir.FullName);
                OutString = OutString.Replace("{EXTPROJECT}", PlatformExtensionProjectConfigDir);
                OutString = OutString.Replace("{RESTRICTEDPROJECT_NFL}", NFLDir.FullName);
                OutString = OutString.Replace("{RESTRICTEDPROJECT_NR}", NRDir.FullName);
            }

            return(OutString);
        }
Exemplo n.º 5
0
 public void AddIncludePath(ref string Arguments, DirectoryReference IncludePath)
 {
     if (IncludePath.IsUnderDirectory(UnrealBuildTool.EngineDirectory))
     {
         Arguments += string.Format(" -I\"{0}\"", IncludePath.MakeRelativeTo(UnrealBuildTool.EngineSourceDirectory));
     }
     else
     {
         Arguments += string.Format(" -I\"{0}\"", IncludePath);
     }
 }
        /// <summary>
        /// Finds all the restricted folder names relative to a base directory
        /// </summary>
        /// <param name="BaseDir">The base directory to check against</param>
        /// <param name="OtherDir">The file or directory to check</param>
        /// <returns>Array of restricted folder names</returns>
        public static List <RestrictedFolder> FindRestrictedFolders(DirectoryReference BaseDir, DirectoryReference OtherDir)
        {
            List <RestrictedFolder> Folders = new List <RestrictedFolder>();

            if (OtherDir.IsUnderDirectory(BaseDir))
            {
                foreach (Tuple <FileSystemName, RestrictedFolder> Pair in RestrictedFolderNames)
                {
                    if (OtherDir.ContainsName(Pair.Item1, BaseDir.FullName.Length))
                    {
                        Folders.Add(Pair.Item2);
                    }
                }
            }
            return(Folders);
        }
        /// <summary>
        /// Finds all the restricted folder names relative to a base directory
        /// </summary>
        /// <param name="BaseDir">The base directory to check against</param>
        /// <param name="OtherDir">The file or directory to check</param>
        /// <returns>Array of restricted folder names</returns>
        public static List <RestrictedFolder> FindRestrictedFolders(DirectoryReference BaseDir, DirectoryReference OtherDir)
        {
            List <RestrictedFolder> Folders = new List <RestrictedFolder>();

            if (OtherDir.IsUnderDirectory(BaseDir))
            {
                foreach (RestrictedFolder Value in RestrictedFolder.GetValues())
                {
                    string Name = Value.ToString();
                    if (OtherDir.ContainsName(Name, BaseDir.FullName.Length))
                    {
                        Folders.Add(Value);
                    }
                }
            }
            return(Folders);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Retrieve the list of base directories for native projects
 /// </summary>
 public static IEnumerable <DirectoryReference> EnumerateBaseDirectories()
 {
     if (CachedBaseDirectories == null)
     {
         lock (LockObject)
         {
             if (CachedBaseDirectories == null)
             {
                 HashSet <DirectoryReference> BaseDirs = new HashSet <DirectoryReference>();
                 foreach (FileReference RootFile in DirectoryLookupCache.EnumerateFiles(UnrealBuildTool.RootDirectory))
                 {
                     if (RootFile.HasExtension(".uprojectdirs"))
                     {
                         foreach (string Line in File.ReadAllLines(RootFile.FullName))
                         {
                             string TrimLine = Line.Trim();
                             if (!TrimLine.StartsWith(";"))
                             {
                                 DirectoryReference BaseProjectDir = DirectoryReference.Combine(UnrealBuildTool.RootDirectory, TrimLine);
                                 if (BaseProjectDir.IsUnderDirectory(UnrealBuildTool.RootDirectory))
                                 {
                                     BaseDirs.Add(BaseProjectDir);
                                 }
                                 else
                                 {
                                     Log.TraceWarning("Project search path '{0}' referenced by '{1}' is not under '{2}', ignoring.", TrimLine, RootFile, UnrealBuildTool.RootDirectory);
                                 }
                             }
                         }
                     }
                 }
                 CachedBaseDirectories = BaseDirs;
             }
         }
     }
     return(CachedBaseDirectories);
 }
Exemplo n.º 9
0
        private LinkEnvironment SetupBinaryLinkEnvironment(ReadOnlyTargetRules Target, UEToolChain ToolChain, LinkEnvironment LinkEnvironment, CppCompileEnvironment CompileEnvironment, FileReference SingleFileToCompile, ISourceFileWorkingSet WorkingSet, DirectoryReference ExeDir, TargetMakefile Makefile)
        {
            LinkEnvironment         BinaryLinkEnvironment         = new LinkEnvironment(LinkEnvironment);
            HashSet <UEBuildModule> LinkEnvironmentVisitedModules = new HashSet <UEBuildModule>();
            List <UEBuildBinary>    BinaryDependencies            = new List <UEBuildBinary>();

            CppCompileEnvironment BinaryCompileEnvironment = CreateBinaryCompileEnvironment(CompileEnvironment);

            if (BinaryCompileEnvironment.bUseSharedBuildEnvironment && Target.ProjectFile != null && IntermediateDirectory.IsUnderDirectory(Target.ProjectFile.Directory))
            {
                BinaryCompileEnvironment.bUseSharedBuildEnvironment = false;
            }

            foreach (UEBuildModule Module in Modules)
            {
                List <FileItem> LinkInputFiles;
                if (Module.Binary == null || Module.Binary == this)
                {
                    // Compile each module.
                    Log.TraceVerbose("Compile module: " + Module.Name);
                    LinkInputFiles = Module.Compile(Target, ToolChain, BinaryCompileEnvironment, SingleFileToCompile, WorkingSet, Makefile);

                    // Save the module outputs. In monolithic builds, this is just the object files.
                    if (Target.LinkType == TargetLinkType.Monolithic)
                    {
                        Makefile.ModuleNameToOutputItems[Module.Name] = LinkInputFiles.ToArray();
                    }

                    // NOTE: Because of 'Shared PCHs', in monolithic builds the same PCH file may appear as a link input
                    // multiple times for a single binary.  We'll check for that here, and only add it once.  This avoids
                    // a linker warning about redundant .obj files.
                    foreach (FileItem LinkInputFile in LinkInputFiles)
                    {
                        if (!BinaryLinkEnvironment.InputFiles.Contains(LinkInputFile))
                        {
                            BinaryLinkEnvironment.InputFiles.Add(LinkInputFile);
                        }
                    }

                    // Force a reference to initialize module for this binary
                    if (Module.Rules.bRequiresImplementModule.Value)
                    {
                        BinaryLinkEnvironment.IncludeFunctions.Add(String.Format("IMPLEMENT_MODULE_{0}", Module.Name));
                    }
                }
                else
                {
                    BinaryDependencies.Add(Module.Binary);
                }

                // Allow the module to modify the link environment for the binary.
                Module.SetupPrivateLinkEnvironment(this, BinaryLinkEnvironment, BinaryDependencies, LinkEnvironmentVisitedModules, ExeDir);
            }


            // Allow the binary dependencies to modify the link environment.
            foreach (UEBuildBinary BinaryDependency in BinaryDependencies)
            {
                BinaryDependency.SetupDependentLinkEnvironment(BinaryLinkEnvironment);
            }

            // Set the link output file.
            BinaryLinkEnvironment.OutputFilePaths = OutputFilePaths.ToList();

            // Set whether the link is allowed to have exports.
            BinaryLinkEnvironment.bHasExports = bAllowExports;

            // Set the output folder for intermediate files
            BinaryLinkEnvironment.IntermediateDirectory = IntermediateDirectory;

            // Put the non-executable output files (PDB, import library, etc) in the same directory as the production
            BinaryLinkEnvironment.OutputDirectory = OutputFilePaths[0].Directory;

            // Setup link output type
            BinaryLinkEnvironment.bIsBuildingDLL     = IsBuildingDll(Type);
            BinaryLinkEnvironment.bIsBuildingLibrary = IsBuildingLibrary(Type);

            // If we don't have any resource file, use the default or compile a custom one for this module
            if (BinaryLinkEnvironment.Platform == UnrealTargetPlatform.Win32 || BinaryLinkEnvironment.Platform == UnrealTargetPlatform.Win64)
            {
                // Figure out if this binary has any custom resource files. Hacky check to ignore the resource file in the Launch module, since it contains dialogs that the engine needs and always needs to be included.
                FileItem[] CustomResourceFiles = BinaryLinkEnvironment.InputFiles.Where(x => x.Location.HasExtension(".res") && !x.Location.FullName.EndsWith("\\Launch\\PCLaunch.rc.res", StringComparison.OrdinalIgnoreCase)).ToArray();
                if (CustomResourceFiles.Length == 0)
                {
                    if (BinaryLinkEnvironment.DefaultResourceFiles.Count > 0)
                    {
                        // Use the default resource file if possible
                        BinaryLinkEnvironment.InputFiles.AddRange(BinaryLinkEnvironment.DefaultResourceFiles);
                    }
                    else
                    {
                        // Get the intermediate directory
                        DirectoryReference ResourceIntermediateDirectory = BinaryLinkEnvironment.IntermediateDirectory;

                        // Create a compile environment for resource files
                        CppCompileEnvironment ResourceCompileEnvironment = new CppCompileEnvironment(BinaryCompileEnvironment);

                        // @todo: This should be in some Windows code somewhere...
                        // Set the original file name macro; used in Default.rc2 to set the binary metadata fields.
                        ResourceCompileEnvironment.Definitions.Add("ORIGINAL_FILE_NAME=\"" + OutputFilePaths[0].GetFileName() + "\"");

                        // Set the other version fields
                        ResourceCompileEnvironment.Definitions.Add(String.Format("BUILT_FROM_CHANGELIST={0}", Target.Version.Changelist));
                        ResourceCompileEnvironment.Definitions.Add(String.Format("BUILD_VERSION={0}", Target.BuildVersion));

                        // Otherwise compile the default resource file per-binary, so that it gets the correct ORIGINAL_FILE_NAME macro.
                        FileItem  DefaultResourceFile   = FileItem.GetItemByFileReference(FileReference.Combine(UnrealBuildTool.EngineDirectory, "Build", "Windows", "Resources", "Default.rc2"));
                        CPPOutput DefaultResourceOutput = ToolChain.CompileRCFiles(ResourceCompileEnvironment, new List <FileItem> {
                            DefaultResourceFile
                        }, ResourceIntermediateDirectory, Makefile.Actions);
                        BinaryLinkEnvironment.InputFiles.AddRange(DefaultResourceOutput.ObjectFiles);
                    }
                }
            }

            // Add all the common resource files
            BinaryLinkEnvironment.InputFiles.AddRange(BinaryLinkEnvironment.CommonResourceFiles);

            return(BinaryLinkEnvironment);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Discover and fill in the project info
        /// </summary>
        public static void FillProjectInfo()
        {
            DateTime StartTime = DateTime.Now;

            List <DirectoryInfo> DirectoriesToSearch = new List <DirectoryInfo>();

            // Find all the .uprojectdirs files contained in the root folder and add their entries to the search array
            string EngineSourceDirectory = Path.GetFullPath(Path.Combine(RootDirectory, "Engine", "Source"));

            foreach (FileReference ProjectDirsFile in DirectoryReference.EnumerateFiles(UnrealBuildTool.RootDirectory, "*.uprojectdirs", SearchOption.TopDirectoryOnly))
            {
                Log.TraceVerbose("\tFound uprojectdirs file {0}", ProjectDirsFile.FullName);
                foreach (string Line in File.ReadAllLines(ProjectDirsFile.FullName))
                {
                    string TrimLine = Line.Trim();
                    if (!TrimLine.StartsWith(";"))
                    {
                        DirectoryReference BaseProjectDir = DirectoryReference.Combine(UnrealBuildTool.RootDirectory, TrimLine);
                        if (BaseProjectDir.IsUnderDirectory(UnrealBuildTool.RootDirectory))
                        {
                            DirectoriesToSearch.Add(new DirectoryInfo(BaseProjectDir.FullName));
                        }
                        else
                        {
                            Log.TraceWarning("Project search path '{0}' is not under root directory, ignoring.", TrimLine);
                        }
                    }
                }
            }

            Log.TraceVerbose("\tFound {0} directories to search", DirectoriesToSearch.Count);

            foreach (DirectoryInfo DirToSearch in DirectoriesToSearch)
            {
                Log.TraceVerbose("\t\tSearching {0}", DirToSearch.FullName);
                if (DirToSearch.Exists)
                {
                    foreach (DirectoryInfo SubDir in DirToSearch.EnumerateDirectories())
                    {
                        Log.TraceVerbose("\t\t\tFound subdir {0} ({1})", SubDir.FullName, SubDir.Name);
                        foreach (FileInfo UProjFile in SubDir.EnumerateFiles("*.uproject", SearchOption.TopDirectoryOnly))
                        {
                            Log.TraceVerbose("\t\t\t\t{0}", UProjFile.FullName);
                            AddProject(new FileReference(UProjFile));
                        }
                    }
                }
                else
                {
                    Log.TraceVerbose("ProjectInfo: Skipping directory {0} from .uprojectdirs file as it doesn't exist.", DirToSearch);
                }
            }

            DateTime StopTime = DateTime.Now;

            if (UnrealBuildTool.bPrintPerformanceInfo)
            {
                TimeSpan TotalProjectInfoTime = StopTime - StartTime;
                Log.TraceInformation("FillProjectInfo took {0} milliseconds", TotalProjectInfoTime.TotalMilliseconds);
            }
        }