[msbuild] Fixed Condition for CalculateCodesignAppBundleInputs (#2843)

* [msbuild] Fixed Condition for CalculateCodesignAppBundleInputs

CodesignAppBundle was not being executed because the inputs were empty.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=59379

* Codesign AppExtensiosn as well (and might as well run CodesignVerify too)

* Revert CompileEntitlements change, only compile them if we require codesigning

* Don't embed mobile provision file unless the build requires codesigning

* More fixes to codesigning iPhoneSimulator builds

* Fixed CodesignAppBundle tests to not check dsym timestamps for iPhoneSimulator builds

* Ignore the user's signing key & provisioning profile for Simulator builds

Xcode9 does not use them. It always codesigns Simulator builds with "-"
and never involves the specified provisioning profile.

This finally fixes the AppGroups sample to work properly

For CodesignVerify, having a _ProvisioningProfile defined means that
we have definitely codesigned the app bundle, so it makes sense to
verify the code signature (it probably doesn't make sense to do if
the codesign key is just "-", for example).
This commit is contained in:
Jeffrey Stedfast 2017-10-30 16:52:03 -04:00 коммит произвёл GitHub
Родитель 2510b805b2
Коммит cb216083f1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 57 добавлений и 50 удалений

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

@ -29,6 +29,7 @@ namespace Xamarin.MacDev.Tasks
[Required]
public string BundleIdentifier { get; set; }
[Output]
[Required]
public string CompiledEntitlements { get; set; }
@ -315,9 +316,6 @@ namespace Xamarin.MacDev.Tasks
Log.LogError ("Could not locate the provisioning profile with a Name or UUID of {0}.", ProvisioningProfile);
return false;
}
} else if (Platform == MobileProvisionPlatform.iOS) {
Log.LogError ("Provisioning Profiles are REQUIRED for iOS.");
return false;
} else {
profile = null;
}

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

@ -353,7 +353,7 @@ namespace Xamarin.MacDev.Tasks
return !Log.HasLoggedErrors;
}
if (!RequireProvisioningProfile && string.IsNullOrEmpty (ProvisioningProfile)) {
if (!RequireProvisioningProfile) {
if (SdkIsSimulator && AppleSdkSettings.XcodeVersion.Major >= 8) {
// Note: Starting with Xcode 8.0, we need to codesign iOS Simulator builds in order for them to run.
// The "-" key is a special value allowed by the codesign utility that allows us to get away with

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

@ -70,7 +70,6 @@ namespace Xamarin.iOS.Tasks
public string ArchiveSymbols { get; set; }
[Required]
public string CompiledEntitlements { get; set; }
[Required]
@ -82,8 +81,6 @@ namespace Xamarin.iOS.Tasks
[Required]
public bool EnableGenericValueTypeSharing { get; set; }
public string Entitlements { get; set; }
public string License { get; set; }
[Required]

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

@ -120,7 +120,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<_RequireCodeSigning Condition="'$(ComputedPlatform)' == 'iPhone'">True</_RequireCodeSigning>
<_RequireProvisioningProfile>False</_RequireProvisioningProfile>
<_RequireProvisioningProfile Condition="'$(ComputedPlatform)' == 'iPhone' Or '$(CodesignEntitlements)' != ''">True</_RequireProvisioningProfile>
<_RequireProvisioningProfile Condition="'$(ComputedPlatform)' == 'iPhone'">True</_RequireProvisioningProfile>
<_PreparedResourceRules></_PreparedResourceRules>
<_AppBundleName>$(AssemblyName)</_AppBundleName>
@ -781,10 +781,9 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
AppBundleDir="$(AppBundleDir)"
AppManifest="$(_AppBundlePath)Info.plist"
Architectures="$(TargetArchitectures)"
Entitlements="$(CodesignEntitlements)"
ExecutableName="$(_ExecutableName)"
NativeExecutable="$(_NativeExecutable)"
CompiledEntitlements="$(DeviceSpecificIntermediateOutputPath)Entitlements.xcent"
CompiledEntitlements="$(_CompiledEntitlements)"
Debug="$(MtouchDebug)"
EnableGenericValueTypeSharing="$(MtouchEnableGenericValueTypeSharing)"
ExtraArgs="$(MtouchExtraArgs)"
@ -1395,7 +1394,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<CreatePkgInfo SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" OutputPath="$(_AppBundlePath)PkgInfo" />
</Target>
<Target Name="_EmbedMobileProvision" Condition="'$(_RequireCodeSigning)' == 'true'" DependsOnTargets="_GenerateBundleName;_DetectSigningIdentity"
<Target Name="_EmbedMobileProvision" Condition="'$(_RequireProvisioningProfile)' == 'true'" DependsOnTargets="_GenerateBundleName;_DetectSigningIdentity"
Outputs="$(_AppBundlePath)embedded.mobileprovision">
<EmbedMobileProvision
SessionId="$(BuildSessionId)"
@ -1406,7 +1405,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
</EmbedMobileProvision>
</Target>
<Target Name="_CompileEntitlements" Condition="'$(_RequireCodeSigning)' == 'true' Or '$(CodesignEntitlements)' != ''" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectSigningIdentity"
<Target Name="_CompileEntitlements" Condition="'$(_RequireCodeSigning)' == 'true'" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectSigningIdentity"
Outputs="$(DeviceSpecificIntermediateOutputPath)Entitlements.xcent">
<CompileEntitlements
SessionId="$(BuildSessionId)"
@ -1422,6 +1421,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
SdkVersion="$(MtouchSdkVersion)"
TargetFrameworkIdentifier="$(TargetFrameworkIdentifier)"
>
<Output TaskParameter="CompiledEntitlements" PropertyName="_CompiledEntitlements" />
</CompileEntitlements>
</Target>
@ -1676,7 +1676,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<PropertyGroup>
<_CodesignDisableTimestamp>False</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_SdkIsSimulator)' == 'true' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_CodeSigningKey)' == '-' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
</PropertyGroup>
<CodesignNativeLibraries
@ -1700,7 +1700,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<PropertyGroup>
<_CodesignDisableTimestamp>False</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_SdkIsSimulator)' == 'true' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_CodeSigningKey)' == '-' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
</PropertyGroup>
<Codesign
@ -1735,7 +1735,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
</ReadItemsFromFile>
</Target>
<Target Name="_CodesignAppExtensions" Condition="'$(_RequireCodeSigning)' == 'true' And '@(_AppExtensionCodesignProperties)' != ''"
<Target Name="_CodesignAppExtensions" Condition="('$(_CanOutputAppBundle)' == 'true' And '$(_CodeSigningKey)' != '') And '@(_AppExtensionCodesignProperties)' != ''"
DependsOnTargets="_DetectSigningIdentity;_ReadAppExtensionCodesignProperties"
Inputs="$(_AppBundlePath)PlugIns\%(_AppExtensionCodesignProperties.Identity)\%(_AppExtensionCodesignProperties.NativeExecutable);%(_AppExtensionCodesignProperties.CodesignAppExtensionInputs)"
Outputs="$(_AppBundlePath)PlugIns\%(_AppExtensionCodesignProperties.Identity)\_CodeSignature\CodeResources">
@ -1773,14 +1773,15 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<Touch
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And '$(_RequireCodeSigning)' == 'true' And Exists ('$(AppBundleDir)\..\%(_AppExtensionCodesignProperties.Identity).dSYM\Contents\Info.plist')"
Condition="'$(IsMacEnabled)' == 'true' And ('$(_CanOutputAppBundle)' == 'true' And '$(_CodeSigningKey)' != '') And Exists ('$(AppBundleDir)\..\%(_AppExtensionCodesignProperties.Identity).dSYM\Contents\Info.plist')"
Files="$(AppBundleDir)\..\%(_AppExtensionCodesignProperties.Identity).dSYM\Contents\Info.plist"
/>
</Target>
<Target Name="_PrepareCodesignAppExtension" Condition="'$(_RequireCodeSigning)' == 'true' And '$(IsAppExtension)' == 'true' And '@(_ResolvedAppBundleExtensions)' == ''">
<Target Name="_PrepareCodesignAppExtension" Condition="('$(_CanOutputAppBundle)' == 'true' And '$(_CodeSigningKey)' != '') And '$(IsAppExtension)' == 'true' And '@(_ResolvedAppBundleExtensions)' == ''">
<!-- For App Extensions, we delay running codesign until it has been copied into the main app bundle... -->
<PropertyGroup>
<_CompiledEntitlementsFullPath></_CompiledEntitlementsFullPath>
<_ResourceRulesFullPath></_ResourceRulesFullPath>
</PropertyGroup>
@ -1788,8 +1789,8 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<Output TaskParameter="FullPath" PropertyName="_AppBundleFullPath" />
</GetFullPath>
<GetFullPath SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" RelativePath="$(DeviceSpecificIntermediateOutputPath)Entitlements.xcent">
<Output TaskParameter="FullPath" PropertyName="_EntitlementsFullPath" />
<GetFullPath SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true' And '$(_CompiledEntitlements)' != ''" RelativePath="$(_CompiledEntitlements)">
<Output TaskParameter="FullPath" PropertyName="_CompiledEntitlementsFullPath" />
</GetFullPath>
<GetFullPath SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true' And '$(_PreparedResourceRules)' != ''" RelativePath="$(_PreparedResourceRules)">
@ -1806,7 +1807,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<_NativeExecutableFileName>$([System.IO.Path]::GetFileName('$(_NativeExecutable)'))</_NativeExecutableFileName>
<_CodesignDisableTimestamp>False</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_SdkIsSimulator)' == 'true' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_CodeSigningKey)' == '-' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
<_CodesignAppExtensionInputs>@(_AppExtensionBundleFiles);$(_EntitlementsFullPath)</_CodesignAppExtensionInputs>
</PropertyGroup>
@ -1819,7 +1820,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<NativeExecutable>$(_NativeExecutableFileName)</NativeExecutable>
<CodesignAllocate>$(_CodesignAllocate)</CodesignAllocate>
<DisableTimestamp>$(_CodesignDisableTimestamp)</DisableTimestamp>
<Entitlements>$(_EntitlementsFullPath)</Entitlements>
<Entitlements>$(_CompiledEntitlementsFullPath)</Entitlements>
<ResourceRules>$(_ResourceRulesFullPath)</ResourceRules>
<Keychain>$(CodesignKeychain)</Keychain>
<SigningKey>$(_CodeSigningKey)</SigningKey>
@ -1837,7 +1838,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
/>
</Target>
<Target Name="_CalculateCodesignAppBundleInputs" Condition="'$(_RequireCodeSigning)' == 'true' And ('$(IsAppExtension)' == 'false' Or '@(_ResolvedAppExtensionReferences)' != '')">
<Target Name="_CalculateCodesignAppBundleInputs" Condition="('$(_CanOutputAppBundle)' == 'true' And '$(_CodeSigningKey)' != '') And ('$(IsAppExtension)' == 'false' Or '@(_ResolvedAppExtensionReferences)' != '')">
<ItemGroup>
<_CodesignAppBundleInputs Include="$(_AppBundlePath)**\*.*" Exclude="$(_AppBundlePath)_CodeSignature\CodeResources" />
</ItemGroup>
@ -1848,7 +1849,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<PropertyGroup>
<_CodesignDisableTimestamp>False</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_SdkIsSimulator)' == 'true' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_CodeSigningKey)' == '-' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
</PropertyGroup>
<Codesign
@ -1859,7 +1860,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
CodesignAllocate="$(_CodesignAllocate)"
DisableTimestamp="$(_CodesignDisableTimestamp)"
Keychain="$(CodesignKeychain)"
Entitlements="$(DeviceSpecificIntermediateOutputPath)Entitlements.xcent"
Entitlements="$(_CompiledEntitlements)"
ResourceRules="$(_PreparedResourceRules)"
Resources="$(AppBundleDir)"
SigningKey="$(_CodeSigningKey)"
@ -2004,7 +2005,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<IsStreamable Condition="'$(EmbedOnDemandResources)' == 'false'">true</IsStreamable>
<_CodesignDisableTimestamp>False</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_SdkIsSimulator)' == 'true' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
<_CodesignDisableTimestamp Condition="'$(_CodeSigningKey)' == '-' Or '$(MtouchDebug)' == 'true'">True</_CodesignDisableTimestamp>
</PropertyGroup>
<RemoveDir SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" Directories="$(_IntermediateODRDir)" />
@ -2048,7 +2049,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
CodesignAllocate="$(_CodesignAllocate)"
DisableTimestamp="$(_CodesignDisableTimestamp)"
Keychain="$(CodesignKeychain)"
Entitlements="$(DeviceSpecificIntermediateOutputPath)Entitlements.xcent"
Entitlements="$(_CompiledEntitlements)"
Resources="@(_AssetPack)"
SigningKey="$(_CodeSigningKey)"
ExtraArgs="$(CodesignExtraArgs)"
@ -2075,7 +2076,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
CodesignAllocate="$(_CodesignAllocate)"
DisableTimestamp="$(_CodesignDisableTimestamp)"
Keychain="$(CodesignKeychain)"
Entitlements="$(DeviceSpecificIntermediateOutputPath)Entitlements.xcent"
Entitlements="$(_CompiledEntitlements)"
ResourceRules="$(_PreparedResourceRules)"
Resources="$(_IpaAppBundleDir)"
SigningKey="$(_CodeSigningKey)"

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

@ -1,7 +1,9 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;
using NUnit.Framework;
@ -9,13 +11,15 @@ using Xamarin.MacDev;
namespace Xamarin.iOS.Tasks
{
[TestFixture ("Debug")]
[TestFixture ("Release")]
[TestFixture ("iPhone", "Debug")]
[TestFixture ("iPhone", "Release")]
[TestFixture ("iPhoneSimulator", "Debug")]
[TestFixture ("iPhoneSimulator", "Release")]
public class CodesignAppBundle : ProjectTest
{
readonly string config;
public CodesignAppBundle (string configuration) : base ("iPhone")
public CodesignAppBundle (string platform, string configuration) : base (platform)
{
config = configuration;
}
@ -62,8 +66,12 @@ namespace Xamarin.iOS.Tasks
var appexDsymDir = Path.GetFullPath (Path.Combine (AppBundlePath, "..", "MyActionExtension.appex.dSYM"));
var timestamps = Directory.EnumerateFiles (AppBundlePath, "*.*", SearchOption.TopDirectoryOnly).ToDictionary (file => file, file => GetLastModified (file));
var dsymTimestamps = Directory.EnumerateFiles (dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
var appexDsymTimestamps = Directory.EnumerateFiles (appexDsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
Dictionary<string, DateTime> dsymTimestamps = null, appexDsymTimestamps = null;
if (Platform != "iPhoneSimulator") {
dsymTimestamps = Directory.EnumerateFiles (dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
appexDsymTimestamps = Directory.EnumerateFiles (appexDsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
}
Thread.Sleep (1000);
@ -73,8 +81,6 @@ namespace Xamarin.iOS.Tasks
AssertProperlyCodesigned ();
var newTimestamps = Directory.EnumerateFiles (AppBundlePath, "*.*", SearchOption.TopDirectoryOnly).ToDictionary (file => file, file => GetLastModified (file));
var newDsymTimestamps = Directory.EnumerateFiles (dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
var newAppexDsymTimestamps = Directory.EnumerateFiles (appexDsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
foreach (var file in timestamps.Keys) {
// The executable files will all be newer because they get touched during each Build, all other files should not change
@ -84,22 +90,27 @@ namespace Xamarin.iOS.Tasks
Assert.AreEqual (timestamps[file], newTimestamps[file], "App Bundle timestamp changed: " + file);
}
foreach (var file in dsymTimestamps.Keys) {
// The Info.plist should be newer because it gets touched
if (Path.GetFileName (file) == "Info.plist") {
Assert.IsTrue (dsymTimestamps[file] < newDsymTimestamps[file], "App Bundle dSYMs Info.plist not touched: " + file);
} else {
Assert.AreEqual (dsymTimestamps[file], newDsymTimestamps[file], "App Bundle dSYMs changed: " + file);
}
}
if (Platform != "iPhoneSimulator") {
var newDsymTimestamps = Directory.EnumerateFiles (dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
var newAppexDsymTimestamps = Directory.EnumerateFiles (appexDsymDir, "*.*", SearchOption.AllDirectories).ToDictionary (file => file, file => GetLastModified (file));
// The appex dSYMs will all be newer because they currently get regenerated after each Build due to the fact that the entire
// *.appex gets cloned into the app bundle each time.
//
// Note: we could fix this by not using `ditto` and instead implementing this ourselves to only overwrite files if they've changed
// and then setting some [Output] params that specify whether or not we need to re-codesign and/or strip debug symbols.
foreach (var file in appexDsymTimestamps.Keys)
Assert.IsTrue (appexDsymTimestamps[file] < newAppexDsymTimestamps[file], "App Extension dSYMs should be newer: " + file);
foreach (var file in dsymTimestamps.Keys) {
// The Info.plist should be newer because it gets touched
if (Path.GetFileName (file) == "Info.plist") {
Assert.IsTrue (dsymTimestamps[file] < newDsymTimestamps[file], "App Bundle dSYMs Info.plist not touched: " + file);
} else {
Assert.AreEqual (dsymTimestamps[file], newDsymTimestamps[file], "App Bundle dSYMs changed: " + file);
}
}
// The appex dSYMs will all be newer because they currently get regenerated after each Build due to the fact that the entire
// *.appex gets cloned into the app bundle each time.
//
// Note: we could fix this by not using `ditto` and instead implementing this ourselves to only overwrite files if they've changed
// and then setting some [Output] params that specify whether or not we need to re-codesign and/or strip debug symbols.
foreach (var file in appexDsymTimestamps.Keys)
Assert.IsTrue (appexDsymTimestamps[file] < newAppexDsymTimestamps[file], "App Extension dSYMs should be newer: " + file);
}
}
[Test]