Skip to content

Commit

Permalink
Merge branch 'main' into dev/mandel/get-selector-for-accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque authored Jan 17, 2025
2 parents 64bbd26 + 02ad356 commit b288190
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
5 changes: 5 additions & 0 deletions msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1714,4 +1714,9 @@
{0}: the path to a file
</comment>
</data>

<data name="W7144" xml:space="preserve">
<value>Did not extract {0} because it would write outside the target directory.</value>
</data>

</root>
12 changes: 12 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Decompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ static bool TryDecompressUsingSystemIOCompression (TaskLoggingHelper log, string
resource = resource.TrimEnd ('/', '\\');
resource = resource.Replace ('\\', zipDirectorySeparator);
var resourceAsDir = resource + zipDirectorySeparator;
decompressionDir = Path.GetFullPath (decompressionDir);

using var archive = ZipFile.OpenRead (zip);
foreach (var entry in archive.Entries) {
Expand Down Expand Up @@ -204,6 +205,17 @@ static bool TryDecompressUsingSystemIOCompression (TaskLoggingHelper log, string

var isDir = entryPath [entryPath.Length - 1] == zipDirectorySeparator;
var targetPath = Path.Combine (decompressionDir, entryPath.Replace (zipDirectorySeparator, Path.DirectorySeparatorChar));

// canonicalize the path
targetPath = Path.GetFullPath (targetPath);

// validate that the unzipped file is inside the target directory
var decompressionDirectoryPath = decompressionDir.Trim (Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
if (!targetPath.StartsWith (decompressionDirectoryPath)) {
log.LogWarning (7144, null, MSBStrings.W7144 /* Did not extract {0} because it would write outside the target directory. */, entryPath);
continue;
}

if (isDir) {
Directory.CreateDirectory (targetPath);
} else {
Expand Down
156 changes: 156 additions & 0 deletions tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,162 @@ public Utils.MyClass Name {
),
])
];

const string autoPropertyGetterWithAttribute = @"
using System.Runtime.Versioning;
using ObjCBindings;
namespace Test;
public class TestClass {
const string name = ""Test"";
[SupportedOSPlatform (""ios"")]
public string Name {
[SupportedOSPlatform (""ios17.0"")]
get;
set;
}
}
";
getterAvailabilityBuilder.Clear ();
getterAvailabilityBuilder.Add (supportedPlatform: new SupportedOSPlatformData (platformName: "ios17.0"));
yield return [
autoPropertyGetterWithAttribute,
new Property (
name: "Name",
returnType: ReturnTypeForString (),
symbolAvailability: propertyAvailabilityBuilder.ToImmutable (),
attributes: [
new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios"]),
],
modifiers: [
SyntaxFactory.Token (kind: SyntaxKind.PublicKeyword),
],
accessors: [
new (
accessorKind: AccessorKind.Getter,
symbolAvailability: getterAvailabilityBuilder.ToImmutable (),
exportPropertyData: null,
attributes: [
new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios17.0"]),
],
modifiers: []
),
new (
accessorKind: AccessorKind.Setter,
symbolAvailability: propertyAvailabilityBuilder.ToImmutable (),
exportPropertyData: null,
attributes: [],
modifiers: []
),
])
];

const string staticAutoPropertyGetterWithAttribute = @"
using System.Runtime.Versioning;
using ObjCBindings;
namespace Test;
public class TestClass {
const string name = ""Test"";
[SupportedOSPlatform (""ios"")]
public static string Name {
[SupportedOSPlatform (""ios17.0"")]
get;
set;
}
}
";
getterAvailabilityBuilder.Clear ();
getterAvailabilityBuilder.Add (supportedPlatform: new SupportedOSPlatformData (platformName: "ios17.0"));
yield return [
staticAutoPropertyGetterWithAttribute,
new Property (
name: "Name",
returnType: ReturnTypeForString (),
symbolAvailability: propertyAvailabilityBuilder.ToImmutable (),
attributes: [
new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios"]),
],
modifiers: [
SyntaxFactory.Token (kind: SyntaxKind.PublicKeyword),
SyntaxFactory.Token (kind: SyntaxKind.StaticKeyword),
],
accessors: [
new (
accessorKind: AccessorKind.Getter,
symbolAvailability: getterAvailabilityBuilder.ToImmutable (),
exportPropertyData: null,
attributes: [
new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios17.0"]),
],
modifiers: []
),
new (
accessorKind: AccessorKind.Setter,
symbolAvailability: propertyAvailabilityBuilder.ToImmutable (),
exportPropertyData: null,
attributes: [],
modifiers: []
),
])
];

const string partialStaticAutoPropertyGetterWithAttribute = @"
using System.Runtime.Versioning;
using ObjCBindings;
namespace Test;
public class TestClass {
const string name = ""Test"";
[SupportedOSPlatform (""ios"")]
public static partial string Name {
[SupportedOSPlatform (""ios17.0"")]
get;
set;
}
}
";
getterAvailabilityBuilder.Clear ();
getterAvailabilityBuilder.Add (supportedPlatform: new SupportedOSPlatformData (platformName: "ios17.0"));
yield return [
partialStaticAutoPropertyGetterWithAttribute,
new Property (
name: "Name",
returnType: ReturnTypeForString (),
symbolAvailability: propertyAvailabilityBuilder.ToImmutable (),
attributes: [
new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios"]),
],
modifiers: [
SyntaxFactory.Token (kind: SyntaxKind.PublicKeyword),
SyntaxFactory.Token (kind: SyntaxKind.StaticKeyword),
SyntaxFactory.Token (kind: SyntaxKind.PartialKeyword),
],
accessors: [
new (
accessorKind: AccessorKind.Getter,
symbolAvailability: getterAvailabilityBuilder.ToImmutable (),
exportPropertyData: null,
attributes: [
new (name: "System.Runtime.Versioning.SupportedOSPlatformAttribute", arguments: ["ios17.0"]),
],
modifiers: []
),
new (
accessorKind: AccessorKind.Setter,
symbolAvailability: propertyAvailabilityBuilder.ToImmutable (),
exportPropertyData: null,
attributes: [],
modifiers: []
),
])
];
}

IEnumerator IEnumerable.GetEnumerator ()
Expand Down

0 comments on commit b288190

Please sign in to comment.