Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/Scripts/AnalyzeThirdPartyLibs.Automation.cs
Ben Marsh 1ae32843fa Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3058348)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2982033 on 2016/05/18 by Chad.Garyet

	Checking in progress on the ue4 BuildGraph conversion.
	Builds and Compiles editor and game on all platforms
	Builds DDC on win64 and mac
	Builds Tools on win64

Change 3047983 on 2016/07/13 by Ben.Marsh

	PR #2597: Fix P4 environment used for running BuildUGS commandlet (Contributed by paulevans)

Change 3048267 on 2016/07/13 by Ben.Marsh

	BuildGraph: Allow more permissive list of characters for node names; just restrict against characters which are illegal in filenames. Allows creating aggregate names which match job names (eg. "Editor, Tools & Monolithics").

Change 3048293 on 2016/07/13 by Ben.Marsh

	BuildGraph: Allow passing -listonly without a specific -target=... parameter in BuildGraph, to see the contents of the entire script.

Change 3048454 on 2016/07/13 by Ben.Marsh

	BuildGraph: Disable output of error messages when just printing the contents of the graph.

Change 3048507 on 2016/07/13 by Ben.Marsh

	BuildGraph: Rename "Ticket" to "Token" for files used to ensure exclusive access to run part of a build.

Change 3049459 on 2016/07/14 by Matthew.Griffin

	Updated location of HTML5 SDKs for Installed Builds
	#jira UE-32171

Change 3049675 on 2016/07/14 by Matthew.Griffin

	Ensured that all platforms are registered when running -validateplatform command
	#jira UE-31082

Change 3049922 on 2016/07/14 by Ben.Marsh

	UBT: Fix path to XML config file in boilerplate message.

Change 3051483 on 2016/07/15 by Ben.Marsh

	EC: Remove code to prettify node names, now that we can have pretty node names explicitly.

Change 3051522 on 2016/07/15 by Ben.Marsh

	BuildGraph: Change spawn task to fail if a non-zero exit code is returned by an external program. The minimum exit code to be treated as an error can be set using the "ErrorLevel" attribute, similar to ERRORLEVEL in DOS.

Change 3051770 on 2016/07/15 by Ben.Marsh

	UGS: Add support for narrowing virtual streams; fetch event and precompiled binaries for parent stream instead.

Change 3052990 on 2016/07/17 by Ben.Marsh

	Show the names of people with notifications disabled in the heading of failure emails, so it's clear that they're not on CC.

Change 3053556 on 2016/07/18 by Ben.Marsh

	BuildGraph: Add a explicit <Option> tag instead of the <Property Default=""/> shenanigans, so that properties that are meant to be modified by the user are listed explicitly. Supported attributes are "DefaultValue" (which specifies a default if the user does not set it on the command line), "Description" (which explains the purpose of the option to users, which is displayed in a table when BuildGraph is invoked with the -listonly argument), and "Restrict" (which specifies a regex to validate an argument supplied by the user).

	Also add an <EnvVar Name="Blah"/> tag which imports the given environment variable as a property (or sets it to "" if it doesn't exist), and rename the <Choose>/<Option>/<Otherwise> triple to <Switch>/<Case>/<Default> to avoid confusion with the new <Option> tag.

Change 3053688 on 2016/07/18 by Ben.Marsh

	Update build scripts to link to p4-swarm rather than p4-web in dashboard pages and notification emails.

Change 3054039 on 2016/07/18 by Ben.Marsh

	Fix confusing message when compiler isn't installed if the target forces VS2013

Change 3054360 on 2016/07/18 by Ben.Marsh

	Remove GUBP support from EC scripts.

Change 3054399 on 2016/07/18 by Ben.Marsh

	Remove circular include from Json.h -> JsonSerializerMacros.h -> Json.h

Change 3055671 on 2016/07/19 by Ben.Marsh

	Remove incomplete UWP integration from UE4.

Change 3055943 on 2016/07/19 by Ben.Marsh

	Remove the WinRT target platform.

Change 3056270 on 2016/07/19 by Ben.Marsh

	Core: Move VectorRegister.h include to eliminate include dependency on UnrealMathUtility.h

Change 3056390 on 2016/07/19 by Ben.Marsh

	Core: Directly include headers required by default JsonWriter template instantiation.

Change 3057444 on 2016/07/20 by Ben.Marsh

	UBT: Fall back to checking for the VS140COMNTOOLS environment variable if we couldn't determine the Visual Studio installation directory from the registry. Allows using the standalone Visual Studio build tools to compile UE4.

Change 3058337 on 2016/07/20 by Ben.Marsh

	Remove EnvVarsToXML. All target platforms now determine their compile environment directly from the registry.

Change 3058348 on 2016/07/20 by Ben.Marsh

	Disable optimization for all automation projects. They don't generally do anything particularly CPU intensive, and VS2015 optimizations are inhibitive to debugging.

[CL 3058822 by Ben Marsh in Main branch]
2016-07-20 20:25:02 -04:00

240 lines
6.4 KiB
C#

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using AutomationTool;
using UnrealBuildTool;
using System.Linq;
/*
- You can also use the full program to test compiling all or a subset of libs:
- From Engine/Build/BatchFiles, do:
- RunUAT AnalyzeThirdPartyLibs [-libs=lib1+lib2+lib3] [-changelist=NNNN]
*/
class PlatformLibraryInfo
{
public List<string> PathParticles = new List<string>();
public List<string> Manifest = new List<string>();
public long TotalSize = 0;
public string PlatformName;
public bool PartOfPlatform(string Filename)
{
foreach (string Particle in PathParticles)
{
if (Filename.IndexOf(Particle, StringComparison.InvariantCultureIgnoreCase) != -1)
{
return true;
}
}
return (PathParticles.Count == 0) ? true : false;
}
public PlatformLibraryInfo(string PlatformName, params string[] Values)
{
this.PlatformName = PlatformName;
PathParticles.AddRange(Values);
}
public void AddFile(string Filename, long Size)
{
Manifest.Add(Filename);
TotalSize += Size;
}
};
class ThirdPartyLibraryInfo
{
public List<string> Manifest = new List<string>();
public long GetSize(List<PlatformLibraryInfo> Platforms)
{
long TotalSize = 0;
foreach (string Filename in Manifest)
{
FileInfo FI = new FileInfo(Filename);
long Size = FI.Length;
foreach (PlatformLibraryInfo Platform in Platforms)
{
if (Platform.PartOfPlatform(Filename))
{
Platform.AddFile(Filename, Size);
}
}
TotalSize += Size;
}
return TotalSize;
}
public void FindLargeFiles(List<string> AllowedExtensions, long MinSize)
{
foreach (string Filename in Manifest)
{
FileInfo FI = new FileInfo(Filename);
long Size = FI.Length;
if (Size > MinSize)
{
bool bAllowed = false;
foreach (string Extension in AllowedExtensions)
{
if (Filename.EndsWith(Extension, StringComparison.InvariantCultureIgnoreCase))
{
bAllowed = true;
break;
}
}
if (!bAllowed)
{
CommandUtils.LogWarning("{0} is {1} with an unexpected extension", Filename, AnalyzeThirdPartyLibs.ToMegabytes(Size));
}
}
}
}
public ThirdPartyLibraryInfo(string Root)
{
string[] Files = Directory.GetFiles(Root, "*.*", SearchOption.AllDirectories);
Manifest.AddRange(Files);
}
}
[Help("Analyzes third party libraries")]
[Help("Libs", "[Optional] + separated list of libraries to compile; if not specified this job will build all libraries it can find builder scripts for")]
[Help("Changelist", "[Optional] a changelist to check out into; if not specified, a changelist will be created")]
class AnalyzeThirdPartyLibs : BuildCommand
{
// path to the third party directory
static private string LibDir = "Engine/Source/ThirdParty";
// batch/script file to look for when compiling
public static string ToMegabytes(long Size)
{
double SizeKB = Size / 1024.0;
double SizeMB = SizeKB / 1024.0;
return String.Format("{0:N2} MB", SizeMB);
}
public override void ExecuteBuild()
{
Log("************************* Analyze Third Party Libs");
// figure out what batch/script to run
switch (UnrealBuildTool.BuildHostPlatform.Current.Platform)
{
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.Mac:
case UnrealTargetPlatform.Linux:
break;
default:
throw new AutomationException("Unknown runtime platform!");
}
// go to the third party lib dir
CommandUtils.PushDir(LibDir);
// figure out what libraries to evaluate
string LibsToEvaluateString = ParseParamValue("Libs");
// Determine which libraries to evaluate
List<string> LibsToEvaluate = new List<string>();
if (string.IsNullOrEmpty(LibsToEvaluateString))
{
// loop over third party directories looking for the right batch files
foreach (string Dir in Directory.EnumerateDirectories("."))
{
LibsToEvaluate.Add(Path.GetFileName(Dir));
}
}
else
{
// just split up the param and make sure the batch file exists
string[] Libs = LibsToEvaluateString.Split('+');
foreach (string Dir in Libs)
{
LibsToEvaluate.Add(Path.GetFileName(Dir));
}
}
// Make a list of platforms
List<PlatformLibraryInfo> Platforms = new List<PlatformLibraryInfo>();
Platforms.Add(new PlatformLibraryInfo("Windows", "Windows", "Win32", "Win64", "VS20"));
Platforms.Add(new PlatformLibraryInfo("Mac", "Osx", "Mac"));
Platforms.Add(new PlatformLibraryInfo("iOS", "IOS"));
Platforms.Add(new PlatformLibraryInfo("Android", "Android"));
Platforms.Add(new PlatformLibraryInfo("PS4", "PS4"));
Platforms.Add(new PlatformLibraryInfo("XB1", "XBoxOne"));
Platforms.Add(new PlatformLibraryInfo("HTML5", "HTML5"));
Platforms.Add(new PlatformLibraryInfo("Linux", "Linux"));
Platforms.Add(new PlatformLibraryInfo("VS2013", "VS2013", "vs12"));
Platforms.Add(new PlatformLibraryInfo("VS2015", "VS2015", "vs14"));
List<long> LastSizes = new List<long>();
foreach (var Platform in Platforms)
{
LastSizes.Add(0);
}
// now go through and evaluate each package
long TotalSize = 0;
foreach (string Lib in LibsToEvaluate)
{
ThirdPartyLibraryInfo Info = new ThirdPartyLibraryInfo(Lib);
long Size = Info.GetSize(Platforms);
Log("Library {0} is {1}", Lib, ToMegabytes(Size));
long Total = 0;
for (int Index = 0; Index < Platforms.Count; ++Index)
{
PlatformLibraryInfo Platform = Platforms[Index];
long Growth = Platform.TotalSize - LastSizes[Index];
Log(" {0} is {1}", Platform.PlatformName, ToMegabytes(Growth));
LastSizes[Index] = Platform.TotalSize;
Total += Growth;
}
Log(" Platform neutral is probably {0} (specific sum {1})", ToMegabytes(Size - Total), ToMegabytes(Total));
TotalSize += Size;
}
// Make a list of known large file types
List<string> LargeFileExtensions = new List<string>();
LargeFileExtensions.AddRange(new string[] { ".pdb", ".a", ".lib", ".dll", ".dylib", ".bc", ".so" });
// Hackery, look for big files (re-traverses everything)
Log("----");
foreach (string Lib in LibsToEvaluate)
{
ThirdPartyLibraryInfo Info = new ThirdPartyLibraryInfo(Lib);
Info.FindLargeFiles(LargeFileExtensions, 1024 * 1024);
}
Log("----");
foreach (var Platform in Platforms)
{
Log(" {0} is {1} (estimate)", Platform.PlatformName, ToMegabytes(Platform.TotalSize));
}
Log(" OVERALL is {0} (accurate)", ToMegabytes(TotalSize));
// undo the LibDir push
CommandUtils.PopDir();
PrintRunTime();
}
}