Skip to content

[build] Fix the Linux build (Take 2?) - #407

Merged
radical merged 1 commit into
dotnet:masterfrom
jonpryor:jonp-fix-linux-build-2
Feb 13, 2017
Merged

[build] Fix the Linux build (Take 2?)#407
radical merged 1 commit into
dotnet:masterfrom
jonpryor:jonp-fix-linux-build-2

Conversation

@jonpryor

@jonpryor jonpryor commented Jan 25, 2017

Copy link
Copy Markdown
Contributor

As feared, commit 743529c's removal of $(TargetFrameworkRootPath)
broke the Linux build:

    Gui/Activities/TestSuiteActivity.cs(25,35): error CS0012: The type `System.IDisposable' is defined in an assembly that is not referenced.
    Consider adding a reference to assembly `System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

macOS is unaffected as it's unfortunately using System files:

    Found framework definition list '/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/RedistList/FrameworkList.xml' for framework 'MonoAndroid,Version=v1.0'

(Heavy sigh.)

Thus, our scenario: msbuild doesn't like our setting
$(TargetFrameworkRootPath), yet $(TargetFrameworkRootPath) needs
to be set for Linux+xbuild to work, because Linux+xbuild doesn't have
a system-wide Xamarin.Android install. (Not that we want to require a
Xamarin.Android install! But that's just why macOS is building...)

The fix? Split the difference, somewhat. We can't set
$(TargetFrameworkRootPath) for everything, but we can override
it for specific projects. Update Mono.Data.Sqlite.csproj,
Mono.Posix.csproj, OpenTK.csproj,
System.Drawing.Primitives.csproj,
System.EnterpriseServices.csproj, and
Xamarin.Android.NUnitLite.csproj to <Import/> the new
build-tools/scripts/MonoAndroidFramework.props file, which
overrides $(TargetFrameworkRootPath) and other MSBuild properties
appropriately, so that they resolve the MonoAndroid framework
assemblies from the internal build tree.

What's left is Mono.Android.csproj and Mono.Android.Export.csproj,
which don't <Import/> Xamarin.Android.CSharp.targets. These are
the projects that needed to "hack in" a @(Reference) to
System.Runtime in 7343965, which was removed in 743529c. The fix is
more voodoo in each of them:

  • Set $(ImplicitlyExpandDesignTimeFacades)=False and provide a
    %(Reference.HintPath) value for System.Runtimeso that it can be found. We *don't* want$(ImplicitlyExpandDesignTimeFacades)`=True because that can cause
    all manner of madness on macOS, as it "implicitly expands
    facades", pulling in facades from both the internal build tree
    and the system-wide location. (Madness, and duplicate assembly
    reference errors, ensue.)
  • Set $(TargetFrameworkIdentifier)=MonoAndroid, so we're looking for
    the correct framework.
  • Set $(TargetFrameworkRootPath) so that the MonoAndroid framework
    can be found in the local build tree.
  • Set $(TargetFrameworkVersion) to a valid MonoAndroid framework
    version number.

This allows Mono.Android.Export.csproj. Mono.Android.csproj needs
one more fix: in order for frameworks to be resolved from a "clean"
state, RedistList\FrameworkList.xml must exist before attempting to
resolve assemblies. Fix the _GenerateFrameworkList target so that
FrameworkList.xml is created before the ResolveReferences
target, thus allowing the MonoAndroid,v7.1 framework to be found.

One more final tidbit: MonoAndroidFramework.props and msbuild.mk
in concert use (and set) the new
$(_XAFixMSBuildFrameworkPathOverride) MSBuild property, which is set
when:

  1. msbuild is being used, and
  2. Mono is a version prior to Mono 4.8.

The msbuild included in Mono prior to 4.8 has a known bug where
$(FrameworkOverridePath) doesn't respect $(TargetFrameworkRootPath).
Without this fix, too many mscorlib.dll files are used in various
parts of the build process (via @(_ExplicitReference)), which causes
yet more sadness.

When using msbuild prior to Mono 4.8, explicitly set the
$(FrameworkOverridePath) property to a valid value.

@jonpryor jonpryor added the do-not-merge PR should not be merged. label Jan 25, 2017
@jonpryor
jonpryor force-pushed the jonp-fix-linux-build-2 branch 2 times, most recently from 6b52841 to 6990877 Compare January 25, 2017 21:15
@jonpryor jonpryor changed the title [build] Fix the Linux build [build] Fix the Linux build (Take 2?) Jan 25, 2017
@jonpryor
jonpryor force-pushed the jonp-fix-linux-build-2 branch 16 times, most recently from cc4af9a to 1614034 Compare February 13, 2017 20:44
As feared, commit 743529c's removal of `$(TargetFrameworkRootPath)`
[broke the Linux build][0]:

	Gui/Activities/TestSuiteActivity.cs(25,35): error CS0012: The type `System.IDisposable' is defined in an assembly that is not referenced.
	Consider adding a reference to assembly `System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

macOS is unaffected as [it's unfortunately using System files][1]:

	Found framework definition list '/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/RedistList/FrameworkList.xml' for framework 'MonoAndroid,Version=v1.0'

(Heavy sigh.)

Thus, our scenario: `msbuild` doesn't like our setting
`$(TargetFrameworkRootPath)`, yet `$(TargetFrameworkRootPath)` needs
to be set for Linux+xbuild to work, because Linux+xbuild doesn't have
a system-wide Xamarin.Android install. (Not that we want to require a
Xamarin.Android install! But that's just why macOS is building...)

The fix? Split the difference, somewhat. We can't set
`$(TargetFrameworkRootPath)` for *everything*, but we *can* override
it for *specific projects*. Update `Mono.Data.Sqlite.csproj`,
`Mono.Posix.csproj`, `OpenTK.csproj`,
`System.Drawing.Primitives.csproj`,
`System.EnterpriseServices.csproj`, and
`Xamarin.Android.NUnitLite.csproj` to `<Import/>` the new
`build-tools/scripts/MonoAndroidFramework.props` file, which
overrides `$(TargetFrameworkRootPath)` and other MSBuild properties
appropriately, so that they resolve the `MonoAndroid` framework
assemblies from the internal build tree.

What's left is `Mono.Android.csproj` and `Mono.Android.Export.csproj`,
which don't `<Import/>` `Xamarin.Android.CSharp.targets`. These are
the projects that needed to "hack in" a `@(Reference)` to
`System.Runtime` in 7343965, which was removed in 743529c. The fix is
more voodoo in each of them:

* Set `$(ImplicitlyExpandDesignTimeFacades)`=False and provide a
    `%(Reference.HintPath) value for `System.Runtime` so that it can
    be found. We *don't* want
    `$(ImplicitlyExpandDesignTimeFacades)`=True because that can cause
    all manner of madness on macOS, as it "implicitly expands
    facades", pulling in facades from *both* the internal build tree
    *and* the system-wide location. (Madness, and duplicate assembly
    reference errors, ensue.)
* Set `$(TargetFrameworkIdentifier)`=MonoAndroid, so we're looking for
    the correct framework.
* Set `$(TargetFrameworkRootPath)` so that the MonoAndroid framework
    can be found in the local build tree.
* Set `$(TargetFrameworkVersion)` to a valid MonoAndroid framework
    version number.

This allows `Mono.Android.Export.csproj`. `Mono.Android.csproj` needs
one more fix: in order for frameworks to be resolved from a "clean"
state, `RedistList\FrameworkList.xml` must exist before attempting to
resolve assemblies. Fix the `_GenerateFrameworkList` target so that
`FrameworkList.xml` is created *before* the `ResolveReferences`
target, thus allowing the `MonoAndroid,v7.1` framework to be found.

One more final tidbit: `MonoAndroidFramework.props` and `msbuild.mk`
in concert use (and set) the new
`$(_XAFixMSBuildFrameworkPathOverride)` MSBuild property, which is set
when:

1. `msbuild` is being used, and
2. Mono is a version prior to Mono 4.8.

The `msbuild` included in Mono prior to 4.8 has a known bug where
[`$(FrameworkOverridePath)` doesn't respect `$(TargetFrameworkRootPath)`][2].
Without this fix, *too many* `mscorlib.dll` files are used in various
parts of the build process (via `@(_ExplicitReference)`), which causes
yet more sadness.

When using `msbuild` prior to Mono 4.8, explicitly set the
`$(FrameworkOverridePath)` property to a valid value.

[0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-linux/173/
[1]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/207/consoleText
[2]: mono/msbuild@9d7b4b5
@jonpryor
jonpryor force-pushed the jonp-fix-linux-build-2 branch from 1614034 to f3d04eb Compare February 13, 2017 21:33
@jonpryor jonpryor removed the do-not-merge PR should not be merged. label Feb 13, 2017
@radical
radical merged commit 0eee673 into dotnet:master Feb 13, 2017
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants