Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#if UNITY_EDITOR

using System;
using System.Collections.Generic;

namespace Microsoft.Build.Unity.ProjectGeneration.Exporters
{
/// <summary>
/// Exporter for the platform props file.
/// </summary>
public interface IPlatformPropsExporter
{
/// <summary>
/// Gets or sets the TargetFramework of the platform.
/// </summary>
string TargetFramework { get; set; }

/// <summary>
/// Gets a set of define constants for the platform.
/// </summary>
HashSet<string> DefineConstants { get; }

/// <summary>
/// Gets a set of assembly search paths for the platform.
/// </summary>
HashSet<string> AssemblySearchPaths { get; }

/// <summary>
/// Gets a set of references for the platform.
/// </summary>
Dictionary<string, Uri> References { get; }

/// <summary>
/// Writes out the data.
/// </summary>
void Write();
}

/// <summary>
/// Specialized exporter for the Player|WSA platform.
/// </summary>
public interface IWSAPlayerPlatformPropsExporter : IPlatformPropsExporter
{
/// <summary>
/// Gets or sets the target UWP version.
/// </summary>
string TargetUWPVersion { get; set; }

/// <summary>
/// Gets or sets the minimum UWP version.
/// </summary>
string MinimumUWPVersion { get; set; }
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ public interface IUnityProjectExporter
ICommonPropsExporter CreateCommonPropsExporter(FileInfo path);

/// <summary>
/// Exports the Common props file based on the given compilation platform and whether to export it as an In-Editor flavor vs Player.
/// Creates the platform props file exporter.
/// </summary>
/// <param name="platform">The platform to export.</param>
/// <param name="inEditorConfiguration">True if this is an In-Editor flavor, false otherwise.</param>
void ExportPlatformPropsFile(CompilationPlatformInfo platform, bool inEditorConfiguration);
/// <param name="path">The <see cref="FileInfo"/> representing where this props file will be written.</param>
/// <param name="unityConfiguration">The configuration for the platform props.</param>
/// <param name="unityPlatform">The unity platform for the platform props.</param>
/// <param name="scriptingBackend">The scripting backend for the platform props.</param>
IPlatformPropsExporter CreatePlatformPropsExporter(FileInfo path, string unityConfiguration, string unityPlatform, ScriptingBackend scriptingBackend);

/// <summary>
/// Creates the specialized platform props file exporter for Player|WSA combination.
/// </summary>
/// <param name="path">The <see cref="FileInfo"/> representing where this props file will be written.</param>
/// <param name="scriptingBackend">The scripting backend for the platform props.</param>
IWSAPlayerPlatformPropsExporter CreateWSAPlayerPlatformPropsExporter(FileInfo path, ScriptingBackend scriptingBackend);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateWSAPlayerPlatformPropsExporter [](start = 40, length = 36)

are we going to need a custom exporter for each platform/player combination? Are there specific things needed on IWSAPlayerPlatformPropsExporter that wouldn't pertain to other platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and yes Min/Max target UWP platform.

}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,31 @@ internal class TemplatedCommonPropsExporter : TemplatedExporterBase, ICommonProp
private const string GeneratedOutputDirectoryToken = "GENERATED_OUTPUT_DIRECTORY";
private const string UnityProjectAssetsDirectoryToken = "UNITY_PROJECT_ASSETS_PATH";

private string unityMajorVersion;
private string unityMinorVersion;
private string currentUnityPlatform;
private string currentTargetFramework;
private DirectoryInfo unityProjectAssetsDirectory;
private DirectoryInfo generatedProjectOutputPath;
public string UnityMajorVersion { get; set; }

public string UnityMajorVersion
{
get => unityMajorVersion;
set => UpdateToken(ref unityMajorVersion, value, UnityMajorVersionToken);
}
public string UnityMinorVersion { get; set; }

public string UnityMinorVersion
{
get => unityMinorVersion;
set => UpdateToken(ref unityMinorVersion, value, UnityMinorVersionToken);
}
public string CurrentUnityPlatform { get; set; }

public string CurrentUnityPlatform
{
get => currentUnityPlatform;
set => UpdateToken(ref currentUnityPlatform, value, CurrentUnityPlatformToken);
}
public string CurrentTargetFramework { get; set; }

public string CurrentTargetFramework
{
get => currentTargetFramework;
set => UpdateToken(ref currentTargetFramework, value, CurrentTargetFrameworkToken);
}
public DirectoryInfo UnityProjectAssetsDirectory { get; set; }

public DirectoryInfo UnityProjectAssetsDirectory
{
get => unityProjectAssetsDirectory;
set => UpdateToken(ref unityProjectAssetsDirectory, value, UnityProjectAssetsDirectoryToken, t => t.FullName);
}
public DirectoryInfo GeneratedProjectOutputPath { get; set; }

public DirectoryInfo GeneratedProjectOutputPath
internal TemplatedCommonPropsExporter(FileTemplate fileTemplate, FileInfo exportPath)
: base(fileTemplate, exportPath)
{
get => generatedProjectOutputPath;
set => UpdateToken(ref generatedProjectOutputPath, value, GeneratedOutputDirectoryToken, t => t.FullName);
}

internal TemplatedCommonPropsExporter(FileTemplate fileTemplate, FileInfo exportPath)
: base(fileTemplate, exportPath)
protected override void Export(TemplatedWriter writer)
{
writer.Write(UnityMajorVersionToken, UnityMajorVersion);
writer.Write(UnityMinorVersionToken, UnityMinorVersion);
writer.Write(CurrentUnityPlatformToken, CurrentUnityPlatform);
writer.Write(CurrentTargetFrameworkToken, CurrentTargetFramework);
writer.Write(UnityProjectAssetsDirectoryToken, UnityProjectAssetsDirectory.FullName);
writer.Write(GeneratedOutputDirectoryToken, GeneratedProjectOutputPath.FullName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace Microsoft.Build.Unity.ProjectGeneration.Exporters.TemplatedExporter
/// <summary>
/// Base class for file based exporters.
/// </summary>
internal class TemplatedExporterBase : TemplatedExporterPart
internal abstract class TemplatedExporterBase
{
private readonly FileTemplate templateFile;
private readonly FileInfo exportPath;

protected TemplatedExporterBase(FileTemplate templateFile, FileInfo exportPath)
: base(templateFile.Root, templateFile.Root.CreateReplacementSet())
{
this.templateFile = templateFile;
this.exportPath = exportPath;
Expand All @@ -30,8 +29,18 @@ public void Write()
// Ensure the parent directories are created
Directory.CreateDirectory(exportPath.Directory.FullName);

TemplateReplacementSet replacementSet = templateFile.Root.CreateReplacementSet();

Export(new TemplatedWriter(templateFile.Root, replacementSet));

templateFile.Write(exportPath.FullName, replacementSet);
}

/// <summary>
/// Override this method in a derived class to perform the export.
/// </summary>
/// <param name="writer">The writer to use to export.</param>
protected abstract void Export(TemplatedWriter writer);
}
}
#endif

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#if UNITY_EDITOR
using Microsoft.Build.Unity.ProjectGeneration.Templates;
using System;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.Build.Unity.ProjectGeneration.Exporters.TemplatedExporter
{
/// <summary>
/// A class for exporting platform props using templates.
/// </summary>
internal class TemplatedPlatformPropsExporter : TemplatedExporterBase, IPlatformPropsExporter
{
private const string TargetFrameworkToken = "TARGET_FRAMEWORK";
private const string DefineConstantsToken = "PLATFORM_COMMON_DEFINE_CONSTANTS";
private const string AssemblySearchPathsToken = "PLATFORM_COMMON_ASSEMBLY_SEARCH_PATHS";

private const string CommonReferenceSubTemplate = "PLATFORM_COMMON_REFERENCE";
private const string CommonReferencesSubTemplateReferenceToken = "REFERENCE";
private const string CommonReferencesSubTemplateHintPathToken = "HINT_PATH";

public string TargetFramework { get; set; }

public HashSet<string> DefineConstants { get; } = new HashSet<string>(); // Guess at default size

public HashSet<string> AssemblySearchPaths { get; } = new HashSet<string>(); // Guess at default size

public Dictionary<string, Uri> References { get; } = new Dictionary<string, Uri>(250); // Guess at default size

public TemplatedPlatformPropsExporter(FileTemplate fileTemplate, FileInfo exportPath)
: base(fileTemplate, exportPath)
{

}

protected override void Export(TemplatedWriter writer)
{
writer.Write(TargetFrameworkToken, TargetFramework, optional: true);

writer.Write(DefineConstantsToken, DefineConstants);
writer.Write(AssemblySearchPathsToken, AssemblySearchPaths);

foreach (KeyValuePair<string, Uri> reference in References)
{
TemplatedWriter subTemplateWriter = writer.CreateWriterFor(CommonReferenceSubTemplate);
subTemplateWriter.Write(CommonReferencesSubTemplateReferenceToken, reference.Key);
subTemplateWriter.Write(CommonReferencesSubTemplateHintPathToken, reference.Value.LocalPath);
}
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading