Skip to content
Permalink
Browse files

[Build] Pack Xenko assets as part of NuGet packaging

  • Loading branch information
xen2 committed Jan 9, 2019
1 parent 1d59bce commit 23d088ee3aca90a49019ae11b486e57ffc976cbe
@@ -25,6 +25,7 @@
using Xenko.Rendering.Materials;
using Xenko.Rendering.ProceduralModels;
using Xenko.SpriteStudio.Offline;
using Xenko.Core.Assets.CompilerApp.Tasks;

namespace Xenko.Core.Assets.CompilerApp
{
@@ -66,6 +67,7 @@ public int Run(string[] args)

var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
var showHelp = false;
var packMode = false;
var buildEngineLogger = GlobalLogger.GetLogger("BuildEngine");
var options = new PackageBuilderOptions(new ForwardingLoggerResult(buildEngineLogger));

@@ -112,6 +114,7 @@ public int Run(string[] args)
} },
{ "slave=", "Slave pipe", v => options.SlavePipe = v }, // Benlitz: I don't think this should be documented
{ "server=", "This Compiler is launched as a server", v => { } },
{ "pack", "Special mode to copy assets and resources in a folder for NuGet packaging", v => packMode = true },
{ "t|threads=", "Number of threads to create. Default value is the number of hardware threads available.", v => options.ThreadCount = int.Parse(v) },
{ "test=", "Run a test session.", v => options.TestName = v },
{ "property:", "Properties. Format is name1=value1;name2=value2", v =>
@@ -210,6 +213,34 @@ public int Run(string[] args)
throw new OptionException(ex.Message, ex.ParamName);
}

if (showHelp)
{
p.WriteOptionDescriptions(Console.Out);
return (int)BuildResultCode.Successful;
}
else if (packMode)
{
PackageSessionPublicHelper.FindAndSetMSBuildVersion();

var csprojFile = options.PackageFile;
var intermediatePackagePath = options.BuildDirectory;
var generatedItems = new List<(string SourcePath, string PackagePath)>();
var logger = new LoggerResult();
if (!PackAssetsHelper.Run(logger, csprojFile, intermediatePackagePath, generatedItems))
{
foreach (var message in logger.Messages)
{
Console.WriteLine(message);
}
return (int)BuildResultCode.BuildError;
}
foreach (var generatedItem in generatedItems)
{
Console.WriteLine($"{generatedItem.SourcePath}|{generatedItem.PackagePath}");
}
return (int)BuildResultCode.Successful;
}

// Also write logs from master process into a file
if (options.SlavePipe == null)
{
@@ -238,12 +269,7 @@ public int Run(string[] args)
IsSlave = true;
}

if (showHelp)
{
p.WriteOptionDescriptions(Console.Out);
exitCode = BuildResultCode.Successful;
}
else if (!string.IsNullOrEmpty(options.TestName))
if (!string.IsNullOrEmpty(options.TestName))
{
var test = new TestSession();
test.RunTest(options.TestName, options.Logger);
@@ -9,41 +9,16 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xenko.Core.Assets;
using Xenko.Core.Diagnostics;
using Xenko.Core.IO;
using Xenko.Core.Yaml;
using Xenko.Core.Yaml.Events;

namespace Xenko.Core.Tasks
namespace Xenko.Core.Assets.CompilerApp.Tasks
{
public class PackAssets : Task
public static class PackAssetsHelper
{
[Required]
public ITaskItem ProjectFile { get; set; }

[Required]
public ITaskItem IntermediatePackagePath { get; set; }

[Output]
public ITaskItem[] GeneratedItems { get; private set; }

public override bool Execute()
{
var generatedItems = new List<(string SourcePath, string PackagePath)>();
var result = Run(new RedirectLog(Log), ProjectFile.ItemSpec, IntermediatePackagePath.ItemSpec, generatedItems);

GeneratedItems = generatedItems.Select(x =>
{
var generatedItem = new TaskItem(x.SourcePath);
generatedItem.SetMetadata("Pack", "true");
generatedItem.SetMetadata("PackagePath", x.PackagePath);
return generatedItem;
}).ToArray();
return result;
}

public static bool Run(Diagnostics.Logger logger, string projectFile, string intermediatePackagePath, List<(string SourcePath, string PackagePath)> generatedItems)
public static bool Run(Core.Diagnostics.Logger logger, string projectFile, string intermediatePackagePath, List<(string SourcePath, string PackagePath)> generatedItems)
{
var package = Package.Load(logger, projectFile, new PackageLoadParameters()
{
@@ -258,6 +233,32 @@ void TryCopyResource(UFile resourceFilePath, UFile targetFilePath)

return !logger.HasErrors;
}
}
public class PackAssets : Task
{
[Required]
public ITaskItem ProjectFile { get; set; }

[Required]
public ITaskItem IntermediatePackagePath { get; set; }

[Output]
public ITaskItem[] GeneratedItems { get; private set; }

public override bool Execute()
{
var generatedItems = new List<(string SourcePath, string PackagePath)>();
var result = PackAssetsHelper.Run(new RedirectLog(Log), ProjectFile.ItemSpec, IntermediatePackagePath.ItemSpec, generatedItems);

GeneratedItems = generatedItems.Select(x =>
{
var generatedItem = new TaskItem(x.SourcePath);
generatedItem.SetMetadata("Pack", "true");
generatedItem.SetMetadata("PackagePath", x.PackagePath);
return generatedItem;
}).ToArray();
return result;
}

class RedirectLog : Core.Diagnostics.Logger
{
@@ -113,4 +113,26 @@
<AndroidStoreUncompressedFileExtensions>$(AndroidStoreUncompressedFileExtensions);.bundle</AndroidStoreUncompressedFileExtensions>
</PropertyGroup>
</Target>

<!-- Pack target -->
<!--<UsingTask TaskName="Xenko.Core.Tasks.PackAssets" AssemblyFile="$(XenkoCompileAssetCommand)" />-->
<Target Name="_XenkoPrepareAssetsForPack" BeforeTargets="_GetPackageFiles">
<!-- We use exec version rather than task version, otherwise file will be locked during rebuild -->
<!--<PackAssets ProjectFile="$(MSBuildProjectFile)" IntermediatePackagePath="$(IntermediateOutputPath)\xenko">
<Output TaskParameter="GeneratedItems" ItemName="None"/>
</PackAssets>-->
<Exec Command="&quot;$(XenkoCompileAssetCommand)&quot; --pack --package-file=&quot;$(MSBuildProjectFullPath)&quot; --build-path=&quot;$(ProjectDir)$(BaseIntermediateOutputPath)xenko\pack&quot;" ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" ItemName="PackAssetsLine" />
</Exec>
<ItemGroup>
<PackAssetsLine Update="@(PackAssetsLine)">
<SourcePath>$([System.String]::new('%(Identity)').Split('|')[0])</SourcePath>
<PackagePath>$([System.String]::new('%(Identity)').Split('|')[1])</PackagePath>
</PackAssetsLine>
<None Include="%(PackAssetsLine.SourcePath)">
<Pack>true</Pack>
<PackagePath>%(PackAssetsLine.PackagePath)</PackagePath>
</None>
</ItemGroup>
</Target>
</Project>
@@ -7,6 +7,7 @@
using System.Reflection;
using Microsoft.Build.Locator;
using Mono.Options;
using Xenko.Core.Assets.CompilerApp.Tasks;
using Xenko.Core.Diagnostics;

namespace Xenko.Core.Tasks
@@ -83,7 +84,7 @@ public static int RealMain(string[] args)
var intermediatePackagePath = commandArgs[2];
var generatedItems = new List<(string SourcePath, string PackagePath)>();
var logger = new LoggerResult();
if (!PackAssets.Run(logger, csprojFile, intermediatePackagePath, generatedItems))
if (!PackAssetsHelper.Run(logger, csprojFile, intermediatePackagePath, generatedItems))
{
foreach (var message in logger.Messages)
{
@@ -40,6 +40,7 @@
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\assets\Xenko.Core.Assets.CompilerApp\Tasks\PackAssets.cs" Link="PackAssets.cs" />
<Compile Include="..\..\shared\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>

0 comments on commit 23d088e

Please sign in to comment.
You can’t perform that action at this time.