Skip to content
Permalink
Browse files

[Assets] Fix platform update

  • Loading branch information
xen2 committed Sep 9, 2018
1 parent 5ec594f commit 0c12372ab203fab5baa22dc78ce88b255b88f4d5
@@ -311,7 +311,6 @@

<!-- Compute graphics platform from game settings asset -->
<Target Name="XenkoComputeGraphicsPlatformFromGameSettings" Inputs="$(XenkoGameSettings)" Outputs="$(IntermediateOutputPath)XenkoGraphicsPlatform.cache" Condition="'$(XenkoCurrentPackagePath)' != '' and '$(XenkoIsExecutable)' == 'true'">
<Error Condition="'$(XenkoBuildProfile)' == ''" Text="The asset compiler is requiring the property (XenkoBuildProfile) to be defined"/>
<Error Condition="!Exists('$(XenkoCurrentPackagePath)')" Text="Unable to find package decription from path [$(XenkoCurrentPackagePath)]"/>

<!-- Ensure the output directory exists -->
@@ -359,7 +358,6 @@
<!--Compile assets for all XenkoPackage items and only for an executable-->
<Target Name="XenkoCompileAsset" DependsOnTargets="XenkoUpdateGraphicsPlatform" Condition="'$(XenkoCurrentPackagePath)' != '' and '$(XenkoIsExecutable)' == 'true'">
<!--Check that the package file actually exist-->
<Error Condition="'$(XenkoBuildProfile)' == ''" Text="The asset compiler is requiring the property (XenkoBuildProfile) to be defined"/>
<Error Condition="!Exists('$(XenkoCurrentPackagePath)')" Text="Unable to find package decription from path [$(XenkoCurrentPackagePath)]"/>
<PropertyGroup>
<XenkoCompileAssetCommandProxy>$(XenkoCompileAssetCommandProxy) $(XenkoCompileAssetOptions) --disable-auto-compile --project-configuration &quot;$(Configuration)&quot; --platform=$(XenkoPlatform) --project-configuration=$(Configuration) --output-path=&quot;$(XenkoCompileAssetOutputPath)&quot; --build-path=&quot;$(XenkoCompileAssetBuildPath)&quot; --package-file=&quot;$(XenkoCurrentPackagePath)&quot; --log-pipe=&quot;$(XenkoBuildEngineLogPipeUrl)&quot;</XenkoCompileAssetCommandProxy>
@@ -10,7 +10,6 @@
{
#>
<XenkoPlatform><#= currentPlatform #></XenkoPlatform>
<XenkoBuildProfile><#= Properties.CurrentProfile #></XenkoBuildProfile>
<#
}
#>
@@ -129,7 +129,7 @@ protected override bool Generate(SessionTemplateGeneratorParameters parameters)
ProjectTemplateGeneratorHelper.Progress(logger, $"Generating {projectGameName}...", stepIndex++, stepCount);

// Generate the Game library
var project = ProjectTemplateGeneratorHelper.GenerateTemplate(parameters, platforms, "ProjectLibrary.Game/ProjectLibrary.Game.ttproj", projectGameName, PlatformType.Shared, null, null, ProjectType.Library, orientation);
var project = ProjectTemplateGeneratorHelper.GenerateTemplate(parameters, platforms, "ProjectLibrary.Game/ProjectLibrary.Game.ttproj", projectGameName, PlatformType.Shared, null, ProjectType.Library, orientation);
var package = project.Package;

//write gitignore
@@ -150,10 +150,10 @@ protected override bool Generate(SessionTemplateGeneratorParameters parameters)
session.LoadMissingAssets(parameters.Logger, project.LoadedDependencies);

// Add Effects as an asset folder in order to load xksl
//sharedProfile.AssetFolders.Add(new AssetFolder(projectGameName + "/Effects"));
package.Profile.AssetFolders.Add(new AssetFolder("Effects"));

// Generate executable projects for each platform
//ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, platforms, orientation, package.Id, name, package, false);
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, platforms, orientation, package.Id, name, package, false);

// Add asset packages
CopyAssetPacks(parameters, package);
@@ -327,27 +327,26 @@ protected override async Task<bool> AfterSave(SessionTemplateGeneratorParameters
// We want to force regeneration of Windows platform in case the sample .csproj is outdated
UpdatePlatformsTemplateGenerator.SetForcePlatformRegeneration(updateParameters, true);

// TODO CSPROJ=XKPKG
//var updateTemplate = UpdatePlatformsTemplateGenerator.Default;
//if (!await updateTemplate.PrepareForRun(updateParameters) || !updateTemplate.Run(updateParameters))
//{
// // Remove the created project
// var path = Path.GetDirectoryName(parameters.Session.SolutionPath.ToWindowsPath());
// try
// {
// Directory.Delete(path ?? "", true);
// }
// catch (IOException ex)
// {
// parameters.Logger.Error("Error when removing generated project.", ex);
// }
// catch (UnauthorizedAccessException ex)
// {
// parameters.Logger.Error("Error when removing generated project.", ex);
// }
// // Notify cancellation
// return false;
//}
var updateTemplate = UpdatePlatformsTemplateGenerator.Default;
if (!await updateTemplate.PrepareForRun(updateParameters) || !updateTemplate.Run(updateParameters))
{
// Remove the created project
var path = Path.GetDirectoryName(parameters.Session.SolutionPath.ToWindowsPath());
try
{
Directory.Delete(path ?? "", true);
}
catch (IOException ex)
{
parameters.Logger.Error("Error when removing generated project.", ex);
}
catch (UnauthorizedAccessException ex)
{
parameters.Logger.Error("Error when removing generated project.", ex);
}
// Notify cancellation
return false;
}

// Save again post update
SaveSession(parameters);
@@ -60,7 +60,6 @@ public override async Task<bool> PrepareForRun(PackageTemplateGeneratorParameter
}

// TODO CSPROJ=XKPKG
throw new NotImplementedException();
// If there are no executable/shared projects in this package, we can't work on it
/*var sharedProfile = package.Profile;
var existingPlatformTypesWithExe = new HashSet<PlatformType>(package.Profiles.Where(profile => profile.Platform != PlatformType.Shared && profile.ProjectReferences.Any(projectRef => projectRef.Type == ProjectType.Executable)).Select(item => item.Platform));
@@ -126,7 +125,6 @@ public sealed override bool Run(PackageTemplateGeneratorParameters parameters)

// Generate missing platforms
bool forceGenerating = parameters.GetTag(ForcePlatformRegenerationKey);
// TODO CSPROJ=XKPKG
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, parameters.GetTag(PlatformsKey), parameters.GetTag(OrientationKey), package.Id, name, package, forceGenerating);

// Save the session after the update
@@ -70,80 +70,62 @@ public static void UpdatePackagePlatforms(TemplateGeneratorParameters parameters
AddOption(parameters, "ProjectGameRelativePath", (package.Container as SolutionProject)?.FullPath.MakeRelative(parameters.OutputDirectory).ToWindowsPath());
AddOption(parameters, "PackageGameRelativePath", package.FullPath.MakeRelative(parameters.OutputDirectory).ToWindowsPath());

// TODO CSPROJ=XKPKG
throw new NotImplementedException();
/*// Add projects
// Add projects
var stepIndex = 0;
var stepCount = platforms.Count + 1;
var profilesToRemove = package.Profiles.Where(profile => platforms.All(platform => profile.Platform != PlatformType.Shared && platform.Platform.Type != profile.Platform)).ToList();
stepCount += profilesToRemove.Count;

foreach (var platform in platforms)
{
stepIndex++;

// Don't add a platform that is already in the package
var platformProfile = package.Profiles.FirstOrDefault(profile => profile.Platform == platform.Platform.Type);
if (platformProfile != null && !forcePlatformRegeneration)
continue;
var projectName = Utilities.BuildValidNamespaceName(name) + "." + platform.Platform.Name;
var projectFullPath = UPath.Combine(package.RootDirectory.GetParent(), (UFile)(projectName + ".csproj"));
var existingProject = package.Session.Projects.OfType<SolutionProject>().FirstOrDefault(x => x.FullPath == projectFullPath);

var projectGuid = Guid.NewGuid();

if (platformProfile == null)
{
platformProfile = new PackageProfile() { Platform = platform.Platform.Type };
platformProfile.AssetFolders.Add(new AssetFolder("Assets/" + platform.Platform.Name));
}
else
if (existingProject != null)
{
if (!forcePlatformRegeneration)
continue;

projectGuid = existingProject.Id;

// We are going to regenerate this platform, so we are removing it before
var previousExeProject = platformProfile.ProjectReferences.FirstOrDefault(project => project.Type == ProjectType.Executable);
if (previousExeProject != null)
package.Session.Projects.Remove(existingProject);
var projectDirectory = Path.GetDirectoryName(projectFullPath);
if (projectDirectory != null && Directory.Exists(projectDirectory))
{
projectGuid = previousExeProject.Id;
RemoveProject(previousExeProject, logger);
platformProfile.ProjectReferences.Remove(previousExeProject);
try
{
Directory.Delete(projectDirectory, true);
}
catch (Exception)
{
logger.Warning($"Unable to delete directory [{projectDirectory}]");
}
}
}

var templatePath = platform.Template?.TemplatePath ?? $"ProjectExecutable.{platform.Platform.Name}/ProjectExecutable.{platform.Platform.Name}.ttproj";

// Log progress
var projectName = Utilities.BuildValidNamespaceName(name) + "." + platform.Platform.Name;
Progress(logger, $"Generating {projectName}...", stepIndex - 1, stepCount);

var graphicsPlatform = platform.Platform.Type.GetDefaultGraphicsPlatform();
var newExeProject = GenerateTemplate(parameters, platforms, templatePath, projectName, platform.Platform.Type, platformProfile.Name, graphicsPlatform, ProjectType.Executable, orientation, projectGuid);
var newExeProject = GenerateTemplate(parameters, platforms, templatePath, projectName, platform.Platform.Type, graphicsPlatform, ProjectType.Executable, orientation, projectGuid);

package.Session.Projects.Add(newExeProject);

package.IsDirty = true;
}
// Remove existing platform profiles
foreach (var profileToRemove in profilesToRemove)
{
package.Profiles.Remove(profileToRemove);
package.IsDirty = true;
foreach (var projectReference in profileToRemove.ProjectReferences)
{
// Try to remove the directory
Progress(logger, $"Deleting {projectReference.Location}...", stepIndex++, stepCount);
RemoveProject(projectReference, logger);
}
// We are completely removing references from profile
profileToRemove.ProjectReferences.Clear();
}*/
}

public static SolutionProject GenerateTemplate(TemplateGeneratorParameters parameters, ICollection<SelectedSolutionPlatform> platforms, UFile templateRelativePath, string projectName, PlatformType platformType, string currentProfile, GraphicsPlatform? graphicsPlatform, ProjectType projectType, DisplayOrientation orientation, Guid? projectGuid = null)
public static SolutionProject GenerateTemplate(TemplateGeneratorParameters parameters, ICollection<SelectedSolutionPlatform> platforms, UFile templateRelativePath, string projectName, PlatformType platformType, GraphicsPlatform? graphicsPlatform, ProjectType projectType, DisplayOrientation orientation, Guid? projectGuid = null)
{
AddOption(parameters, "Platforms", platforms.Select(x => x.Platform).ToList());
AddOption(parameters, "CurrentPlatform", platformType);
AddOption(parameters, "CurrentProfile", currentProfile);
AddOption(parameters, "Orientation", orientation);

List<string> generatedFiles;

0 comments on commit 0c12372

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