Skip to content

Commit

Permalink
Merge branch '3.0.0' into 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneDelcroix committed May 29, 2018
2 parents 9e44010 + 7a06d91 commit 012d248
Show file tree
Hide file tree
Showing 14 changed files with 598 additions and 60 deletions.
36 changes: 21 additions & 15 deletions .nuspec/Xamarin.Forms.targets
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,23 @@
</CoreCompileDependsOn>
</PropertyGroup>

<Target Name="XamlG" BeforeTargets="BeforeCompile" DependsOnTargets="PrepareResourceNames" Condition="'$(_XamlGAlreadyExecuted)'!='true'">
<PropertyGroup>
<_XamlGAlreadyExecuted>true</_XamlGAlreadyExecuted>
</PropertyGroup>
<Target Name="_FindXamlGFiles" DependsOnTargets="PrepareResourceNames">
<ItemGroup>
<_XamlGInputs Include="@(EmbeddedResource)" Condition="'%(Extension)' == '.xaml' AND '$(DefaultLanguageSourceExtension)' == '.cs' AND '%(TargetPath)' != ''" />
<_XamlGOutputs Include="@(_XamlGInputs->'$(IntermediateOutputPath)%(TargetPath).g.cs')" />
</ItemGroup>
</Target>

<Target Name="XamlG" BeforeTargets="BeforeCompile" DependsOnTargets="_FindXamlGFiles" Inputs="@(_XamlGInputs)" Outputs="@(_XamlGOutputs)">
<XamlGTask
XamlFiles="@(EmbeddedResource)" Condition="'%(Extension)' == '.xaml' AND '$(DefaultLanguageSourceExtension)' == '.cs'"
Language = "$(Language)"
AssemblyName = "$(AssemblyName)"
OutputPath = "$(IntermediateOutputPath)">
<Output ItemName="FilesWrite" TaskParameter="GeneratedCodeFiles" />
<Output ItemName="Compile" TaskParameter="GeneratedCodeFiles" />
</XamlGTask>
XamlFiles="@(_XamlGInputs)"
OutputFiles="@(_XamlGOutputs)"
Language="$(Language)"
AssemblyName="$(AssemblyName)" />
<ItemGroup>
<FileWrites Include="@(_XamlGOutputs)" />
<Compile Include="@(_XamlGOutputs)" />
</ItemGroup>
</Target>

<!-- XamlC -->
Expand All @@ -94,9 +99,10 @@
DebugSymbols = "$(DebugSymbols)"
DebugType = "$(DebugType)"
KeepXamlResources = "$(XFKeepXamlResources)" />
<Touch Files="$(IntermediateOutputPath)XamlC.stamp" AlwaysCreate="True">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites"/>
</Touch>
<Touch Files="$(IntermediateOutputPath)XamlC.stamp" AlwaysCreate="True" />
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)XamlC.stamp" />
</ItemGroup>
</Target>

<!-- CssG -->
Expand All @@ -115,7 +121,7 @@
Language = "$(Language)"
AssemblyName = "$(AssemblyName)"
OutputPath = "$(IntermediateOutputPath)">
<Output ItemName="FilesWrite" TaskParameter="GeneratedCodeFiles" />
<Output ItemName="FileWrites" TaskParameter="GeneratedCodeFiles" />
<Output ItemName="Compile" TaskParameter="GeneratedCodeFiles" />
</CssGTask>
</Target>
Expand Down
32 changes: 16 additions & 16 deletions Xamarin.Forms.Build.Tasks/XamlGTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;

Expand All @@ -10,44 +9,45 @@ namespace Xamarin.Forms.Build.Tasks
{
public class XamlGTask : Task
{
List<ITaskItem> _generatedCodeFiles = new List<ITaskItem>();

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

[Output]
public ITaskItem[] GeneratedCodeFiles => _generatedCodeFiles.ToArray();
[Required]
public ITaskItem[] OutputFiles { get; set; }

public string Language { get; set; }
public string AssemblyName { get; set; }
public string OutputPath { get; set; }

public override bool Execute()
{
bool success = true;
Log.LogMessage(MessageImportance.Normal, "Generating code behind for XAML files");

if (XamlFiles == null) {
//NOTE: should not happen due to [Required], but there appears to be a place this is class is called directly
if (XamlFiles == null || OutputFiles == null) {
Log.LogMessage("Skipping XamlG");
return true;
}

foreach (var xamlFile in XamlFiles) {
//when invoked from `UpdateDesigntimeXaml` target, the `TargetPath` isn't set, use a random one instead
var targetPath = xamlFile.GetMetadata("TargetPath");
if (string.IsNullOrWhiteSpace(targetPath))
targetPath = $".{Path.GetRandomFileName()}";
if (XamlFiles.Length != OutputFiles.Length) {
Log.LogError("\"{2}\" refers to {0} item(s), and \"{3}\" refers to {1} item(s). They must have the same number of items.", XamlFiles.Length, OutputFiles.Length, "XamlFiles", "OutputFiles");
return false;
}

var outputFile = Path.Combine(OutputPath, $"{targetPath}.g.cs");
for (int i = 0; i < XamlFiles.Length; i++) {
var xamlFile = XamlFiles[i];
var outputFile = OutputFiles[i].ItemSpec;
if (Path.DirectorySeparatorChar == '/' && outputFile.Contains(@"\"))
outputFile = outputFile.Replace('\\','/');
else if (Path.DirectorySeparatorChar == '\\' && outputFile.Contains(@"/"))
outputFile = outputFile.Replace('/', '\\');

var generator = new XamlGenerator(xamlFile, Language, AssemblyName, outputFile, Log);
try {
if (generator.Execute())
_generatedCodeFiles.Add(new TaskItem(Microsoft.Build.Evaluation.ProjectCollection.Escape(outputFile)));
if (!generator.Execute()) {
//If Execute() fails, the file still needs to exist because it is added to the <Compile/> ItemGroup
File.WriteAllText (outputFile, string.Empty);
}
}
catch (XmlException xe) {
Log.LogError(null, null, null, xamlFile.ItemSpec, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
<MtouchLink>None</MtouchLink>
<MtouchDebug>True</MtouchDebug>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchSdkVersion>
</MtouchSdkVersion>
<MtouchProfiling>False</MtouchProfiling>
<MtouchFastDev>False</MtouchFastDev>
<MtouchEnableGenericValueTypeSharing>True</MtouchEnableGenericValueTypeSharing>
Expand Down Expand Up @@ -70,8 +68,6 @@
<MtouchDebug>True</MtouchDebug>
<CodesignEntitlements>
</CodesignEntitlements>
<MtouchSdkVersion>
</MtouchSdkVersion>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchProfiling>False</MtouchProfiling>
<MtouchExtraArgs />
Expand Down Expand Up @@ -274,7 +270,7 @@
<Reference Include="Xamarin.iOS" />
<Reference Include="netstandard" />
<Reference Include="Calabash">
<HintPath>..\packages\Xamarin.TestCloud.Agent.0.21.4\lib\Xamarin.iOS\Calabash.dll</HintPath>
<HintPath>..\packages\Xamarin.TestCloud.Agent.0.21.5\lib\Xamarin.iOS\Calabash.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.ControlGallery.iOS/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
<package id="System.Xml.XmlDocument" version="4.3.0" targetFramework="xamarinios10" />
<package id="Xam.Plugin.DeviceInfo" version="3.0.2" targetFramework="xamarinios10" />
<package id="Xamarin.Insights" version="1.12.3" targetFramework="xamarinios10" />
<package id="Xamarin.TestCloud.Agent" version="0.21.4" targetFramework="xamarinios10" />
<package id="Xamarin.TestCloud.Agent" version="0.21.5" targetFramework="xamarinios10" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<Name>Xamarin.Forms.Maps</Name>
</ProjectReference>
<ProjectReference Include="..\Xamarin.Forms.Platform\Xamarin.Forms.Platform.csproj">
<Project>{67f9d3a8-f71e-4428-913f-c37ae82cdb24}</Project>
<Project>{D31A6537-ED9C-4EBD-B231-A8D4FE44126A}</Project>
<Name>Xamarin.Forms.Platform</Name>
</ProjectReference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Build.Framework;

namespace Xamarin.Forms.Xaml.UnitTests
{
public class DummyBuildEngine : IBuildEngine
{
public List<BuildErrorEventArgs> Errors { get; } = new List<BuildErrorEventArgs> ();

public List<BuildWarningEventArgs> Warnings { get; } = new List<BuildWarningEventArgs> ();

public List<BuildMessageEventArgs> Messages { get; } = new List<BuildMessageEventArgs> ();

public void LogErrorEvent (BuildErrorEventArgs e)
{
Errors.Add (e);
}

public void LogWarningEvent (BuildWarningEventArgs e)
{
Warnings.Add (e);
}

public void LogMessageEvent (BuildMessageEventArgs e)
{
Messages.Add (e);
}

public void LogCustomEvent (CustomBuildEventArgs e)
Expand Down
Loading

0 comments on commit 012d248

Please sign in to comment.