internal string GetEngineSuffix()
        {
            //grab first project listed in order to resolve ini path
            string iniPath = "";
            List <UProjectInfo> projects = UProjectInfo.FilterGameProjects(false, null);

            foreach (UProjectInfo upi in projects)
            {
                iniPath = upi.Folder.FullName;
                break;
            }

            //no INI, default to CPU
            if (iniPath.Length == 0)
            {
                return("CPU");
            }

            //We can't use the ConfigCacheIni file here because it bypasses the Substance section.
            try
            {
                iniPath = Path.Combine(iniPath, Path.Combine("Config", "DefaultEngine.ini"));

                //parse INI file line by line until we find our result
                StreamReader file = new StreamReader(iniPath);
                string       line;
                string       suffix     = "CPU";
                string       startsWith = "SubstanceEngine=";
                while ((line = file.ReadLine()) != null)
                {
                    if (line.StartsWith(startsWith))
                    {
                        string value = line.Substring(startsWith.Length);

                        if (value == "SET_CPU")
                        {
                            suffix = "CPU";
                        }
                        else if (value == "SET_GPU")
                        {
                            suffix = "GPU";
                        }

                        break;
                    }
                }

                return(suffix);
            }
            catch (Exception)
            {
                return("CPU");
            }
        }
Esempio n. 2
0
        private static void FindAndCompileScriptModules(string ScriptsForProjectFileName, List <string> AdditionalScriptsFolders)
        {
            Log.TraceInformation("Compiling scripts.");

            var OldCWD             = Environment.CurrentDirectory;
            var UnrealBuildToolCWD = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, "Engine", "Source");

            Environment.CurrentDirectory = UnrealBuildToolCWD;

            // Configure the rules compiler
            // Get all game folders and convert them to build subfolders.
            List <DirectoryReference> AllGameFolders;

            if (ScriptsForProjectFileName == null)
            {
                AllGameFolders = UProjectInfo.FilterGameProjects(true, null).Select(x => x.Folder).ToList();
            }
            else
            {
                AllGameFolders = new List <DirectoryReference> {
                    new DirectoryReference(Path.GetDirectoryName(ScriptsForProjectFileName))
                };
            }

            var AllAdditionalScriptFolders = new List <DirectoryReference>(AdditionalScriptsFolders.Select(x => new DirectoryReference(x)));

            foreach (var Folder in AllGameFolders)
            {
                var GameBuildFolder = DirectoryReference.Combine(Folder, "Build");
                if (DirectoryReference.Exists(GameBuildFolder))
                {
                    AllAdditionalScriptFolders.Add(GameBuildFolder);
                }
            }

            Log.TraceVerbose("Discovering game folders.");

            var DiscoveredModules = UnrealBuildTool.RulesCompiler.FindAllRulesSourceFiles(UnrealBuildTool.RulesCompiler.RulesFileType.AutomationModule, GameFolders: AllGameFolders, ForeignPlugins: null, AdditionalSearchPaths: AllAdditionalScriptFolders);
            var ModulesToCompile  = new List <string>(DiscoveredModules.Count);

            foreach (var ModuleFilename in DiscoveredModules)
            {
                if (HostPlatform.Current.IsScriptModuleSupported(ModuleFilename.GetFileNameWithoutAnyExtensions()))
                {
                    ModulesToCompile.Add(ModuleFilename.FullName);
                }
                else
                {
                    CommandUtils.LogVerbose("Script module {0} filtered by the Host Platform and will not be compiled.", ModuleFilename);
                }
            }

            if ((UnrealBuildTool.BuildHostPlatform.Current.Platform == UnrealBuildTool.UnrealTargetPlatform.Win64) ||
                (UnrealBuildTool.BuildHostPlatform.Current.Platform == UnrealBuildTool.UnrealTargetPlatform.Win32))
            {
                string Modules = string.Join(";", ModulesToCompile.ToArray());
                var    UATProj = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, @"Engine\Source\Programs\AutomationTool\Scripts\UAT.proj");
                var    CmdLine = String.Format("\"{0}\" /p:Modules=\"{1}\" /p:Configuration={2} /verbosity:minimal /nologo", UATProj, Modules, BuildConfig);
                // suppress the run command because it can be long and intimidating, making the logs around this code harder to read.
                var Result = CommandUtils.Run(CommandUtils.CmdEnv.MsBuildExe, CmdLine, Options: CommandUtils.ERunOptions.Default | CommandUtils.ERunOptions.NoLoggingOfRunCommand | CommandUtils.ERunOptions.LoggingOfRunDuration);
                if (Result.ExitCode != 0)
                {
                    throw new AutomationException(String.Format("Failed to build \"{0}\":{1}{2}", UATProj, Environment.NewLine, Result.Output));
                }
            }
            else
            {
                CompileModules(ModulesToCompile);
            }


            Environment.CurrentDirectory = OldCWD;
        }