[xharness] Fix generation of today extension projects to work from Xamarin Studio. (#1502)

Minor tweaks to make the solutions/project files usable from the IDE, and not
only the command line.
This commit is contained in:
Rolf Bjarne Kvinge 2017-01-16 16:23:49 +01:00 коммит произвёл GitHub
Родитель f19d2707e3
Коммит 787c63766e
5 изменённых файлов: 63 добавлений и 31 удалений

Просмотреть файл

@ -25,6 +25,11 @@ namespace xharness
SetPListStringValue (plist, "MinimumOSVersion", value);
}
public static void SetCFBundleDisplayName (this XmlDocument plist, string value)
{
SetPListStringValue (plist, "CFBundleDisplayName", value);
}
public static string GetMinimumOSVersion (this XmlDocument plist)
{
return GetPListStringValue (plist, "MinimumOSVersion");
@ -62,7 +67,12 @@ namespace xharness
public static void SetPListStringValue (this XmlDocument plist, string node, string value)
{
plist.SelectSingleNode ("//dict/key[text()='" + node + "']").NextSibling.InnerText = value;
var element = plist.SelectSingleNode ("//dict/key[text()='" + node + "']");
if (element == null) {
AddPListStringValue (plist, node, value);
} else {
element.NextSibling.InnerText = value;
}
}
public static void AddPListStringValue (this XmlDocument plist, string node, string value)

Просмотреть файл

@ -63,11 +63,12 @@ namespace xharness
writer.WriteLine ("Microsoft Visual Studio Solution File, Format Version 11.00");
writer.WriteLine ("# Visual Studio 2010");
foreach (var target in targets) {
var w = target as WatchOSTarget;
var relatedProjects = target.GetRelatedProjects ();
var hasRelatedProjects = relatedProjects != null;
var folderGuid = string.Empty;
var useFolders = w != null && w.IsExe && exeTarget == null;
var useFolders = hasRelatedProjects && target.IsExe && exeTarget == null;
if (w != null && w.IsExe) {
if (hasRelatedProjects && target.IsExe) {
if (exeTarget == null) {
CreateSolution (harness, targets, target, infix); // create a solution for just this test project as well
} else if (exeTarget != target) {
@ -84,17 +85,17 @@ namespace xharness
writer.WriteLine ("Project(\"{3}\") = \"{0}\", \"{1}\", \"{2}\"", Path.GetFileNameWithoutExtension (target.ProjectPath), FixProjectPath (sln_path, Path.GetFullPath (target.ProjectPath)), target.ProjectGuid, target.LanguageGuid);
writer.WriteLine ("EndProject");
if (w != null && w.IsExe) {
writer.WriteLine ("Project(\"{3}\") = \"{0}\", \"{1}\", \"{2}\"", Path.GetFileNameWithoutExtension (w.WatchOSExtensionProjectPath), FixProjectPath (sln_path, Path.GetFullPath (w.WatchOSExtensionProjectPath)), w.WatchOSExtensionGuid, w.LanguageGuid);
writer.WriteLine ("EndProject");
writer.WriteLine ("Project(\"{3}\") = \"{0}\", \"{1}\", \"{2}\"", Path.GetFileNameWithoutExtension (w.WatchOSAppProjectPath), FixProjectPath (sln_path, Path.GetFullPath (w.WatchOSAppProjectPath)), w.WatchOSAppGuid, w.LanguageGuid);
writer.WriteLine ("EndProject");
if (hasRelatedProjects && target.IsExe) {
foreach (var rp in relatedProjects) {
writer.WriteLine ("Project(\"{3}\") = \"{0}\", \"{1}\", \"{2}\"", Path.GetFileNameWithoutExtension (rp.ProjectPath), FixProjectPath (sln_path, Path.GetFullPath (rp.ProjectPath)), rp.Guid, target.LanguageGuid);
writer.WriteLine ("EndProject");
}
}
if (useFolders) {
folders.AppendFormat ("\t\t{0} = {{{1}}}\n", target.ProjectGuid, folderGuid);
folders.AppendFormat ("\t\t{0} = {{{1}}}\n", w.WatchOSExtensionGuid, folderGuid);
folders.AppendFormat ("\t\t{0} = {{{1}}}\n", w.WatchOSAppGuid, folderGuid);
foreach (var rp in relatedProjects)
folders.AppendFormat ("\t\t{0} = {{{1}}}\n", rp.Guid, folderGuid);
}
}
@ -147,21 +148,18 @@ namespace xharness
}
if (target.IsExe) {
var w = target as WatchOSTarget;
if (w != null) {
foreach (var conf in configurations) {
foreach (var platform in exePlatforms) {
writer.WriteLine ("\t\t{0}.{1}|{2}.ActiveCfg = {1}|{2}", w.WatchOSExtensionGuid, conf, platform);
writer.WriteLine ("\t\t{0}.{1}|{2}.Build.0 = {1}|{2}", w.WatchOSExtensionGuid, conf, platform);
}
}
foreach (var conf in configurations) {
foreach (var platform in exePlatforms) {
writer.WriteLine ("\t\t{0}.{1}|{2}.ActiveCfg = {1}|{2}", w.WatchOSAppGuid, conf, platform);
writer.WriteLine ("\t\t{0}.{1}|{2}.Build.0 = {1}|{2}", w.WatchOSAppGuid, conf, platform);
var relatedProjects = target.GetRelatedProjects ();
if (relatedProjects != null) {
foreach (var rp in relatedProjects) {
foreach (var conf in configurations) {
foreach (var platform in exePlatforms) {
writer.WriteLine ("\t\t{0}.{1}|{2}.ActiveCfg = {1}|{2}", rp.Guid, conf, platform);
writer.WriteLine ("\t\t{0}.{1}|{2}.Build.0 = {1}|{2}", rp.Guid, conf, platform);
}
}
}
}
}
}

Просмотреть файл

@ -184,6 +184,17 @@ namespace xharness
ExecuteInternal ();
}
}
public virtual IEnumerable<RelatedProject> GetRelatedProjects ()
{
return null;
}
}
public class RelatedProject
{
public string ProjectPath;
public string Guid;
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
@ -40,6 +41,7 @@ namespace xharness
csproj.FixCompileInclude ("Main.cs", Path.Combine (Harness.TodayContainerTemplate, "Main.cs").Replace ('/', '\\'));
csproj.FixInfoPListInclude (suffix);
TodayContainerGuid = "{" + Harness.NewStableGuid ().ToString ().ToUpper () + "}";
ProjectGuid = TodayContainerGuid;
csproj.SetProjectGuid (TodayContainerGuid);
Harness.Save (csproj, TodayContainerProjectPath);
@ -56,7 +58,7 @@ namespace xharness
{
var csproj = inputProject;
var suffix = "-today-extension";
csproj.SetProjectTypeGuids ("{FEACFBD2-3405-455C-9665-78FE426C6842};" + LanguageGuid);
csproj.SetProjectTypeGuids ("{EE2C853D-36AF-4FDB-B1AD-8E90477E2198};" + LanguageGuid);
csproj.SetOutputPath ("bin\\$(Platform)\\$(Configuration)" + suffix);
csproj.SetIntermediateOutputPath ("obj\\$(Platform)\\$(Configuration)" + suffix);
csproj.SetImport (IsFSharp ? "$(MSBuildExtensionsPath)\\Xamarin\\iOS\\Xamarin.iOS.AppExtension.FSharp.targets" : "$(MSBuildExtensionsPath)\\Xamarin\\iOS\\Xamarin.iOS.AppExtension.CSharp.targets");
@ -80,6 +82,7 @@ namespace xharness
info_plist.SetCFBundleIdentifier (BundleIdentifier + ".todayextension");
info_plist.SetMinimumOSVersion ("8.0");
info_plist.AddPListStringValue ("CFBundlePackageType", "XPC!");
info_plist.SetCFBundleDisplayName (Name);
info_plist.AddPListKeyValuePair ("NSExtension", "dict",
@"
<key>NSExtensionMainStoryboard</key>
@ -90,12 +93,6 @@ namespace xharness
Harness.Save (info_plist, target_info_plist);
}
protected override string Imports {
get {
return IsFSharp ? "$(MSBuildExtensionsPath)\\Xamarin\\WatchOS\\Xamarin.WatchOS.FSharp.targets" : "$(MSBuildExtensionsPath)\\Xamarin\\WatchOS\\Xamarin.WatchOS.CSharp.targets";
}
}
protected override void ExecuteInternal ()
{
ExtensionName = Name + " Today Extension";
@ -109,11 +106,18 @@ namespace xharness
CreateTodayContainerProject ();
break;
case "Library":
base.ExecuteInternal ();
CreateLibraryProject ();
break;
default:
throw new Exception (string.Format ("Unknown OutputType: {0}", OutputType));
}
}
public override IEnumerable<RelatedProject> GetRelatedProjects ()
{
return new RelatedProject [] {
new RelatedProject { Guid = TodayExtensionGuid, ProjectPath = TodayExtensionProjectPath },
};
}
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
@ -182,6 +183,14 @@ namespace xharness
return true;
}
}
public override IEnumerable<RelatedProject> GetRelatedProjects ()
{
return new RelatedProject [] {
new RelatedProject { Guid = WatchOSExtensionGuid, ProjectPath = WatchOSExtensionProjectPath },
new RelatedProject { Guid = WatchOSAppGuid, ProjectPath = WatchOSAppProjectPath },
};
}
}
}