2019-07-03 09:44:53 +02:00
|
|
|
using GodotTools.Core;
|
2017-10-02 23:24:00 +02:00
|
|
|
using System;
|
2019-07-03 09:44:53 +02:00
|
|
|
using System.Collections.Generic;
|
2017-10-02 23:24:00 +02:00
|
|
|
using System.IO;
|
|
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
2019-07-03 09:44:53 +02:00
|
|
|
namespace GodotTools.ProjectEditor
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
|
|
|
public static class ProjectGenerator
|
|
|
|
{
|
2019-07-03 09:44:53 +02:00
|
|
|
private const string CoreApiProjectName = "GodotSharp";
|
|
|
|
private const string EditorApiProjectName = "GodotSharpEditor";
|
|
|
|
private const string CoreApiProjectGuid = "{AEBF0036-DA76-4341-B651-A3F2856AB2FA}";
|
|
|
|
private const string EditorApiProjectGuid = "{8FBEC238-D944-4074-8548-B3B524305905}";
|
2018-10-22 19:21:15 +02:00
|
|
|
|
2019-07-03 09:44:53 +02:00
|
|
|
public static string GenCoreApiProject(string dir, IEnumerable<string> compileItems)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2018-11-08 01:05:19 +01:00
|
|
|
string path = Path.Combine(dir, CoreApiProjectName + ".csproj");
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
ProjectPropertyGroupElement mainGroup;
|
2018-11-08 01:05:19 +01:00
|
|
|
var root = CreateLibraryProject(CoreApiProjectName, out mainGroup);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
mainGroup.AddProperty("DocumentationFile", Path.Combine("$(OutputPath)", "$(AssemblyName).xml"));
|
|
|
|
mainGroup.SetProperty("RootNamespace", "Godot");
|
2018-10-22 19:21:15 +02:00
|
|
|
mainGroup.SetProperty("ProjectGuid", CoreApiProjectGuid);
|
2019-01-21 00:38:24 +01:00
|
|
|
mainGroup.SetProperty("BaseIntermediateOutputPath", "obj");
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2018-11-08 01:05:19 +01:00
|
|
|
GenAssemblyInfoFile(root, dir, CoreApiProjectName,
|
2019-07-03 09:44:53 +02:00
|
|
|
new[] {"[assembly: InternalsVisibleTo(\"" + EditorApiProjectName + "\")]"},
|
|
|
|
new[] {"System.Runtime.CompilerServices"});
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
foreach (var item in compileItems)
|
|
|
|
{
|
|
|
|
root.AddItem("Compile", item.RelativeToPath(dir).Replace("/", "\\"));
|
|
|
|
}
|
|
|
|
|
|
|
|
root.Save(path);
|
|
|
|
|
2018-11-08 01:05:19 +01:00
|
|
|
return CoreApiProjectGuid;
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2019-07-03 09:44:53 +02:00
|
|
|
public static string GenEditorApiProject(string dir, string coreApiProjPath, IEnumerable<string> compileItems)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2018-11-08 01:05:19 +01:00
|
|
|
string path = Path.Combine(dir, EditorApiProjectName + ".csproj");
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
ProjectPropertyGroupElement mainGroup;
|
2018-11-08 01:05:19 +01:00
|
|
|
var root = CreateLibraryProject(EditorApiProjectName, out mainGroup);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
mainGroup.AddProperty("DocumentationFile", Path.Combine("$(OutputPath)", "$(AssemblyName).xml"));
|
|
|
|
mainGroup.SetProperty("RootNamespace", "Godot");
|
2018-10-22 19:21:15 +02:00
|
|
|
mainGroup.SetProperty("ProjectGuid", EditorApiProjectGuid);
|
2019-01-21 00:38:24 +01:00
|
|
|
mainGroup.SetProperty("BaseIntermediateOutputPath", "obj");
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2018-11-08 01:05:19 +01:00
|
|
|
GenAssemblyInfoFile(root, dir, EditorApiProjectName);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
foreach (var item in compileItems)
|
|
|
|
{
|
|
|
|
root.AddItem("Compile", item.RelativeToPath(dir).Replace("/", "\\"));
|
|
|
|
}
|
|
|
|
|
2018-11-08 01:05:19 +01:00
|
|
|
var coreApiRef = root.AddItem("ProjectReference", coreApiProjPath.Replace("/", "\\"));
|
2017-10-02 23:24:00 +02:00
|
|
|
coreApiRef.AddMetadata("Private", "False");
|
|
|
|
|
|
|
|
root.Save(path);
|
|
|
|
|
2018-11-08 01:05:19 +01:00
|
|
|
return EditorApiProjectGuid;
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2019-07-03 09:44:53 +02:00
|
|
|
public static string GenGameProject(string dir, string name, IEnumerable<string> compileItems)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
|
|
|
string path = Path.Combine(dir, name + ".csproj");
|
|
|
|
|
|
|
|
ProjectPropertyGroupElement mainGroup;
|
|
|
|
var root = CreateLibraryProject(name, out mainGroup);
|
|
|
|
|
|
|
|
mainGroup.SetProperty("OutputPath", Path.Combine(".mono", "temp", "bin", "$(Configuration)"));
|
|
|
|
mainGroup.SetProperty("BaseIntermediateOutputPath", Path.Combine(".mono", "temp", "obj"));
|
|
|
|
mainGroup.SetProperty("IntermediateOutputPath", Path.Combine("$(BaseIntermediateOutputPath)", "$(Configuration)"));
|
2019-07-03 09:44:53 +02:00
|
|
|
mainGroup.SetProperty("ApiConfiguration", "Debug").Condition = " '$(Configuration)' != 'Release' ";
|
|
|
|
mainGroup.SetProperty("ApiConfiguration", "Release").Condition = " '$(Configuration)' == 'Release' ";
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
var toolsGroup = root.AddPropertyGroup();
|
|
|
|
toolsGroup.Condition = " '$(Configuration)|$(Platform)' == 'Tools|AnyCPU' ";
|
|
|
|
toolsGroup.AddProperty("DebugSymbols", "true");
|
2018-05-17 01:26:02 +02:00
|
|
|
toolsGroup.AddProperty("DebugType", "portable");
|
2017-10-02 23:24:00 +02:00
|
|
|
toolsGroup.AddProperty("Optimize", "false");
|
2019-05-09 19:54:56 +02:00
|
|
|
toolsGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;TOOLS;");
|
2017-10-02 23:24:00 +02:00
|
|
|
toolsGroup.AddProperty("ErrorReport", "prompt");
|
|
|
|
toolsGroup.AddProperty("WarningLevel", "4");
|
|
|
|
toolsGroup.AddProperty("ConsolePause", "false");
|
|
|
|
|
2018-11-08 01:05:19 +01:00
|
|
|
var coreApiRef = root.AddItem("Reference", CoreApiProjectName);
|
2019-07-03 09:44:53 +02:00
|
|
|
coreApiRef.AddMetadata("HintPath", Path.Combine("$(ProjectDir)", ".mono", "assemblies", "$(ApiConfiguration)", CoreApiProjectName + ".dll"));
|
2017-10-02 23:24:00 +02:00
|
|
|
coreApiRef.AddMetadata("Private", "False");
|
|
|
|
|
2018-11-08 01:05:19 +01:00
|
|
|
var editorApiRef = root.AddItem("Reference", EditorApiProjectName);
|
2017-10-02 23:24:00 +02:00
|
|
|
editorApiRef.Condition = " '$(Configuration)' == 'Tools' ";
|
2019-07-03 09:44:53 +02:00
|
|
|
editorApiRef.AddMetadata("HintPath", Path.Combine("$(ProjectDir)", ".mono", "assemblies", "$(ApiConfiguration)", EditorApiProjectName + ".dll"));
|
2017-10-02 23:24:00 +02:00
|
|
|
editorApiRef.AddMetadata("Private", "False");
|
|
|
|
|
|
|
|
GenAssemblyInfoFile(root, dir, name);
|
|
|
|
|
|
|
|
foreach (var item in compileItems)
|
|
|
|
{
|
|
|
|
root.AddItem("Compile", item.RelativeToPath(dir).Replace("/", "\\"));
|
|
|
|
}
|
|
|
|
|
|
|
|
root.Save(path);
|
|
|
|
|
|
|
|
return root.GetGuid().ToString().ToUpper();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void GenAssemblyInfoFile(ProjectRootElement root, string dir, string name, string[] assemblyLines = null, string[] usingDirectives = null)
|
|
|
|
{
|
|
|
|
string propertiesDir = Path.Combine(dir, "Properties");
|
|
|
|
if (!Directory.Exists(propertiesDir))
|
|
|
|
Directory.CreateDirectory(propertiesDir);
|
|
|
|
|
|
|
|
string usingDirectivesText = string.Empty;
|
|
|
|
|
|
|
|
if (usingDirectives != null)
|
|
|
|
{
|
|
|
|
foreach (var usingDirective in usingDirectives)
|
|
|
|
usingDirectivesText += "\nusing " + usingDirective + ";";
|
|
|
|
}
|
|
|
|
|
|
|
|
string assemblyLinesText = string.Empty;
|
|
|
|
|
|
|
|
if (assemblyLines != null)
|
2019-07-03 09:44:53 +02:00
|
|
|
assemblyLinesText += string.Join("\n", assemblyLines) + "\n";
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-07-03 09:44:53 +02:00
|
|
|
string content = string.Format(AssemblyInfoTemplate, usingDirectivesText, name, assemblyLinesText);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
string assemblyInfoFile = Path.Combine(propertiesDir, "AssemblyInfo.cs");
|
|
|
|
|
|
|
|
File.WriteAllText(assemblyInfoFile, content);
|
|
|
|
|
|
|
|
root.AddItem("Compile", assemblyInfoFile.RelativeToPath(dir).Replace("/", "\\"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ProjectRootElement CreateLibraryProject(string name, out ProjectPropertyGroupElement mainGroup)
|
|
|
|
{
|
2019-02-28 22:24:31 +01:00
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
throw new ArgumentException($"{nameof(name)} cannot be empty", nameof(name));
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
var root = ProjectRootElement.Create();
|
|
|
|
root.DefaultTargets = "Build";
|
|
|
|
|
|
|
|
mainGroup = root.AddPropertyGroup();
|
|
|
|
mainGroup.AddProperty("Configuration", "Debug").Condition = " '$(Configuration)' == '' ";
|
|
|
|
mainGroup.AddProperty("Platform", "AnyCPU").Condition = " '$(Platform)' == '' ";
|
|
|
|
mainGroup.AddProperty("ProjectGuid", "{" + Guid.NewGuid().ToString().ToUpper() + "}");
|
|
|
|
mainGroup.AddProperty("OutputType", "Library");
|
|
|
|
mainGroup.AddProperty("OutputPath", Path.Combine("bin", "$(Configuration)"));
|
2019-02-28 22:24:31 +01:00
|
|
|
mainGroup.AddProperty("RootNamespace", IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true));
|
2017-10-02 23:24:00 +02:00
|
|
|
mainGroup.AddProperty("AssemblyName", name);
|
|
|
|
mainGroup.AddProperty("TargetFrameworkVersion", "v4.5");
|
|
|
|
|
|
|
|
var debugGroup = root.AddPropertyGroup();
|
|
|
|
debugGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ";
|
|
|
|
debugGroup.AddProperty("DebugSymbols", "true");
|
2018-05-17 01:26:02 +02:00
|
|
|
debugGroup.AddProperty("DebugType", "portable");
|
2017-10-02 23:24:00 +02:00
|
|
|
debugGroup.AddProperty("Optimize", "false");
|
2019-05-09 19:54:56 +02:00
|
|
|
debugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;");
|
2017-10-02 23:24:00 +02:00
|
|
|
debugGroup.AddProperty("ErrorReport", "prompt");
|
|
|
|
debugGroup.AddProperty("WarningLevel", "4");
|
|
|
|
debugGroup.AddProperty("ConsolePause", "false");
|
|
|
|
|
|
|
|
var releaseGroup = root.AddPropertyGroup();
|
|
|
|
releaseGroup.Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ";
|
2018-05-17 01:26:02 +02:00
|
|
|
releaseGroup.AddProperty("DebugType", "portable");
|
2017-10-02 23:24:00 +02:00
|
|
|
releaseGroup.AddProperty("Optimize", "true");
|
2019-05-09 19:54:56 +02:00
|
|
|
releaseGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;");
|
2017-10-02 23:24:00 +02:00
|
|
|
releaseGroup.AddProperty("ErrorReport", "prompt");
|
|
|
|
releaseGroup.AddProperty("WarningLevel", "4");
|
|
|
|
releaseGroup.AddProperty("ConsolePause", "false");
|
|
|
|
|
|
|
|
// References
|
|
|
|
var referenceGroup = root.AddItemGroup();
|
|
|
|
referenceGroup.AddItem("Reference", "System");
|
|
|
|
|
|
|
|
root.AddImport(Path.Combine("$(MSBuildBinPath)", "Microsoft.CSharp.targets").Replace("/", "\\"));
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void AddItems(ProjectRootElement elem, string groupName, params string[] items)
|
|
|
|
{
|
|
|
|
var group = elem.AddItemGroup();
|
|
|
|
|
|
|
|
foreach (var item in items)
|
|
|
|
{
|
|
|
|
group.AddItem(groupName, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 09:44:53 +02:00
|
|
|
private const string AssemblyInfoTemplate =
|
|
|
|
@"using System.Reflection;{0}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
// Information about this assembly is defined by the following attributes.
|
|
|
|
// Change them to the values specific to your project.
|
|
|
|
|
|
|
|
[assembly: AssemblyTitle(""{1}"")]
|
|
|
|
[assembly: AssemblyDescription("""")]
|
|
|
|
[assembly: AssemblyConfiguration("""")]
|
|
|
|
[assembly: AssemblyCompany("""")]
|
|
|
|
[assembly: AssemblyProduct("""")]
|
|
|
|
[assembly: AssemblyCopyright("""")]
|
|
|
|
[assembly: AssemblyTrademark("""")]
|
|
|
|
[assembly: AssemblyCulture("""")]
|
|
|
|
|
|
|
|
// The assembly version has the format ""{{Major}}.{{Minor}}.{{Build}}.{{Revision}}"".
|
|
|
|
// The form ""{{Major}}.{{Minor}}.*"" will automatically update the build and revision,
|
|
|
|
// and ""{{Major}}.{{Minor}}.{{Build}}.*"" will update just the revision.
|
|
|
|
|
|
|
|
[assembly: AssemblyVersion(""1.0.*"")]
|
|
|
|
|
|
|
|
// The following attributes are used to specify the signing key for the assembly,
|
|
|
|
// if desired. See the Mono documentation for more information about signing.
|
|
|
|
|
|
|
|
//[assembly: AssemblyDelaySign(false)]
|
|
|
|
//[assembly: AssemblyKeyFile("""")]
|
|
|
|
{2}";
|
|
|
|
}
|
|
|
|
}
|