Skip to content

Commit

Permalink
Add support for copying data from package resource directories
Browse files Browse the repository at this point in the history
  • Loading branch information
adamrehn committed Jul 23, 2020
1 parent 631c110 commit e10f742
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 15 deletions.
10 changes: 10 additions & 0 deletions conan_ue4cli/commands/precompute.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def precompute(manager, argv):
libDir = join(args.dir, 'precomputed', engineVersion, targetID, 'lib')
Utility.truncateDirectory(libDir)

# Create a data directory for our aggregated data/resource files
dataDir = join(args.dir, 'precomputed', engineVersion, targetID, 'data')
Utility.truncateDirectory(dataDir)

# Keep track of any additional aggregated flags, including system libraries and macro definitions
flags = {
'defines': [],
Expand Down Expand Up @@ -91,6 +95,12 @@ def precompute(manager, argv):
else:
print('Warning: failed to resolve static library file for library name "{}"'.format(lib))

# Aggregate the files from each of the dependency's resource directories
for depResourceDir in dependency['res_paths']:
for file in glob.glob(join(depResourceDir, '*')):
print('Copying "{}"...'.format(file))
Utility.copyFileOrDir(file, dataDir)

# Add any macro definitions to our list
flags['defines'] += dependency['defines']

Expand Down
33 changes: 28 additions & 5 deletions conan_ue4cli/data/boilerplate_templates/v1/Template.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private string GetEngineVersion()
}

//Processes the JSON data produced by Conan that describes our dependencies
private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target)
private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target, string stagingDir)
{
//We need to ensure libraries end with ".lib" under Windows
string libSuffix = ((this.IsWindows(target)) ? ".lib" : "");
Expand All @@ -67,20 +67,31 @@ private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target)
string libFull = lib + ((libSuffix.Length == 0 || lib.EndsWith(libSuffix)) ? "" : libSuffix);
PublicAdditionalLibraries.Add(libFull);
}

//Copy any data files needed by the package into our staging directory
string[] dataDirs = dep.GetStringArrayField("res_paths");
foreach (string dir in dataDirs)
{
string[] files = Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
foreach(string file in files) {
RuntimeDependencies.Add(Path.Combine(stagingDir, Path.GetFileName(file)), file, StagedFileType.NonUFS);
}
}
}
}

//Determines if we have precomputed dependency data for the specified target and Engine version, and processes it if we do
private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVersion)
private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVersion, string stagingDir)
{
//Resolve the paths to the files and directories that will exist if we have precomputed data for the target
string targetDir = Path.Combine(ModuleDirectory, "precomputed", engineVersion, this.TargetIdentifier(target));
string flagsFile = Path.Combine(targetDir, "flags.json");
string includeDir = Path.Combine(targetDir, "include");
string libDir = Path.Combine(targetDir, "lib");
string dataDir = Path.Combine(targetDir, "data");

//If any of the required files or directories do not exist then we do not have precomputed data
if (!File.Exists(flagsFile) || !Directory.Exists(includeDir) || !Directory.Exists(libDir)) {
if (!File.Exists(flagsFile) || !Directory.Exists(includeDir) || !Directory.Exists(libDir) || !Directory.Exists(dataDir)) {
return false;
}

Expand Down Expand Up @@ -108,16 +119,28 @@ private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVer
PublicAdditionalLibraries.Add(libFull);
}

//Copy any data files needed by the package into our staging directory
string[] files = Directory.GetFiles(dataDir, "*", SearchOption.AllDirectories);
foreach(string file in files) {
RuntimeDependencies.Add(Path.Combine(stagingDir, Path.GetFileName(file)), file, StagedFileType.NonUFS);
}

return true;
}

public ${MODULE}(ReadOnlyTargetRules Target) : base(Target)
{
Type = ModuleType.External;

//Ensure our staging directory exists prior to copying any dependency data files into it
string stagingDir = Path.Combine("$(ProjectDir)", "Binaries", "Data", "${MODULE}");
if (!Directory.Exists(stagingDir)) {
Directory.CreateDirectory(stagingDir);
}

//Determine if we have precomputed dependency data for the target that is being built
string engineVersion = this.GetEngineVersion();
if (this.ProcessPrecomputedData(Target, engineVersion) == false)
if (this.ProcessPrecomputedData(Target, engineVersion, stagingDir) == false)
{
//No precomputed data detected, install third-party dependencies using Conan
Process.Start(new ProcessStartInfo
Expand All @@ -130,7 +153,7 @@ private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVer
.WaitForExit();

//Link against our Conan-installed dependencies
this.ProcessDependencies(Path.Combine(ModuleDirectory, "conanbuildinfo.json"), Target);
this.ProcessDependencies(Path.Combine(ModuleDirectory, "conanbuildinfo.json"), Target, stagingDir);
}
}
}
33 changes: 28 additions & 5 deletions conan_ue4cli/data/boilerplate_templates/v2/Template.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private string GetEngineVersion()
}

//Processes the JSON data produced by Conan that describes our dependencies
private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target)
private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target, string stagingDir)
{
//We need to ensure libraries end with ".lib" under Windows
string libSuffix = ((this.IsWindows(target)) ? ".lib" : "");
Expand All @@ -71,20 +71,31 @@ private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target)
string libFull = lib + ((libSuffix.Length == 0 || lib.EndsWith(libSuffix)) ? "" : libSuffix);
PublicAdditionalLibraries.Add(libFull);
}

//Copy any data files needed by the package into our staging directory
string[] dataDirs = dep.GetStringArrayField("res_paths");
foreach (string dir in dataDirs)
{
string[] files = Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
foreach(string file in files) {
RuntimeDependencies.Add(Path.Combine(stagingDir, Path.GetFileName(file)), file, StagedFileType.NonUFS);
}
}
}
}

//Determines if we have precomputed dependency data for the specified target and Engine version, and processes it if we do
private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVersion)
private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVersion, string stagingDir)
{
//Resolve the paths to the files and directories that will exist if we have precomputed data for the target
string targetDir = Path.Combine(ModuleDirectory, "precomputed", engineVersion, this.TargetIdentifier(target));
string flagsFile = Path.Combine(targetDir, "flags.json");
string includeDir = Path.Combine(targetDir, "include");
string libDir = Path.Combine(targetDir, "lib");
string dataDir = Path.Combine(targetDir, "data");

//If any of the required files or directories do not exist then we do not have precomputed data
if (!File.Exists(flagsFile) || !Directory.Exists(includeDir) || !Directory.Exists(libDir)) {
if (!File.Exists(flagsFile) || !Directory.Exists(includeDir) || !Directory.Exists(libDir) || !Directory.Exists(dataDir)) {
return false;
}

Expand Down Expand Up @@ -112,16 +123,28 @@ private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVer
PublicAdditionalLibraries.Add(libFull);
}

//Copy any data files needed by the package into our staging directory
string[] files = Directory.GetFiles(dataDir, "*", SearchOption.AllDirectories);
foreach(string file in files) {
RuntimeDependencies.Add(Path.Combine(stagingDir, Path.GetFileName(file)), file, StagedFileType.NonUFS);
}

return true;
}

public ${MODULE}(ReadOnlyTargetRules Target) : base(Target)
{
Type = ModuleType.External;

//Ensure our staging directory exists prior to copying any dependency data files into it
string stagingDir = Path.Combine("$(ProjectDir)", "Binaries", "Data", "${MODULE}");
if (!Directory.Exists(stagingDir)) {
Directory.CreateDirectory(stagingDir);
}

//Determine if we have precomputed dependency data for the target that is being built
string engineVersion = this.GetEngineVersion();
if (this.ProcessPrecomputedData(Target, engineVersion) == false)
if (this.ProcessPrecomputedData(Target, engineVersion, stagingDir) == false)
{
//No precomputed data detected, install third-party dependencies using Conan
Process.Start(new ProcessStartInfo
Expand All @@ -134,7 +157,7 @@ private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVer
.WaitForExit();

//Link against our Conan-installed dependencies
this.ProcessDependencies(Path.Combine(ModuleDirectory, "conanbuildinfo.json"), Target);
this.ProcessDependencies(Path.Combine(ModuleDirectory, "conanbuildinfo.json"), Target, stagingDir);
}
}
}
33 changes: 28 additions & 5 deletions conan_ue4cli/data/boilerplate_templates/v3/Template.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private string GetEngineVersion()
}

//Processes the JSON data produced by Conan that describes our dependencies
private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target)
private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target, string stagingDir)
{
//We need to ensure libraries end with ".lib" under Windows
string libSuffix = ((this.IsWindows(target)) ? ".lib" : "");
Expand All @@ -71,20 +71,31 @@ private void ProcessDependencies(string depsJson, ReadOnlyTargetRules target)
string libFull = lib + ((libSuffix.Length == 0 || lib.EndsWith(libSuffix)) ? "" : libSuffix);
PublicAdditionalLibraries.Add(libFull);
}

//Copy any data files needed by the package into our staging directory
string[] dataDirs = dep.GetStringArrayField("res_paths");
foreach (string dir in dataDirs)
{
string[] files = Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
foreach(string file in files) {
RuntimeDependencies.Add(Path.Combine(stagingDir, Path.GetFileName(file)), file, StagedFileType.NonUFS);
}
}
}
}

//Determines if we have precomputed dependency data for the specified target and Engine version, and processes it if we do
private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVersion)
private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVersion, string stagingDir)
{
//Resolve the paths to the files and directories that will exist if we have precomputed data for the target
string targetDir = Path.Combine(ModuleDirectory, "precomputed", engineVersion, this.TargetIdentifier(target));
string flagsFile = Path.Combine(targetDir, "flags.json");
string includeDir = Path.Combine(targetDir, "include");
string libDir = Path.Combine(targetDir, "lib");
string dataDir = Path.Combine(targetDir, "data");

//If any of the required files or directories do not exist then we do not have precomputed data
if (!File.Exists(flagsFile) || !Directory.Exists(includeDir) || !Directory.Exists(libDir)) {
if (!File.Exists(flagsFile) || !Directory.Exists(includeDir) || !Directory.Exists(libDir) || !Directory.Exists(dataDir)) {
return false;
}

Expand Down Expand Up @@ -112,16 +123,28 @@ private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVer
PublicAdditionalLibraries.Add(libFull);
}

//Copy any data files needed by the package into our staging directory
string[] files = Directory.GetFiles(dataDir, "*", SearchOption.AllDirectories);
foreach(string file in files) {
RuntimeDependencies.Add(Path.Combine(stagingDir, Path.GetFileName(file)), file, StagedFileType.NonUFS);
}

return true;
}

public ${MODULE}(ReadOnlyTargetRules Target) : base(Target)
{
Type = ModuleType.External;

//Ensure our staging directory exists prior to copying any dependency data files into it
string stagingDir = Path.Combine("$(ProjectDir)", "Binaries", "Data", "${MODULE}");
if (!Directory.Exists(stagingDir)) {
Directory.CreateDirectory(stagingDir);
}

//Determine if we have precomputed dependency data for the target that is being built
string engineVersion = this.GetEngineVersion();
if (this.ProcessPrecomputedData(Target, engineVersion) == false)
if (this.ProcessPrecomputedData(Target, engineVersion, stagingDir) == false)
{
//No precomputed data detected, install third-party dependencies using Conan
Process.Start(new ProcessStartInfo
Expand All @@ -134,7 +157,7 @@ private bool ProcessPrecomputedData(ReadOnlyTargetRules target, string engineVer
.WaitForExit();

//Link against our Conan-installed dependencies
this.ProcessDependencies(Path.Combine(ModuleDirectory, "conanbuildinfo.json"), Target);
this.ProcessDependencies(Path.Combine(ModuleDirectory, "conanbuildinfo.json"), Target, stagingDir);
}
}
}

0 comments on commit e10f742

Please sign in to comment.