Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msbuild] Tweak the codesign logic for iOS Simulator builds #3114

Merged
merged 3 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,53 +344,35 @@ public override bool Execute ()
return false;
}

if (Framework == PlatformFramework.MacOS && !RequireCodeSigning) {
DetectedBundleId = identity.BundleId;
DetectedAppId = DetectedBundleId;

ReportDetectedCodesignInfo ();
if (Framework == PlatformFramework.MacOS) {
if (!RequireCodeSigning) {
DetectedBundleId = identity.BundleId;
DetectedAppId = DetectedBundleId;

return !Log.HasLoggedErrors;
}
ReportDetectedCodesignInfo ();

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
// not having an actual codesign key. As far as we know, this only works with Xcode >= 8.
DetectedCodeSigningKey = "-";
} else {
// Try and get a valid codesigning certificate...
if (!TryGetSigningCertificates (out certs, SdkIsSimulator))
return false;

if (certs.Count > 0) {
if (certs.Count > 1) {
if (!string.IsNullOrEmpty (SigningKey))
Log.LogMessage (MessageImportance.Normal, "Multiple signing identities match '{0}'; using the first match.", SigningKey);
else
Log.LogMessage (MessageImportance.Normal, "Multiple signing identities found; using the first identity.");

for (int i = 0; i < certs.Count; i++) {
Log.LogMessage (MessageImportance.Normal, "{0,3}. Signing Identity: {1} ({2})", i + 1,
SecKeychain.GetCertificateCommonName (certs[i]), certs[i].Thumbprint);
}
}

codesignCommonName = SecKeychain.GetCertificateCommonName (certs[0]);
DetectedCodeSigningKey = certs[0].Thumbprint;
return !Log.HasLoggedErrors;
}
} else {
// Framework is either iOS, tvOS or watchOS
if (SdkIsSimulator) {
if (AppleSdkSettings.XcodeVersion.Major >= 8 && RequireProvisioningProfile) {
// Note: Starting with Xcode 8.0, we need to codesign iOS Simulator builds that enable Entitlements
// in order for them to run. The "-" key is a special value allowed by the codesign utility that
// allows us to get away with not having an actual codesign key.
DetectedCodeSigningKey = "-";
} else {
// Note: We don't have to codesign for iOS Simulator builds meant to run on Xcode iOS Simulators
// older than 8.0, so it's non-fatal if we don't find any...
// Note: Do not codesign. Codesigning seems to break the iOS Simulator in older versions of Xcode.
DetectedCodeSigningKey = null;
}
}

DetectedBundleId = identity.BundleId;
DetectedAppId = DetectedBundleId;
DetectedBundleId = identity.BundleId;
DetectedAppId = DetectedBundleId;

ReportDetectedCodesignInfo ();
ReportDetectedCodesignInfo ();

return !Log.HasLoggedErrors;
return !Log.HasLoggedErrors;
}
}

// Note: if we make it this far, we absolutely need a codesigning certificate
Expand Down
5 changes: 0 additions & 5 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,6 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<Output TaskParameter="DetectedDistributionType" PropertyName="_DistributionType" />
<Output TaskParameter="DetectedProvisioningProfile" PropertyName="_ProvisioningProfile" />
</DetectSigningIdentity>

<PropertyGroup>
<!-- Always use '-' as the signing key for iOS Simulator builds -->
<_CodeSigningKey Condition="'$(_SdkIsSimulator)' == 'true'">-</_CodeSigningKey>
</PropertyGroup>
</Target>

<Target Name="_GenerateBundleName" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="_ComputeTargetArchitectures">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,29 @@ static bool IsCodesigned (string path)
return process.ExitCode == 0;
}

void AssertProperlyCodesigned ()
void AssertProperlyCodesigned (bool expected)
{
foreach (var dylib in Directory.EnumerateFiles (AppBundlePath, "*.dylib", SearchOption.AllDirectories))
Assert.IsTrue (IsCodesigned (dylib), "{0} is not properly codesigned.", dylib);
Assert.AreEqual (expected, IsCodesigned (dylib), "{0} is not properly codesigned.", dylib);

foreach (var appex in Directory.EnumerateDirectories (AppBundlePath, "*.appex", SearchOption.AllDirectories))
Assert.IsTrue (IsCodesigned (appex), "{0} is not properly codesigned.", appex);
Assert.AreEqual (expected, IsCodesigned (appex), "{0} is not properly codesigned.", appex);

var watchDir = Path.Combine (AppBundlePath, "Watch");
if (Directory.Exists (watchDir)) {
foreach (var watchApp in Directory.EnumerateDirectories (watchDir, "*.app", SearchOption.TopDirectoryOnly))
Assert.IsTrue (IsCodesigned (watchApp), "{0} is not properly codesigned.", watchApp);
Assert.AreEqual (expected, IsCodesigned (watchApp), "{0} is not properly codesigned.", watchApp);
}
}

[Test]
public void RebuildNoChanges ()
{
bool expectedCodesignResults = Platform != "iPhoneSimulator";

BuildProject ("MyTabbedApplication", Platform, config, clean: true);

AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);

var dsymDir = Path.GetFullPath (Path.Combine (AppBundlePath, "..", "MyTabbedApplication.app.dSYM"));
var appexDsymDir = Path.GetFullPath (Path.Combine (AppBundlePath, "..", "MyActionExtension.appex.dSYM"));
Expand All @@ -78,7 +80,7 @@ public void RebuildNoChanges ()
// Rebuild w/ no changes
BuildProject ("MyTabbedApplication", Platform, config, clean: false);

AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);

var newTimestamps = Directory.EnumerateFiles (AppBundlePath, "*.*", SearchOption.TopDirectoryOnly).ToDictionary (file => file, file => GetLastModified (file));

Expand Down Expand Up @@ -121,10 +123,11 @@ public void CodesignAfterModifyingAppExtensionTest ()
var appexProjectDir = Path.Combine (testsDir, "MyActionExtension");
var viewController = Path.Combine (appexProjectDir, "ActionViewController.cs");
var mainExecutable = Path.Combine (AppBundlePath, "MyTabbedApplication");
bool expectedCodesignResults = Platform != "iPhoneSimulator";
var timestamp = File.GetLastWriteTimeUtc (mainExecutable);
var text = File.ReadAllText (viewController);

AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);

Thread.Sleep (1000);

Expand All @@ -137,9 +140,9 @@ public void CodesignAfterModifyingAppExtensionTest ()
var newTimestamp = File.GetLastWriteTimeUtc (mainExecutable);

// make sure that the main app bundle was codesigned due to the changes in the appex
Assert.IsTrue (newTimestamp > timestamp, "The main app bundle does not seem to have been re-codesigned");
Assert.AreEqual (expectedCodesignResults, newTimestamp > timestamp, "The main app bundle does not seem to have been re-codesigned");

AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);
} finally {
// restore the original ActionViewController.cs code...
text = text.Replace ("bool imageFound = true;", "bool imageFound = false;");
Expand All @@ -150,17 +153,19 @@ public void CodesignAfterModifyingAppExtensionTest ()
[Test]
public void RebuildWatchAppNoChanges ()
{
bool expectedCodesignResults = Platform != "iPhoneSimulator";

BuildProject ("MyWatch2Container", Platform, config, clean: true);

AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);

Thread.Sleep (1000);

// Rebuild w/ no changes
BuildProject ("MyWatch2Container", Platform, config, clean: false);

// make sure everything is still codesigned properly
AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);
}

[Test]
Expand All @@ -171,10 +176,11 @@ public void CodesignAfterModifyingWatchApp2Test ()
var appexProjectDir = Path.Combine (testsDir, "MyWatchKit2Extension");
var viewController = Path.Combine (appexProjectDir, "InterfaceController.cs");
var mainExecutable = Path.Combine (AppBundlePath, "MyWatch2Container");
bool expectedCodesignResults = Platform != "iPhoneSimulator";
var timestamp = File.GetLastWriteTimeUtc (mainExecutable);
var text = File.ReadAllText (viewController);

AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);

Thread.Sleep (1000);

Expand All @@ -185,7 +191,7 @@ public void CodesignAfterModifyingWatchApp2Test ()
try {
BuildProject ("MyWatch2Container", Platform, config, clean: false);

AssertProperlyCodesigned ();
AssertProperlyCodesigned (expectedCodesignResults);

var newTimestamp = File.GetLastWriteTimeUtc (mainExecutable);

Expand Down
6 changes: 4 additions & 2 deletions tests/framework-test/framework-test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -29,6 +29,7 @@
<MtouchDebug>true</MtouchDebug>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchProfiling>true</MtouchProfiling>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>full</DebugType>
Expand Down Expand Up @@ -85,6 +86,7 @@
<MtouchArch>i386, x86_64</MtouchArch>
<MtouchLink>None</MtouchLink>
<CodesignKey>iPhone Developer</CodesignKey>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -163,4 +165,4 @@
<Name>bindings-framework-test</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>