Skip to content

Commit e3abe4b

Browse files
authored
[libzip-windows] Fix building with msbuild (#1491)
Whenever `external/mono` is bumped, the [`xamarin-android-msbuild` job breaks][0]: [0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-msbuild/838/ Building target "_Make" completely. ... Task "Touch" (TaskId:1642) Task Parameter: Files= …/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/x64/libzip.dll CMake=/Users/builder/android-toolchain/mxe-b9cbb53/bin/x86_64-w64-mingw32.static-cmake CMakeFlags= CopyToOutputDirectory=Always OutputLibrary=x64/libzip.dll OutputLibraryPath=lib/libzip.dll …/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/libzip.dll CMake=/Users/builder/android-toolchain/mxe-b9cbb53/bin/i686-w64-mingw32.static-cmake CMakeFlags= CopyToOutputDirectory=Always OutputLibrary=libzip.dll OutputLibraryPath=lib/libzip.dll (TaskId:1642) Touching "…/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/x64/libzip.dll". (TaskId:1642) …/build-tools/libzip/libzip.targets(52,5): error MSB3375: The file "…/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/libzip.dll" does not exist. […/build-tools/libzip-windows/libzip-windows.csproj] Done executing task "Touch" -- FAILED. (TaskId:1642) This is due to an "`xbuild`-ism" we were inadvertently using which `msbuild` doesn't like: when item metadata is used in `//Target/@Inputs`, [MSBuild Target Batching][1] is *not* used. [1]: https://msdn.microsoft.com/en-us/library/ms171473.aspx Case in point, the `_Make` target: <!-- BAD! --> <Target Name="_Make" Condition=" '@(_LibZipTarget)' != '' " Inputs="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile" Outputs="@(Content)"> Because this used "inline" item metadata, the target wasn't being batched as intended (and as `xbuild` does). Consequently, `@(_LibZipTarget)` was only being built for mxe-Win64, *not* mxe-Win32, which is why the `<Touch/>` use within the `_Make` target failed. The fix? Don't Do That™. Instead, use a new `@(_LibZipTargetMakefile)` item group for the `//Target/@Inputs`, which allows `msbuild` to properly batch the `_Make` target contents: <ItemGroup> <_LibZipTargetMakefile Include="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile" /> </ItemGroup> <Target Name="_Make" Condition=" '@(_LibZipTarget)' != '' " Inputs="@(_LibZipTargetMakefile)" Outputs="@(Content)"> Review other files matching `git grep 'Inputs=.*%'` and fix them too.
1 parent 0f0f783 commit e3abe4b

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

build-tools/api-xml-adjuster/api-xml-adjuster.targets

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
AdditionalMetadata="ParameterDescription=$(_TopDir)\src\Mono.Android\Profiles\api-%(AndroidApiInfo.Level).params.txt;ClassParseXml=$(_OutputPath)api\api-%(AndroidApiInfo.Level).xml.class-parse;ApiAdjustedXml=$(_OutputPath)api\api-%(AndroidApiInfo.Level).xml.in">
1313
<Output TaskParameter="Include" ItemName="ApiFileDefinition"/>
1414
</CreateItem>
15+
<ItemGroup>
16+
<_ApiParameterDescription Include="%(ApiFileDefinition.ParameterDescription)" />
17+
<_ApiClassParseXml Include="%(ApiFileDefinition.ClassParseXml)" />
18+
<_ApiAdjustedXml Include="%(ApiFileDefinition.ApiAdjustedXml)" />
19+
</ItemGroup>
1520
</Target>
1621

1722
<Target Name="_ClassParse"
1823
BeforeTargets="_AdjustApiXml"
1924
DependsOnTargets="_DefineApiFiles"
20-
Inputs="%(ApiFileDefinition.ParameterDescription)"
21-
Outputs="%(ApiFileDefinition.ClassParseXml)">
25+
Inputs="@(_ApiParameterDescription)"
26+
Outputs="@(_ApiClassParseXml)">
2227
<PropertyGroup>
2328
<ClassParse>$(_TopDir)\bin\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android\class-parse.exe</ClassParse>
2429
</PropertyGroup>
@@ -31,8 +36,8 @@
3136
<Target Name="_AdjustApiXml"
3237
AfterTargets="Build"
3338
DependsOnTargets="_DefineApiFiles"
34-
Inputs="%(ApiFileDefinition.ClassParseXml)"
35-
Outputs="%(ApiFileDefinition.ApiAdjustedXml)">
39+
Inputs="@(_ApiClassParseXml)"
40+
Outputs="@(_ApiAdjustedXml)">
3641
<PropertyGroup>
3742
<ApiXmlAdjuster>$(_TopDir)\bin\Build$(Configuration)\api-xml-adjuster.exe</ApiXmlAdjuster>
3843
</PropertyGroup>

src/libzip/libzip.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3838
</Content>
3939
</ItemGroup>
40+
<ItemGroup>
41+
<_LibZipTargetMakefile Include="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile" />
42+
</ItemGroup>
4043
<Target Name="_Make"
4144
Condition=" '@(_LibZipTarget)' != '' "
42-
Inputs="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile"
45+
Inputs="@(_LibZipTargetMakefile)"
4346
Outputs="@(Content)">
4447
<Exec
4548
Command="make"

src/mono-runtimes/mono-runtimes.targets

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,14 +786,19 @@
786786
/>
787787
</Target>
788788

789+
<ItemGroup>
790+
<_MonoCrossRuntimeStamp Include="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\.stamp" />
791+
<_MonoCrossRuntimeIntermediateOutput Include="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\mono\mini\mono-sgen%(_MonoCrossRuntime.ExeSuffix)" />
792+
<_MonoCrossRuntimeOutput Include="$(_MSBuildDir)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)" />
793+
</ItemGroup>
789794

790795
<!-- The condition below is to work around a bug in xbuild which attempts to batch
791796
even if there are no _MonoCrossRuntime items and the Copy task fails
792797
-->
793798
<Target Name="_BuildCrossRuntimes"
794799
DependsOnTargets="_GenerateCrossOffsetHeaderFiles"
795-
Inputs="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\.stamp"
796-
Outputs="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\mono\mini\mono-sgen%(_MonoCrossRuntime.ExeSuffix)"
800+
Inputs="@(_MonoCrossRuntimeStamp)"
801+
Outputs="@(_MonoCrossRuntimeIntermediateOutput)"
797802
Condition=" '@(_MonoCrossRuntime)' != '' ">
798803
<Message Text="Building %(_MonoCrossRuntime.Identity) in $(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)"/>
799804
<Exec
@@ -802,16 +807,16 @@
802807
WorkingDirectory="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)"
803808
/>
804809
<Touch
805-
Files="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\mono\mini\mono-sgen%(_MonoCrossRuntime.ExeSuffix)"
810+
Files="@(_MonoCrossRuntimeIntermediateOutput)"
806811
/>
807812
</Target>
808813

809814
<!-- The condition below is to work around a bug in xbuild which attempts to batch
810815
even if there are no _MonoCrossRuntime items and the Copy task fails
811816
-->
812817
<Target Name="_InstallCrossRuntimes"
813-
Inputs="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\mono\mini\mono-sgen%(_MonoCrossRuntime.ExeSuffix)"
814-
Outputs="$(_MSBuildDir)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)"
818+
Inputs="@(_MonoCrossRuntimeIntermediateOutput)"
819+
Outputs="@(_MonoCrossRuntimeOutput)"
815820
Condition=" '@(_MonoCrossRuntime)' != '' ">
816821
<Copy
817822
SourceFiles="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\mono\mini\mono-sgen%(_MonoCrossRuntime.ExeSuffix)"
@@ -826,7 +831,7 @@
826831
Command="&quot;%(_MonoCrossRuntime.Strip)&quot; %(_MonoCrossRuntime.StripFlags) &quot;$(_MSBuildDir)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)&quot;"
827832
/>
828833
<Touch
829-
Files="$(_MSBuildDir)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)"
834+
Files="@(_MonoCrossRuntimeOutput)"
830835
/>
831836
</Target>
832837
<Target Name="GetMonoBundleItems"

0 commit comments

Comments
 (0)