Граф коммитов

157 Коммитов

Автор SHA1 Сообщение Дата
Stephane Delcroix 7cab837955 Merge branch '3.1.0' 2018-05-29 11:12:09 +02:00
Stephane Delcroix 012d248e2a Merge branch '3.0.0' into 3.1.0 2018-05-29 10:18:13 +02:00
Jason Smith b84b35bb5f [XamlG] builds incrementally, add MSBuild integration tests (#2825)
* [XamlG] builds incrementally, add MSBuild integration tests

Context: https://github.com/xamarin/Xamarin.Forms/pull/2230

The main performance problem with the collection of MSBuild targets in
`Xamarin.Forms.targets` is they don't build incrementally. I addressed
this with `XamlC` using a "stamp" file; however, it is not quite so
easy to setup the same thing with `XamlG`.

They way "incremental" builds are setup in MSBuild, is by specifying
the `Inputs` and `Outputs` of a `<Target />`. MSBuild will partially
build a target when some outputs are not up to date, and skip it
entirely if they are all up to date.

The best docs I can find on MSBuild incremental builds:
https://msdn.microsoft.com/en-us/library/ms171483.aspx

Unfortunately a few things had to happen to make this work for
`XamlG`:
- Define a new target `_FindXamlGFiles` that is invoked before `XamlG`
- `_FindXamlGFiles` defines the `_XamlGInputs` and `_XamlGOutputs`
  `<ItemGroup />`'s
- `_FindXamlGFiles` must also define `<Compile />` and `<FileWrites />`,
  in case the `XamlG` target is skipped
- `XamlGTask` now needs to get passed in a list of `OutputFiles`,
  since we have computed these paths ahead of time
- `XamlGTask` should validate the lengths of `XamlFiles` and
  `OutputFiles` match, used error message from MSBuild proper:
  a691a44f0e/src/Tasks/Copy.cs (L505)

`XamlG` now builds incrementally!

To give some context on how much improvement we can see with build
times, consider the following command:

    msbuild Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj

If you run it once, it will take a while--this change will not improve
the first build. On the second build with the exact same command, it
*should* be much faster.

Before this commit, the second build on my machine takes:

    40.563s

After the change:

    23.692s

`XamlG` has cascading impact on build times when it isn't built
incrementally:
- The C# assembly always changes
- Hence, `XamlC` will always run
- Hence, `GenerateJavaStubs` will always run
- Hence, `javac.exe` and `dx.jar` will always run

I am making other improvements like this in Xamarin.Android itself,
that will further improve these times, such as:
https://github.com/xamarin/xamarin-android/pull/1693

~~ New MSBuild Integration Tests ~~

Added some basic MSBuild testing infrastructure:
- Tests write project files to `bin/Debug/temp/TestName`
- Each test has an `sdkStyle` flag for testing the new project system
  versus the old one
- `[TearDown]` deletes the entire directory, with a retry for
  `IOException` on Windows
- Used the `Microsoft.Build.Locator` NuGet package for locating
  `MSBuild.exe` on Windows
- These tests take 2-5 seconds each

So for example, the simplest test, `BuildAProject` writes to
`Xamarin.Forms.Xaml.UnitTests\bin\Debug\temp\BuildAProject(False)\test.csproj`:

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <Configuration>Debug</Configuration>
        <Platform>AnyCPU</Platform>
        <OutputType>Library</OutputType>
        <OutputPath>bin\Debug</OutputPath>
        <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
      </PropertyGroup>
      <ItemGroup>
        <Reference Include="mscorlib" />
        <Reference Include="System" />
        <Reference Include="Xamarin.Forms.Core.dll">
          <HintPath>..\..\Xamarin.Forms.Core.dll</HintPath>
        </Reference>
        <Reference Include="Xamarin.Forms.Xaml.dll">
          <HintPath>..\..\Xamarin.Forms.Xaml.dll</HintPath>
        </Reference>
      </ItemGroup>
      <ItemGroup>
        <Compile Include="AssemblyInfo.cs" />
      </ItemGroup>
      <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
      <Import Project="..\..\..\..\..\.nuspec\Xamarin.Forms.targets" />
      <ItemGroup>
        <EmbeddedResource Include="MainPage.xaml" />
      </ItemGroup>
    </Project>

Invokes `msbuild`, and checks the intermediate output for files being
generated.

Tested scenarios:
- Build a simple project
- Build, then build again, and make sure targets were skipped
- Build, then clean, make sure files are gone
- Build, with linked files
- Design-time build
- Call `UpdateDesignTimeXaml` directly
- Build, add a new file, build again
- Build, update timestamp on a file, build again
- XAML file with random XML content
- XAML file with invalid XML content
- A general `EmbeddedResource` that shouldn't go through XamlG

Adding these tests found a bug! `IncrementalClean` was deleting
`XamlC.stamp`. I fixed this by using `<ItemGroup />`, which will be
propery evaluated even if the target is skipped.

~~ Other Changes ~~

- `FilesWrite` is actually supposed to be `FileWrites`, see canonical
  source of how `Clean` works and what `FileWrites` is here:
  https://github.com/Microsoft/msbuild/issues/2408#issuecomment-321082997
- Moved `DummyBuildEngine` into `MSBuild` directory--makes sense?
  maybe don't need to?
- Added a `XamlGDifferentInputOutputLengths` test to check the error
  message
- Expanded `DummyBuildEngine` so you can assert against log messages
- Changed a setting in `.Xamarin.Forms.Android.sln` so the unit test
  project is built
- My VS IDE monkeyed with a few files, and I kept any *good* (or
  relevant) changes: `Xamarin.Forms.UnitTests.csproj`,
  `Xamarin.Forms.Xaml.UnitTests\app.config`, etc.

There were some checks for `%(TargetPath)` being blank in the C# code
of `XamlGTask`. In that case it was using `Path.GetRandomFileName`,
but we can't do this if we are setting up inputs and outputs for
`XamlG`. I presume this is from the designer and/or design-time builds
before `DependsOnTargets="PrepareResourceNames"` was added. I tested
design-time builds in VS on Windows, and `$(TargetPath)` was set. To
be sure we don't break anything here, I exclude inputs to `XamlG` if
`%(TargetPath)` is somehow blank.

See relevant MSBuild code for `%(TargetPath)` here:

0515178090/src/Tasks/Microsoft.Common.CurrentVersion.targets (L2822)

~~ Future changes ~~

CssG needs the exact same setup, as it was patterned after `XamlG`.
This should probably be done in a future PR.

* [msbuild] improved lookup of Xamarin.Forms.targets in integration tests

Context: https://devdiv.visualstudio.com/DevDiv/_build?buildId=1717939
Context: https://devdiv.visualstudio.com/DevDiv/_build?buildId=1718306

It looks like the VSTS builds for release branches are running tests
in a staging directory. This means we can't reliably import
`Xamarin.Forms.targets` as what was working locally in the
Xamarin.Forms source tree.

So to fix this:
- Look for `.nuspec/Xamarin.Forms.targets`, at the default location
  and then using the `BUILD_SOURCESDIRECTORY` environment variable as
  a fallback
- Copy all `*.targets` files to the test directory
- Our `*.csproj` files under test can import the file from there.

We have to copy the targets files here to be sure that MSBuild can
load `Xamarin.Forms.Build.Tasks.dll`, which is also referenced by the
unit tests.

I also made the tests abort earlier if they can't find
`Xamarin.Forms.targets`.
2018-05-25 15:39:17 +01:00
Rui Marinho fda8a08528 Merge branch '3.1.0' 2018-05-04 12:35:41 +01:00
Stephane Delcroix ac551955a9 [CSS] lightgray is spelled lightgrey in CSS world (#2599) fixes #2596
- fixes #2596
2018-05-03 21:52:09 +01:00
Stephane Delcroix b0e8a12022
Namescope enhancements (#2556)
* [Xaml] open non-generic FindByName()

* [Xaml[C]] Only set the namescope when it's different

avoid setting the NamesCope if it's the same as the parent.

Also provide an IReferenceProvider for markup extension that need to
replicate the x:Reference behavior.
2018-05-03 20:06:52 +02:00
Stephane Delcroix 97a21256b4
[XamlG] creates fields for x:Name on root (#2582)
- fixes #2574
2018-05-02 21:02:46 +02:00
Stephane Delcroix 9e794d557a
[XamlC] throw on invalid xmlns on x:Datatype (#2568)
- fixes #2549
2018-04-30 15:23:37 +02:00
Stephane Delcroix 66175c1b1f Merge branch '3.0.0' 2018-04-26 11:03:15 +02:00
Stephane Delcroix acb053f5e7
[XamlC] meaningful error on missing property (#2525)
* [XamlC] x:DataType in default xmlns

* [XamlC] meaningful error on missing property

throw a readable exception when part of a compiled binding path is
missing.

- fixes #2517
2018-04-24 10:18:54 +02:00
Stephane Delcroix 6141cc3e9a
[XamlC] Import property typeRefs in BindingCompiler (#2523)
- fixes #2518
2018-04-24 09:40:57 +02:00
Stephane Delcroix 1ff3bffc23
[XamlC] correctly create ldc_i4 for uint (#2528)
- fixes #2508
2018-04-24 09:40:24 +02:00
Rui Marinho d70eb72329 Merge branch '3.0.0' 2018-04-23 14:50:26 +01:00
Stephane Delcroix f66a7fc971 [XamlC] pass the nsresolver to expanded value nodes 2018-04-20 09:48:41 +02:00
Stephane Delcroix d228656ec0 [Xaml[C]] consider subclass of RDs as RDs (#2487)
- fixes #2483
2018-04-19 20:50:47 -07:00
Stephane Delcroix d1bfe860fb
[XamlC] accept lowercase colors (#2494)
- fixes #2459
2018-04-18 20:41:11 +02:00
Stephane Delcroix ad1b0d8e15
[XamlC] cache ImportReference and ImportMethodReference as they're slow (#2025)
* [XamlC] cache ImportReference and ImportMethodReference as they're slow
on ns1.4

* more ns14 fixes
2018-04-11 21:36:11 +02:00
Stephane Delcroix bf52acf1c5
[Xaml[C]] don't fail if event has same name as ABP (#2154)
- fixes #2130
2018-03-21 16:33:48 +01:00
Stephane Delcroix 89964f1321
[XamlC] report missing ctor param (#2078)
for parameterized ctors, like Style.

 - fixes #2064
2018-03-13 22:09:57 +01:00
Stephane Delcroix bb07b71874
[XamlC] report undeclared xmlns on custom markups (#2076)
- fixes #2063
2018-03-13 21:35:43 +01:00
Stephane Delcroix 8403ef065b
[XamlC] Find the real VisualState parent (#2036)
`VisualStateGroupList` can be implicit, and it looks like tht wasn't
tested. This adds a test, and a fix.

 - fixes #2034
2018-03-08 16:20:25 +01:00
Stephane Delcroix 056f66e2dd [XamlC] better error reporting on missing Add()er (#1982)
- fixes #1978
2018-02-27 18:39:48 +00:00
Stephane Delcroix 463714be71 [XamlC] no longer use any reflection-base ImportReference (#1899)
* [XamlC] no longer use any reflection-base ImportReference

reflection-base ImportReference -- we were using MethodBase and Type --
are importing the types present in the reflection context, at the time
of compilation. As the compilation happens on netstandard2.0, and our
assembly can now be netstandard1.0 again, those imported types are
failing to be resolved.

this changes always import references based on the assembly, or the
assembly references.

it might, or might not, give us another speed bump.

* [XamlC] accomodate all kinds of netstandard versions

* reuse caching code
2018-02-26 11:07:18 +00:00
Stephane Delcroix 8e5a3baac3 [XamlC] do not log task input parameters 2018-02-14 10:19:27 +01:00
Stephane Delcroix af6f333790
[XamlC] Cache Resolve and ImportReference (#1875)
ImportReference with System.Reflection based argument is notoriously
slow on .NET. So we cache the results for those.

We do not cache the results for TypeReference, MethodReference or
FieldReference calls, as those are already fast (passthrough if the
reference was already imported), and they aren't valid as dictionary
keys (no concept of equatability).

While we're at it, we shave another few ms from Resolve(TypeReference)
calls as well.

As, on good days, it shaves up to 40% of XamlC time, we can say that it

 - fixes #1848
2018-02-13 22:27:02 +01:00
Stephane Delcroix 3a5eb2e0ce [internal] disposable performance helpers 2018-02-10 12:59:16 +01:00
Stephane Delcroix 6cbb51341a
[xamlg] version the CodeGeneratedAttribute (#1838)
- fixes #1810
2018-02-08 14:32:02 +01:00
Stephane Delcroix c44728e242
[build] reduce verbosity of build (#1837)
- fixes #1798
2018-02-08 14:31:35 +01:00
Stephane Delcroix f9b0b4ee29
[C/XamlC] BindingMode.OneTime (#1805)
* [C/XamlC] BindingMode.OneTime

Bindings with mode == OneTime:
 - are only applied when the BindingContext changes
 - do not subscribe to INPC

if the Binding is compiled and the mode explicitely set in the
`{Binding}` Markup extension, the setters and handlers aren't even
created.

 - fixes #1686

* update docs
2018-02-07 09:43:15 +01:00
Stephane Delcroix 73f891f0e6 [XamlC] get the Assembly through the TypeInfo (#1656)
- fixes bz 44130
2018-01-31 17:42:34 +00:00
Stephane Delcroix 6c7a085092
[XamlC] TypedBindings to self for value types (#1617)
fixes #1603
2018-01-19 11:33:20 +01:00
Stephane Delcroix f47c5e3a02
[XamlC][Bindings] value types in compiled bindings (#1604)
support value types in path of bindings that will be compiled.

fixes #1558
2018-01-18 20:13:31 +01:00
Stephane Delcroix 38f244aa49
[Xaml] let the previewer know the asm (#1594)
* [Xaml] let the previewer know the asm

in addition to the resourcePath, tell the previewer the assembly in
which we're looking for the resource.

* fix docs
2018-01-17 15:19:18 +01:00
Stephane Delcroix a24c7e5808
[Xaml[C]] avoid processing RD content multiple times (#1559)
Stop the RD visitor on the RD node, as the SetPropVisitor is taking over

fixes #1554
2018-01-11 20:03:12 +01:00
Stephane Delcroix 0618c35de2
[XamlC] resolve generic types with generic and non-generic parameters (#1533)
fixes #1497
2018-01-09 09:32:41 +01:00
E.Z. Hart 28948d7ef7 VisualStateManager phase 1 (#1405)
* Port from old VSM branch

* Add PS and notes

* Checkpoint: entry text UWP mostly working, need to check on background colors

* Remove irrelevant samples from the EntryDisabledStatesGallery
Make Background color work on UWP Entry with VSM

* Add platform specific for disabling legacy colors on Android

* Add OnPlatform example to visual state manager gallery

* Add example OnIdiom in Visual State Manager

* Add platform specific for disabling legacy color mode on iOS Entry

* Add gallery for Button disabled states
Handling legacy colors for Buttons on Android

* Split out disabled states galleries; disabled legacy handling for Picker

* TimePicker disabled states

* DatePicker color management on Android

* Color management for pre-AppCompat button

* Button legacy color handling on iOS

* Consolidate Platform Specifics;
legacy colors working for iOS Picker and DatePicker

* Fix broken search bar color management
SearchBar color management working with VSM
Add test page for SearchBar disabled color management
Consolidate legacy color management check code into extension method on Android

* Legacy color management for Editor on Android

* Fix legacy color stuff for SearchBar Cancel button on iOS

* C# 7 cleanup

* Add colors for Cancel Button

* Make sure VisualStateGroup collections set by styles are distinct objects

* Validation example

* Make common state names consts

* Make the Windows VSM and Forms VSM work together

* Update galleries for Windows

* Make new methods internal

* Split gallery classes and add more explanation to validation example

* Remove debugging statements

* Add a quick code-only example

* Make legacy color management work for fast button renderer

* Remove old TODO

* Update docs

* Move RunTimeNamePropertyAttribute to Xamarin.Forms.Xaml namespace

* Verify XF namespace when looking for VisualState

* Use nameof

* Make common states constants public

* Cast VisualElement directly so it crashes if the property is set on the wrong type

* Collection -> IList for VisualStateManager

* Setting fromStyle to true

* Remove extraneous `private set`

* Seal VSM classes

* Use constraints instead of ==

* Add teardown method; use constraints rather than ==

* Remove null checking with GetVisualStateGroups

* Don't explicitly initialize collections on elements

* Actually, turns out that fromStyle:false *was* correct

* Direct casts

* Use GetIsDefault check in GoToState

* Validate parents in FindTypeForVisualState

* Validate group and state names on Add

* Fixed check for setter collection

* Fix issues with "duplicate" names when VisualStateGroups declared directly on VisualElements

* Add gallery example for VSGs directly on VisualElements

* Update docs

* Fix bug where initial TextColor isn't set for FastRenderer Button

* Move to explicit VisualStateGroupList in Setter

* Fix return types for unit tests

* Using string.CompareOrdinal in GetState

* Update docs

* Add check for null/empty VisualState Name properties
2018-01-05 09:11:51 +00:00
Stephane Delcroix 5ea86a266b
Stylesheets (#1207)
* [*] Support for CSS StyleSheets

 Parsing, loading, and applying of StyleSheets

 see https://github.com/xamarin/Xamarin.Forms/pull/1207#issue-266464280
 for complete description.

* use initial, not none

* fix tests
2017-12-20 10:47:50 +01:00
WonYoung Choi 27ea629c41 Move XF.Build.Tasks to nestandard2.0 (#1370)
Remove net47 project of XF.Build.Tasks. Xamarin.Forms.nupkg provides
Xamarin.Forms.Build.Tasks.dll and dependencies built with netstandard2.0 only.
2017-12-13 14:29:57 +00:00
Stephane Delcroix 8ede382d02 Merge branch '15-5' 2017-12-13 12:59:38 +01:00
Stephane Delcroix 5d05344e12
[Xaml[C]] do not use implicit operator if the variable is assignable (#1372) 2017-12-13 09:06:31 +01:00
Stephane Delcroix 76aff96add [XamlC] fix typo 2017-12-12 12:49:28 +01:00
WonYoung Choi 9383a907c4 [XamlC] Add netstandard2.0 to Xamarin.Forms.Build.Tasks (#1284)
* Add netstandard2.0 to XF.Build.Tasks

* Separate XF.Build.Taks for netstandard 2.0

* Change comparison variable to determine XBuild
2017-12-07 13:58:16 +01:00
Jason Smith c2f576abe1 Merge branch '15-5' 2017-11-29 14:52:35 -08:00
Stephane Delcroix 2f84a94360 [Xaml[C]] avoid processing nested RD multiple times (#1300) 2017-11-29 10:57:32 -08:00
Rui Marinho b74d545fc1
[All] Move to netstandard2.0 **Breaking change** (#1306)
* Move to netstandard 2.0

* Fix docs

* Small fixes
2017-11-29 17:37:06 +00:00
Stephane Delcroix 9f0f002a26
[XamlC] update cecil to 0.10-b7 (#1301) 2017-11-22 15:01:10 +01:00
Stephane Delcroix 6a88e378f8
Auto merged ResourceDictionaries (#1297)
* [Xaml[C]] add merged resource dictionaries implicitly

* [docs] update docs
2017-11-22 14:56:20 +01:00
Stephane Delcroix 4c8f901e23
Lazy creation of ResourceDictionaries (#1295)
* [C,Xaml] allow implicit ResourceDictionaries

* [XamlC] implicit ResourceDictionaries

* [C] lazy Resources creation

* fix stupid docs

* [C] no need to trigger events on initial get
2017-11-22 12:59:55 +01:00
Stephane Delcroix 7a53ccda83
Fix bz60575 again (#1290)
* [Xaml] fix 60575 for collection with a single element

* [XamlC] fix 60575 for collection with a single element
2017-11-20 11:13:43 +01:00
Stephane Delcroix 4a4a1b1f5c
[XamlC] treat netstandard types as mscorlib (#1281)
If the end user project type differs from Core's type, the compiler can
be confused while comparing base styles, like System.Double.

this fixes that by assuming System.Runtime, mscorlib and netstnadard
types are equivalent (because they are)
2017-11-17 11:20:01 +01:00