/// <summary> /// Sends an arbitrary HTTP request /// </summary> /// <param name="Url">Endpoint to send to</param> /// <param name="Method">The method to use for sending the request</param> /// <param name="BodyObject">Object to be serialized as json in the body</param> /// <returns>HTTP response</returns> HttpWebResponse SendHttpRequest(string Url, string Method, object BodyObject) { // Create the request HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Url); Request.ContentType = "application/json"; Request.Method = Method; string BodyText = null; if (BodyObject != null) { BodyText = new JavaScriptSerializer().Serialize(BodyObject); byte[] BodyData = Encoding.UTF8.GetBytes(BodyText); using (Stream RequestStream = Request.GetRequestStream()) { RequestStream.Write(BodyData, 0, BodyData.Length); } } // Read the response try { return((HttpWebResponse)Request.GetResponse()); } catch (Exception Ex) { ExceptionUtils.AddContext(Ex, String.Format("Url: {0}", Url)); ExceptionUtils.AddContext(Ex, String.Format("Method: {0}", Method)); ExceptionUtils.AddContext(Ex, String.Format("Body: {0}", BodyText)); throw; } }
/// <summary> /// Build all the tasks for this node /// </summary> /// <param name="Job">Information about the current job</param> /// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include. Should be set to contain the node inputs on entry.</param> /// <returns>Whether the task succeeded or not. Exiting with an exception will be caught and treated as a failure.</returns> public bool Build(JobContext Job, Dictionary <string, HashSet <FileReference> > TagNameToFileSet) { // Run each of the tasks in order HashSet <FileReference> BuildProducts = TagNameToFileSet[DefaultOutput.TagName]; for (int Idx = 0; Idx < Tasks.Count; Idx++) { ITaskExecutor Executor = Tasks[Idx].GetExecutor(); if (Executor == null) { // Execute this task directly try { Tasks[Idx].Execute(Job, BuildProducts, TagNameToFileSet); } catch (Exception Ex) { ExceptionUtils.AddContext(Ex, "while executing task {0}", Tasks[Idx].GetTraceString()); if (Tasks[Idx].SourceLocation != null) { ExceptionUtils.AddContext(Ex, "at {0}({1})", GetReadablePathForDiagnostics(Tasks[Idx].SourceLocation.Item1), Tasks[Idx].SourceLocation.Item2); } throw; } } else { // The task has a custom executor, which may be able to execute several tasks simultaneously. Try to add the following tasks. int FirstIdx = Idx; while (Idx + 1 < Tasks.Count && Executor.Add(Tasks[Idx + 1])) { Idx++; } try { Executor.Execute(Job, BuildProducts, TagNameToFileSet); } catch (Exception Ex) { for (int TaskIdx = FirstIdx; TaskIdx <= Idx; TaskIdx++) { ExceptionUtils.AddContext(Ex, "while executing {0}", Tasks[TaskIdx].GetTraceString()); } if (Tasks[FirstIdx].SourceLocation != null) { ExceptionUtils.AddContext(Ex, "at {0}({1})", GetReadablePathForDiagnostics(Tasks[FirstIdx].SourceLocation.Item1), Tasks[FirstIdx].SourceLocation.Item2); } throw; } } } // Remove anything that doesn't exist, since these files weren't explicitly tagged BuildProducts.RemoveWhere(x => !FileReference.Exists(x)); return(true); }
public override void ExecuteBuild() { CommandUtils.LogInformation("************************* List Third Party Software"); string ProjectPath = ParseParamValue("Project", String.Empty); //Add quotes to avoid issues with spaces in project path if (ProjectPath != String.Empty) { ProjectPath = "\"" + ProjectPath + "\""; } // Parse the list of targets to list TPS for. Each target is specified by -Target="Name|Configuration|Platform" on the command line. HashSet <FileReference> TpsFiles = new HashSet <FileReference>(); foreach (string Target in ParseParamValues(Params, "Target")) { // Get the path to store the exported JSON target data FileReference OutputFile = FileReference.Combine(CommandUtils.EngineDirectory, "Intermediate", "Build", "ThirdParty.json"); IProcessResult Result; Result = Run(UE4Build.GetUBTExecutable(), String.Format("{0} {1} -Mode=JsonExport -OutputFile=\"{2}\"", Target.Replace('|', ' '), ProjectPath, OutputFile.FullName), Options: ERunOptions.Default); if (Result.ExitCode != 0) { throw new AutomationException("Failed to run UBT"); } // Read the exported target info back in JsonObject Object = JsonObject.Read(OutputFile); // Get the project file if there is one FileReference ProjectFile = null; string ProjectFileName; if (Object.TryGetStringField("ProjectFile", out ProjectFileName)) { ProjectFile = new FileReference(ProjectFileName); } // Get the default paths to search HashSet <DirectoryReference> DirectoriesToScan = new HashSet <DirectoryReference>(); DirectoriesToScan.Add(DirectoryReference.Combine(CommandUtils.EngineDirectory, "Shaders")); DirectoriesToScan.Add(DirectoryReference.Combine(CommandUtils.EngineDirectory, "Content")); if (ProjectFile != null) { DirectoriesToScan.Add(DirectoryReference.Combine(ProjectFile.Directory, "Content")); } // Add all the paths for each module, and its runtime dependencies JsonObject Modules = Object.GetObjectField("Modules"); foreach (string ModuleName in Modules.KeyNames) { JsonObject Module = Modules.GetObjectField(ModuleName); DirectoriesToScan.Add(new DirectoryReference(Module.GetStringField("Directory"))); foreach (JsonObject RuntimeDependency in Module.GetObjectArrayField("RuntimeDependencies")) { string RuntimeDependencyPath; if (RuntimeDependency.TryGetStringField("SourcePath", out RuntimeDependencyPath) || RuntimeDependency.TryGetStringField("Path", out RuntimeDependencyPath)) { List <FileReference> Files = FileFilter.ResolveWildcard(DirectoryReference.Combine(CommandUtils.EngineDirectory, "Source"), RuntimeDependencyPath); DirectoriesToScan.UnionWith(Files.Select(x => x.Directory)); } } } // Remove any directories that are under other directories, and sort the output list List <DirectoryReference> SortedDirectoriesToScan = new List <DirectoryReference>(); foreach (DirectoryReference DirectoryToScan in DirectoriesToScan.OrderBy(x => x.FullName)) { if (SortedDirectoriesToScan.Count == 0 || !DirectoryToScan.IsUnderDirectory(SortedDirectoriesToScan[SortedDirectoriesToScan.Count - 1])) { SortedDirectoriesToScan.Add(DirectoryToScan); } } // Get the platforms to exclude List <UnrealTargetPlatform> SupportedPlatforms = new List <UnrealTargetPlatform> { UnrealTargetPlatform.Parse(Object.GetStringField("Platform")) }; string[] ExcludePlatformNames = Utils.MakeListOfUnsupportedPlatforms(SupportedPlatforms).ToArray(); // Find all the TPS files under the engine directory which match foreach (DirectoryReference DirectoryToScan in SortedDirectoriesToScan) { foreach (FileReference TpsFile in DirectoryReference.EnumerateFiles(DirectoryToScan, "*.tps", SearchOption.AllDirectories)) { if (!TpsFile.ContainsAnyNames(ExcludePlatformNames, DirectoryToScan)) { TpsFiles.Add(TpsFile); } } } } // Also add any redirects List <string> OutputMessages = new List <string>(); foreach (FileReference TpsFile in TpsFiles) { string Message = TpsFile.FullName; try { string[] Lines = FileReference.ReadAllLines(TpsFile); foreach (string Line in Lines) { const string RedirectPrefix = "Redirect:"; int Idx = Line.IndexOf(RedirectPrefix, StringComparison.InvariantCultureIgnoreCase); if (Idx >= 0) { FileReference RedirectTpsFile = FileReference.Combine(TpsFile.Directory, Line.Substring(Idx + RedirectPrefix.Length).Trim()); Message = String.Format("{0} (redirect from {1})", RedirectTpsFile.FullName, TpsFile.FullName); break; } } } catch (Exception Ex) { ExceptionUtils.AddContext(Ex, "while processing {0}", TpsFile); throw; } OutputMessages.Add(Message); } OutputMessages.Sort(); // Print them all out foreach (string OutputMessage in OutputMessages) { CommandUtils.LogInformation(OutputMessage); } }