Skip to content

Commit

Permalink
[msbuild] Enable nullability in a few tasks. (#20509)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Apr 30, 2024
1 parent 8980649 commit da6e1af
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 57 deletions.
4 changes: 2 additions & 2 deletions msbuild/Xamarin.MacDev.Tasks/LoggingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public static void LogTaskProperty (this TaskLoggingHelper log, string propertyN
/// <param name="errorCode">In the 7xxx range for MSBuild error.</param>
/// <param name="message">The error's message to be displayed in the error pad.</param>
/// <param name="fileName">Path to the known guilty file or null.</param>
public static void LogError (this TaskLoggingHelper log, int errorCode, string fileName, string message, params object [] args)
public static void LogError (this TaskLoggingHelper log, int errorCode, string? fileName, string message, params object [] args)
{
log.LogError (null, $"{ErrorPrefix}{errorCode}", null, fileName ?? "MSBuild", 0, 0, 0, 0, message, args);
}

public static void LogWarning (this TaskLoggingHelper log, int errorCode, string fileName, string message, params object [] args)
public static void LogWarning (this TaskLoggingHelper log, int errorCode, string? fileName, string message, params object [] args)
{
log.LogWarning (null, $"{ErrorPrefix}{errorCode}", null, fileName ?? "MSBuild", 0, 0, 0, 0, message, args);
}
Expand Down
9 changes: 3 additions & 6 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CreateEmbeddedResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

using Xamarin.MacDev.Tasks;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.MacDev.Tasks {
public class CreateEmbeddedResources : XamarinTask {
[Required]
public ITaskItem [] BundleResources { get; set; }
public ITaskItem [] BundleResources { get; set; } = Array.Empty<ITaskItem> ();

[Required]
public string Prefix { get; set; }
public string Prefix { get; set; } = string.Empty;

[Output]
public ITaskItem [] EmbeddedResources { get; set; }
public ITaskItem [] EmbeddedResources { get; set; } = Array.Empty<ITaskItem> ();

static string EscapeMangledResource (string name)
{
Expand Down
35 changes: 18 additions & 17 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/LinkNativeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,46 @@
using Xamarin.Messaging.Build.Client;
using Xamarin.Utils;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.MacDev.Tasks {
public class LinkNativeCode : XamarinTask, ITaskCallback {
string outputPath;
string outputPath = string.Empty;

#region Inputs
public ITaskItem [] LinkerFlags { get; set; }
public ITaskItem [] LinkerFlags { get; set; } = Array.Empty<ITaskItem> ();

public ITaskItem [] LinkWithLibraries { get; set; }
public ITaskItem [] LinkWithLibraries { get; set; } = Array.Empty<ITaskItem> ();

// A path to entitlements to be embedded into the executable
public string EntitlementsInExecutable { get; set; }
public string EntitlementsInExecutable { get; set; } = string.Empty;

[Required]
public string SdkDevPath { get; set; }
public string SdkDevPath { get; set; } = string.Empty;

[Required]
public bool SdkIsSimulator { get; set; }

[Required]
public string SdkRoot { get; set; }
public string SdkRoot { get; set; } = string.Empty;

[Required]
public string OutputFile { get; set; }
public string OutputFile { get; set; } = string.Empty;

[Required]
public ITaskItem [] ObjectFiles { get; set; }
public ITaskItem [] ObjectFiles { get; set; } = Array.Empty<ITaskItem> ();

[Required]
public string MinimumOSVersion { get; set; }
public string MinimumOSVersion { get; set; } = string.Empty;

public ITaskItem [] NativeReferences { get; set; } = Array.Empty<ITaskItem> ();

public ITaskItem [] Frameworks { get; set; }
public ITaskItem [] Frameworks { get; set; } = Array.Empty<ITaskItem> ();

public string DylibRPath { get; set; }
public string DylibRPath { get; set; } = string.Empty;

public string FrameworkRPath { get; set; }
public string FrameworkRPath { get; set; } = string.Empty;

[Required]
public string TargetArchitectures { get; set; }
public string TargetArchitectures { get; set; } = string.Empty;

TargetArchitecture architectures;
#endregion
Expand Down Expand Up @@ -219,7 +216,11 @@ bool ExecuteUnsafe ()
var rv = ExecuteAsync ("xcrun", arguments, sdkDevPath: SdkDevPath, showErrorIfFailure: false).Result;
if (rv.ExitCode != 0) {
var stderr = rv.StandardError?.ToString ()?.Trim ();
#if NET
if (string.IsNullOrEmpty (stderr)) {
#else
if (stderr is null || string.IsNullOrEmpty (stderr)) {
#endif
Log.LogError (MSBStrings.E0117, /* {0} exited with code {1} */ linkerExecutable, rv.ExitCode);
} else {
// Don't show any lines with "ld: warning: " in the error message, they're typically confusing.
Expand Down Expand Up @@ -261,7 +262,7 @@ bool ExecuteUnsafe ()
static bool EntitlementsRequireLinkerFlags (string path)
{
try {
var plist = PDictionary.FromFile (path);
var plist = PDictionary.FromFile (path)!;

// FIXME: most keys do not require linking in the entitlements file, so we
// could probably add some smarter logic here to iterate over all of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
using Xamarin.MacDev.Tasks;
using Xamarin.Messaging.Build.Client;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.MacDev.Tasks {
public class PrepareObjCBindingNativeFrameworks : XamarinTask, ITaskCallback, ICancelableTask {
public ITaskItem [] ObjCBindingNativeFrameworks { get; set; }
public ITaskItem [] ObjCBindingNativeFrameworks { get; set; } = Array.Empty<ITaskItem> ();

public override bool Execute ()
{
Expand Down
11 changes: 4 additions & 7 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/PrepareResourceRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@
using Xamarin.Localization.MSBuild;
using Xamarin.Messaging.Build.Client;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.MacDev.Tasks {
public class PrepareResourceRules : XamarinTask, ICancelableTask {
#region Inputs

[Required]
public string AppBundleDir { get; set; }
public string AppBundleDir { get; set; } = string.Empty;

public string ResourceRules { get; set; }
public string ResourceRules { get; set; } = string.Empty;

[Required]
public string SdkVersion { get; set; }
public string SdkVersion { get; set; } = string.Empty;

#endregion

#region Outputs

[Output]
public string PreparedResourceRules { get; set; }
public string PreparedResourceRules { get; set; } = string.Empty;

#endregion

Expand Down
7 changes: 2 additions & 5 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/ReadItemsFromFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

using Xamarin.Messaging.Build.Client;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.MacDev.Tasks {
public class ReadItemsFromFile : XamarinTask, ITaskCallback {
static readonly XNamespace XmlNs = XNamespace.Get ("http://schemas.microsoft.com/developer/msbuild/2003");
Expand All @@ -24,14 +21,14 @@ public class ReadItemsFromFile : XamarinTask, ITaskCallback {

[Output]
[Required]
public ITaskItem [] File { get; set; }
public ITaskItem [] File { get; set; } = Array.Empty<ITaskItem> ();

#endregion

#region Outputs

[Output]
public ITaskItem [] Items { get; set; }
public ITaskItem [] Items { get; set; } = Array.Empty<ITaskItem> ();

#endregion

Expand Down
5 changes: 1 addition & 4 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/SpotlightIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

using Xamarin.Messaging.Build.Client;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.MacDev.Tasks {
public class SpotlightIndexer : XamarinToolTask {
#region Inputs

[Required]
public string Input { get; set; }
public string Input { get; set; } = string.Empty;

#endregion

Expand Down
11 changes: 4 additions & 7 deletions msbuild/Xamarin.iOS.Tasks.Windows/Tasks/CodesignHotRestartApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@
using Xamarin.iOS.Tasks.Windows.Properties;
using Xamarin.iOS.Windows;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.iOS.HotRestart.Tasks {
public class CodesignHotRestartApp : Task, ICancelableTask {
#region Inputs

[Required]
public string AppBundlePath { get; set; }
public string AppBundlePath { get; set; } = string.Empty;

[Required]
public string BundleIdentifier { get; set; }
public string BundleIdentifier { get; set; } = string.Empty;

[Required]
public string CodeSigningPath { get; set; }
public string CodeSigningPath { get; set; } = string.Empty;

[Required]
public string ProvisioningProfilePath { get; set; }
public string ProvisioningProfilePath { get; set; } = string.Empty;

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
using System;
using System.IO;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.iOS.Tasks.Windows {
public class CreateArchiveDirectory : Task {
[Required]
public string ArchiveBasePath { get; set; }
public string ArchiveBasePath { get; set; } = string.Empty;

[Output]
public string ArchiveRootDir { get; set; }
public string ArchiveRootDir { get; set; } = string.Empty;

public override bool Execute ()
{
Expand Down

13 comments on commit da6e1af

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.