예제 #1
0
        public override ExitCode Execute()
        {
            string EditorPath = HostPlatform.Current.GetUE4ExePath("UE4Editor");

            string EditorArgs = "";

            ProjectName = ParseParamValue("project", ProjectName);

            if (!String.IsNullOrEmpty(ProjectName))
            {
                FileReference ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectName);

                if (ProjectFile == null)
                {
                    throw new AutomationException("Unable to find uproject file for {0}", ProjectName);
                }

                EditorArgs = ProjectFile.FullName;
            }

            Run(EditorPath, EditorArgs, null, ERunOptions.NoWaitForExit);

            return(ExitCode.Success);
        }
예제 #2
0
        public override ExitCode Execute()
        {
            string[] Arguments = this.Params;

            ProjectName    = ParseParamValue("project", ProjectName);
            Targets        = ParseParamValue("target", Targets);
            Platforms      = ParseParamValue("platform", Platforms);
            Configurations = ParseParamValue("configuration", Configurations);
            Clean          = ParseParam("clean") || Clean;

            if (string.IsNullOrEmpty(Targets))
            {
                throw new AutomationException("No target specified with -target. Use -help to see all options");
            }

            bool NoTools = ParseParam("notools");

            IEnumerable <string> TargetList = Targets.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
            IEnumerable <UnrealTargetConfiguration> ConfigurationList = null;
            IEnumerable <UnrealTargetPlatform>      PlatformList      = null;

            try
            {
                ConfigurationList = Configurations.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Select(C => (UnrealTargetConfiguration)Enum.Parse(typeof(UnrealTargetConfiguration), C, true)).ToArray();
            }
            catch (Exception Ex)
            {
                LogError("Failed to parse configuration string. {0}", Ex.Message);
                return(ExitCode.Error_Arguments);
            }

            try
            {
                PlatformList = Platforms.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)
                               .Select(C =>
                {
                    UnrealTargetPlatform Platform;
                    if (!UnrealTargetPlatform.TryParse(C, out Platform))
                    {
                        throw new AutomationException("No such platform {0}", C);
                    }
                    return(Platform);
                }).ToArray();
            }
            catch (Exception Ex)
            {
                LogError("Failed to parse configuration string. {0}", Ex.Message);
                return(ExitCode.Error_Arguments);
            }

            FileReference ProjectFile = null;

            if (!string.IsNullOrEmpty(ProjectName))
            {
                ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectName);

                if (ProjectFile == null)
                {
                    throw new AutomationException("Unable to find uproject file for {0}", ProjectName);
                }

                string SourceDirectoryName = Path.Combine(ProjectFile.Directory.FullName, "Source");

                if (Directory.Exists(SourceDirectoryName))
                {
                    IEnumerable <string> TargetScripts = Directory.EnumerateFiles(SourceDirectoryName, "*.Target.cs");

                    foreach (string TargetName in TargetList)
                    {
                        string TargetScript = TargetScripts.Where(S => S.IndexOf(TargetName, StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();

                        if (TargetScript == null && (
                                TargetName.Equals("Client", StringComparison.OrdinalIgnoreCase) ||
                                TargetName.Equals("Game", StringComparison.OrdinalIgnoreCase)
                                )
                            )
                        {
                            // if there's no ProjectGame.Target.cs or ProjectClient.Target.cs then
                            // fallback to Project.Target.cs
                            TargetScript = TargetScripts.Where(S => S.IndexOf(ProjectName + ".", StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();
                        }

                        if (TargetScript == null)
                        {
                            throw new AutomationException("No Target.cs file for target {0} in project {1}", TargetName, ProjectName);
                        }

                        string FullName = Path.GetFileName(TargetScript);
                        TargetNames[TargetName] = Regex.Replace(FullName, ".Target.cs", "", RegexOptions.IgnoreCase);
                    }
                }
            }
            else
            {
                Log.TraceWarning("No project specified, will build vanilla UE4 binaries");
            }

            // Handle content-only projects or when no project was specified
            if (TargetNames.Keys.Count == 0)
            {
                foreach (string TargetName in TargetList)
                {
                    TargetNames[TargetName] = string.Format("UE4{0}", TargetName);
                }
            }

            UE4Build Build = new UE4Build(this);

            UE4Build.BuildAgenda Agenda = new UE4Build.BuildAgenda();

            string EditorTarget = TargetList.Where(T => T.EndsWith("Editor", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            IEnumerable <string> OtherTargets = TargetList.Where(T => T != EditorTarget);

            UnrealTargetPlatform CurrentPlatform = HostPlatform.Current.HostEditorPlatform;

            if (!NoTools)
            {
                Agenda.AddTarget("UnrealHeaderTool", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile);
            }

            if (string.IsNullOrEmpty(EditorTarget) == false)
            {
                string TargetName = TargetNames[EditorTarget];

                Agenda.AddTarget(TargetName, CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile);

                if (!NoTools)
                {
                    Agenda.AddTarget("UnrealPak", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile);
                    Agenda.AddTarget("ShaderCompileWorker", CurrentPlatform, UnrealTargetConfiguration.Development);
                    Agenda.AddTarget("UnrealLightmass", CurrentPlatform, UnrealTargetConfiguration.Development);
                    Agenda.AddTarget("CrashReportClient", CurrentPlatform, UnrealTargetConfiguration.Shipping);
                    Agenda.AddTarget("CrashReportClientEditor", CurrentPlatform, UnrealTargetConfiguration.Shipping);
                }
            }

            foreach (string Target in OtherTargets)
            {
                string TargetName = TargetNames[Target];

                bool IsServer = Target.EndsWith("Server", StringComparison.OrdinalIgnoreCase);

                IEnumerable <UnrealTargetPlatform> PlatformsToBuild = IsServer ? new UnrealTargetPlatform[] { CurrentPlatform } : PlatformList;

                foreach (UnrealTargetPlatform Platform in PlatformsToBuild)
                {
                    foreach (UnrealTargetConfiguration Config in ConfigurationList)
                    {
                        Agenda.AddTarget(TargetName, Platform, Config);
                    }
                }
            }

            // Set clean and log
            foreach (var Target in Agenda.Targets)
            {
                if (Clean)
                {
                    Target.Clean = Clean;
                }

                Log.TraceInformation("Will {0}build {1}", Clean ? "clean and " : "", Target);
            }

            Build.Build(Agenda, InUpdateVersionFiles: false);

            return(ExitCode.Success);
        }
예제 #3
0
        public override ExitCode Execute()
        {
            string[] Arguments = this.Params;

            ProjectName    = ParseParamValue("project", ProjectName);
            Targets        = ParseParamValue("target", Targets);
            Platforms      = ParseParamValue("platform", Platforms);
            Configurations = ParseParamValue("configuration", Configurations);
            Clean          = ParseParam("clean") || Clean;
            NoTools        = ParseParam("NoTools") || NoTools;
            UBTArgs        = ParseParamValue("ubtargs", UBTArgs);
            Preview        = ParseParam("preview") || Preview;

            if (string.IsNullOrEmpty(Targets))
            {
                throw new AutomationException("No target specified with -target. Use -help to see all options");
            }

            IEnumerable <string> TargetList = Targets.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
            IEnumerable <UnrealTargetConfiguration> ConfigurationList = null;
            IEnumerable <UnrealTargetPlatform>      PlatformList      = null;

            try
            {
                ConfigurationList = Configurations.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)
                                    .Select(C => (UnrealTargetConfiguration)Enum.Parse(typeof(UnrealTargetConfiguration), C, true)).ToArray();
            }
            catch (Exception Ex)
            {
                LogError("Failed to parse configuration string. {0}", Ex.Message);
                return(ExitCode.Error_Arguments);
            }

            try
            {
                PlatformList = Platforms.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)
                               .Select(C =>
                {
                    UnrealTargetPlatform Platform;
                    if (!UnrealTargetPlatform.TryParse(C, out Platform))
                    {
                        throw new AutomationException("No such platform {0}", C);
                    }
                    return(Platform);
                }).ToArray();
            }
            catch (Exception Ex)
            {
                LogError("Failed to parse configuration string. {0}", Ex.Message);
                return(ExitCode.Error_Arguments);
            }

            FileReference ProjectFile = null;

            if (!string.IsNullOrEmpty(ProjectName))
            {
                // find the project
                ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectName);

                if (ProjectFile == null)
                {
                    throw new AutomationException("Unable to find uproject file for {0}", ProjectName);
                }
            }

            IEnumerable <string> BuildTargets = TargetList.Select(T => ProjectTargetFromTarget(T, ProjectFile)).ToArray();

            bool ContainsEditor = BuildTargets.Where(T => T.EndsWith("Editor", StringComparison.OrdinalIgnoreCase)).Any();
            bool SingleBuild    = BuildTargets.Count() == 1 && PlatformList.Count() == 1 && ConfigurationList.Count() == 1;

            if (!SingleBuild || (ContainsEditor && !NoTools))
            {
                UE4Build Build = new UE4Build(this);
                Build.AlwaysBuildUHT = true;

                UE4Build.BuildAgenda Agenda = new UE4Build.BuildAgenda();

                string EditorTarget = BuildTargets.Where(T => T.EndsWith("Editor", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                IEnumerable <string> OtherTargets = BuildTargets.Where(T => T != EditorTarget);

                UnrealTargetPlatform CurrentPlatform = HostPlatform.Current.HostEditorPlatform;

                if (string.IsNullOrEmpty(EditorTarget) == false)
                {
                    Agenda.AddTarget(EditorTarget, CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);

                    if (!NoTools)
                    {
                        Agenda.AddTarget("UnrealPak", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);
                        Agenda.AddTarget("ShaderCompileWorker", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);
                        Agenda.AddTarget("UnrealLightmass", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);
                        Agenda.AddTarget("CrashReportClient", CurrentPlatform, UnrealTargetConfiguration.Shipping, ProjectFile, UBTArgs);
                        Agenda.AddTarget("CrashReportClientEditor", CurrentPlatform, UnrealTargetConfiguration.Shipping, ProjectFile, UBTArgs);
                    }
                }

                foreach (string Target in OtherTargets)
                {
                    bool IsServer = Target.EndsWith("Server", StringComparison.OrdinalIgnoreCase);

                    IEnumerable <UnrealTargetPlatform> PlatformsToBuild = IsServer ? new UnrealTargetPlatform[] { CurrentPlatform } : PlatformList;

                    foreach (UnrealTargetPlatform Platform in PlatformsToBuild)
                    {
                        foreach (UnrealTargetConfiguration Config in ConfigurationList)
                        {
                            Agenda.AddTarget(Target, Platform, Config, ProjectFile, UBTArgs);
                        }
                    }
                }

                foreach (var Target in Agenda.Targets)
                {
                    Log.TraceInformation("Will {0}build {1}", Clean ? "clean and " : "", Target);
                    if (Clean)
                    {
                        Target.Clean = Clean;
                    }
                }

                if (!Preview)
                {
                    Build.Build(Agenda, InUpdateVersionFiles: false);
                }
            }
            else
            {
                // Get the path to UBT
                FileReference InstalledUBT = FileReference.Combine(CommandUtils.EngineDirectory, "Binaries", "DotNET", "UnrealBuildTool.exe");

                UnrealTargetPlatform      PlatformToBuild = PlatformList.First();
                UnrealTargetConfiguration ConfigToBuild   = ConfigurationList.First();
                string TargetToBuild = BuildTargets.First();

                if (!Preview)
                {
                    // Compile the editor
                    string CommandLine = CommandUtils.UBTCommandline(ProjectFile, TargetToBuild, PlatformToBuild, ConfigToBuild, UBTArgs);

                    if (Clean)
                    {
                        CommandUtils.RunUBT(CommandUtils.CmdEnv, InstalledUBT.FullName, CommandLine + " -clean");
                    }
                    CommandUtils.RunUBT(CommandUtils.CmdEnv, InstalledUBT.FullName, CommandLine);
                }
                else
                {
                    Log.TraceInformation("Will {0}build {1} {2} {3}", Clean ? "clean and " : "", TargetToBuild, PlatformToBuild, ConfigToBuild);
                }
            }

            return(ExitCode.Success);
        }