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

Give tvOS a special value for Personal/MyDocuments #57508

Merged
merged 36 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6354dd0
Use a different Personal folder on tvOS, and a test that it works
directhex Aug 16, 2021
0ee7a71
Run this PR on device, the error does not happen on sim
directhex Aug 16, 2021
5854dfc
CI fixes
directhex Aug 16, 2021
7473c19
Nullable
directhex Aug 16, 2021
877258f
Test on devices
directhex Aug 16, 2021
b032fc0
Just run one test to save disk space
directhex Aug 16, 2021
43573f7
Tweak to run only 1 test and make sure DevTeamProvisioning is right
Aug 17, 2021
a39e472
Horrible hack to check something in CI
directhex Aug 17, 2021
392a09b
Merge branch 'tvos-specialdirectories' of github.com:directhex/runtim…
directhex Aug 17, 2021
cfcb6dc
Revert all changes. Run as-is in CI to see if it's my changes to blame
directhex Aug 17, 2021
c50a1af
nonsense
directhex Aug 17, 2021
7e7d49b
Set temp path to a valid location
Aug 18, 2021
064670d
Fix AppDomainTests.ExecuteAssembly to copy files to a valid place
Aug 18, 2021
a48cfe7
Don't expect HOME to work on tvOS
directhex Aug 18, 2021
26354d7
We cannot get exit code from tvOS device, so runonly tests don't work
directhex Aug 18, 2021
4ee0555
Revert infra changes made to enable CI of this PR, which passes now o…
directhex Aug 18, 2021
75bf9e2
Merge remote-tracking branch 'origin/main' into tvos-specialdirectories
directhex Aug 18, 2021
07660e2
Add NSTemporaryDirectory interop function and supporting cast
Aug 18, 2021
e57d693
Merge remote-tracking branch 'origin/tvos-specialdirectories' into tv…
Aug 18, 2021
4b49b07
forgot a void
Aug 19, 2021
84609fc
Requested changes from Alex
directhex Aug 19, 2021
b936dc1
Merge remote-tracking branch 'origin/main' into tvos-specialdirectories
directhex Aug 20, 2021
5ad98b9
Merge remote-tracking branch 'origin/main' into tvos-specialdirectories
directhex Aug 23, 2021
9ebb6b0
Don't use nullable
directhex Aug 23, 2021
fc2cf38
Revert AppDominTests changes, not clear they're needed
directhex Aug 23, 2021
74ddcff
namespace
directhex Aug 23, 2021
a619fa7
Update src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.i…
directhex Aug 23, 2021
33788e1
Revert unused props
directhex Aug 23, 2021
a3d96ed
Update src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.i…
directhex Aug 23, 2021
0baf69f
Update src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.i…
directhex Aug 23, 2021
e85a9e4
Update src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.i…
directhex Aug 23, 2021
6f338fa
Update src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.N…
directhex Aug 23, 2021
eb5706a
Changes squashing other changes, bleh
directhex Aug 23, 2021
67a6c1d
Update src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.i…
directhex Aug 23, 2021
e3cbd8c
error CA1805: Member 's_defaultTempPath' is explicitly initialized to…
directhex Aug 23, 2021
538b631
Merge remote-tracking branch 'origin/main' into tvos-specialdirectories
directhex Aug 23, 2021
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
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SearchPath_TempDirectory")]
internal static extern string SearchPathTempDirectory();
}
}
1 change: 1 addition & 0 deletions src/libraries/Native/Unix/System.Native/entrypoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ static const Entry s_sysNative[] =
DllImportEntry(SystemNative_GetOSArchitecture)
DllImportEntry(SystemNative_GetProcessArchitecture)
DllImportEntry(SystemNative_SearchPath)
DllImportEntry(SystemNative_SearchPath_TempDirectory)
DllImportEntry(SystemNative_RegisterForSigChld)
DllImportEntry(SystemNative_SetDelayedSigChildConsoleConfigurationHandler)
DllImportEntry(SystemNative_SetTerminalInvalidationHandler)
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/Native/Unix/System.Native/pal_searchpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ const char* SystemNative_SearchPath(int32_t folderId)
__builtin_unreachable();
return NULL;
}

const char* SystemNative_SearchPath_TempDirectory()
{
__builtin_unreachable();
return NULL;
}
2 changes: 2 additions & 0 deletions src/libraries/Native/Unix/System.Native/pal_searchpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
#include "pal_types.h"

PALEXPORT const char* SystemNative_SearchPath(int32_t folderId);

PALEXPORT const char* SystemNative_SearchPath_TempDirectory(void);
7 changes: 7 additions & 0 deletions src/libraries/Native/Unix/System.Native/pal_searchpath.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
const char* path = [[url path] UTF8String];
return path == NULL ? NULL : strdup (path);
}

const char* SystemNative_SearchPath_TempDirectory()
{
NSString* tempPath = NSTemporaryDirectory();
const char *path = [tempPath UTF8String];
return path == NULL ? NULL : strdup (path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileSystem.Exists.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileSystemInfo.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.Unix.cs" />
<Compile Condition="'$(IsiOSLike)' == 'true'" Include="$(MSBuildThisFileDirectory)System\IO\Path.Unix.iOS.cs" />
<Compile Condition="'$(IsiOSLike)' != 'true'" Include="$(MSBuildThisFileDirectory)System\IO\Path.Unix.NoniOS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PathInternal.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Names.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\RandomAccess.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.IO
{
public static partial class Path
{
private static string DefaultTempPath => "/tmp/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ private static string RemoveLongPathPrefix(string path)
public static string GetTempPath()
{
const string TempEnvVar = "TMPDIR";
const string DefaultTempPath = "/tmp/";

// Get the temp path from the TMPDIR environment variable.
// If it's not set, just return the default path.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace System.IO
{
public static partial class Path
{
private static string? s_defaultTempPath;

private static string DefaultTempPath =>
s_defaultTempPath ?? (s_defaultTempPath = Interop.Sys.SearchPathTempDirectory()) ??
throw new InvalidOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ public void FailFast_ExceptionStackTrace_InnerException()
}
}

[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix | TestPlatforms.Browser)]
public void GetFolderPath_Unix_PersonalExists()
{
Assert.True(Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
}

[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix | TestPlatforms.Browser)] // Tests OS-specific environment
public void GetFolderPath_Unix_PersonalIsHomeAndUserProfile()
Expand All @@ -339,7 +346,11 @@ public void GetFolderPath_Unix_PersonalIsHomeAndUserProfile()
Assert.Equal(Environment.GetEnvironmentVariable("HOME"), Environment.GetFolderPath(Environment.SpecialFolder.Personal));
Assert.Equal(Environment.GetEnvironmentVariable("HOME"), Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
}
Assert.Equal(Environment.GetEnvironmentVariable("HOME"), Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
// tvOS effectively doesn't have a HOME
if (!PlatformDetection.IstvOS)
{
Assert.Equal(Environment.GetEnvironmentVariable("HOME"), Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
}
}

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/sendtohelixhelp.proj
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
<TestTarget>$(AppleTestTarget)</TestTarget>
</XHarnessAppBundleToTest>
<!-- Create work items for run-only apps -->
<XHarnessAppBundleToTest Condition="Exists('$(TestArchiveRoot)runonly')" Include="$([System.IO.Directory]::GetDirectories('$(TestArchiveRoot)runonly', '*.app', System.IO.SearchOption.AllDirectories))" >
<XHarnessAppBundleToTest Condition="Exists('$(TestArchiveRoot)runonly') and '$(TargetOS)' != 'tvOS'" Include="$([System.IO.Directory]::GetDirectories('$(TestArchiveRoot)runonly', '*.app', System.IO.SearchOption.AllDirectories))" >
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should work on tvOS right? please file an issue so we follow up to reenable the "run-only" apps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference I have for runonly not working on tvOS is something @steveisok said in chat - Steve, is there an actual record of "runonly doesn't work on tvOS"?

Copy link
Member

@steveisok steveisok Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't get a return code from an iOS or tvOS device, which the functional tests expect.

Not sure if there's an issue in xharness. @premun would know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think this is supported in mlaunch. I will confirm this on Monday

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that were the case then this would fail on iOS too (and it doesn't seem to).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akoeplinger have you tested on device? Right now we have no Apple device runs anywhere

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I thought we ran it on the staging pipeline? anyway, if it doesn't work on iOS we should exclude it too :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No iOS_ runs in runtime-staging.yml.

It likely doesn't work on iOS either, but it'll take me ages to check on device via CI.

I could exclude it too, here, though. Or exclude neither since we don't know the state of things for sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can test this for you on an iPhone. Can you give me instructions on how to build the app?

<!-- The sample app doesn't need test runner -->
<IncludesTestRunner>false</IncludesTestRunner>
<!-- The sample's C# Main method returns 42 so it should be considered by xharness as a success -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@
<Compile Include="$(CommonPath)Interop\OSX\System.Native\Interop.SearchPath.cs">
<Link>Common\Interop\OSX\Interop.SearchPath.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\OSX\System.Native\Interop.SearchPath.iOS.cs">
<Link>Common\Interop\OSX\Interop.SearchPath.iOS.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
<Compile Include="$(BclSourcesRoot)\System\Threading\TimerQueue.Browser.Mono.cs" />
Expand Down
29 changes: 21 additions & 8 deletions src/mono/System.Private.CoreLib/src/System/Environment.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
{
switch (folder)
{
// TODO: fix for tvOS (https://github.com/dotnet/runtime/issues/34007)
// The "normal" NSDocumentDirectory is a read-only directory on tvOS
// and that breaks a lot of assumptions in the runtime and the BCL

case SpecialFolder.Personal:
case SpecialFolder.LocalApplicationData:
return Interop.Sys.SearchPath(NSSearchPathDirectory.NSDocumentDirectory);
return CombineDocumentDirectory(string.Empty);

case SpecialFolder.ApplicationData:
// note: at first glance that looked like a good place to return NSLibraryDirectory
// but it would break isolated storage for existing applications
return CombineSearchPath(NSSearchPathDirectory.NSDocumentDirectory, ".config");
return CombineDocumentDirectory(".config");

case SpecialFolder.Resources:
return Interop.Sys.SearchPath(NSSearchPathDirectory.NSLibraryDirectory); // older (8.2 and previous) would return String.Empty
Expand All @@ -63,7 +59,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
return Path.Combine(GetFolderPathCore(SpecialFolder.Personal, SpecialFolderOption.None), "Pictures");

case SpecialFolder.Templates:
return CombineSearchPath(NSSearchPathDirectory.NSDocumentDirectory, "Templates");
return CombineDocumentDirectory("Templates");

case SpecialFolder.MyVideos:
return Path.Combine(GetFolderPathCore(SpecialFolder.Personal, SpecialFolderOption.None), "Videos");
Expand All @@ -72,7 +68,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
return "/usr/share/templates";

case SpecialFolder.Fonts:
return CombineSearchPath(NSSearchPathDirectory.NSDocumentDirectory, ".fonts");
return CombineDocumentDirectory(".fonts");

case SpecialFolder.Favorites:
return CombineSearchPath(NSSearchPathDirectory.NSLibraryDirectory, "Favorites");
Expand Down Expand Up @@ -100,6 +96,23 @@ static string CombineSearchPath(NSSearchPathDirectory searchPath, string subdire
Path.Combine(path, subdirectory) :
string.Empty;
}

static string CombineDocumentDirectory(string subdirectory)
{
#if TARGET_TVOS
string? path = CombineSearchPath(NSSearchPathDirectory.NSLibraryDirectory, Path.Combine("Caches", "Documents", subdirectory));
// Special version of CombineSearchPath which creates the path if needed.
// This isn't needed for "real" search paths which always exist, but on tvOS
// the base path is really a subdirectory we define rather than an OS directory.
// In order to not treat Directory.Exists(SpecialFolder.ApplicationData) differently
// on tvOS, guarantee that it exists by creating it here
if (!Directory.Exists (path))
Directory.CreateDirectory (path);
#else
string? path = CombineSearchPath(NSSearchPathDirectory.NSDocumentDirectory, subdirectory);
#endif
return path;
}
}
}
}