Skip to content

Commit be11da6

Browse files
stuartmorgan-gagrapine
authored andcommitted
[path_provider] Revert iOS/macOS to plugin-based implementation (flutter#10517)
Reverts to the plugin-based implementation of `path_provider_foundation` while issues are being sorted out: - 2.5.0 (the FFI version) had to be retracted due to flutter/flutter#178915 - Releasing a new FFI version that would fix that issue is blocked on dart-lang/native#2824 - Our tree is also closed on dart-lang/native#2824 as an OOB failure due to the `objective_c` 9.2.0 release. - Depending on `objective_c` 9.2.0 also appears to add new toolchain requirements for running Dart unit tests, which we will a) need to figure out in our CI, and b) decide if we are okay pushing onto users (flutter/flutter#178715). This effectively reverts flutter#9762 (except for the changes allowing `ffigen` and `objective_c`, as Dart-team-owned dependencies). It was created by checking out the pre-9762 state of all the files in that directory, then applying `dart fix --apply` and `dart format` to pick up the changes for the new analyzer rules. Because of that PR landing, we can't just do a clean revert. Fixes flutter/flutter#178915 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 98c5dd9 commit be11da6

File tree

25 files changed

+905
-1408
lines changed

25 files changed

+905
-1408
lines changed

packages/path_provider/path_provider_foundation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
## 2.5.1
2+
3+
* Reverts to plugin-based implementation while FFI issues are investigated.
4+
15
## 2.5.0
26

7+
* **Retracted** due to production build issues.
38
* Replaces Flutter-plugin-based implementation with direct FFI calls to
49
Foundation.
510

packages/path_provider/path_provider_foundation/CONTRIBUTING.md

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import XCTest
6+
7+
@testable import path_provider_foundation
8+
9+
#if os(iOS)
10+
import Flutter
11+
#elseif os(macOS)
12+
import FlutterMacOS
13+
#endif
14+
15+
class RunnerTests: XCTestCase {
16+
func testGetTemporaryDirectory() throws {
17+
let plugin = PathProviderPlugin()
18+
let path = plugin.getDirectoryPath(type: .temp)
19+
XCTAssertEqual(
20+
path,
21+
NSSearchPathForDirectoriesInDomains(
22+
FileManager.SearchPathDirectory.cachesDirectory,
23+
FileManager.SearchPathDomainMask.userDomainMask,
24+
true
25+
).first)
26+
}
27+
28+
func testGetApplicationDocumentsDirectory() throws {
29+
let plugin = PathProviderPlugin()
30+
let path = plugin.getDirectoryPath(type: .applicationDocuments)
31+
XCTAssertEqual(
32+
path,
33+
NSSearchPathForDirectoriesInDomains(
34+
FileManager.SearchPathDirectory.documentDirectory,
35+
FileManager.SearchPathDomainMask.userDomainMask,
36+
true
37+
).first)
38+
}
39+
40+
func testGetApplicationSupportDirectory() throws {
41+
let plugin = PathProviderPlugin()
42+
let path = plugin.getDirectoryPath(type: .applicationSupport)
43+
#if os(iOS)
44+
// On iOS, the application support directory path should be just the system application
45+
// support path.
46+
XCTAssertEqual(
47+
path,
48+
NSSearchPathForDirectoriesInDomains(
49+
FileManager.SearchPathDirectory.applicationSupportDirectory,
50+
FileManager.SearchPathDomainMask.userDomainMask,
51+
true
52+
).first)
53+
#else
54+
// On macOS, the application support directory path should be the system application
55+
// support path with an added subdirectory based on the app name.
56+
XCTAssert(
57+
path!.hasPrefix(
58+
NSSearchPathForDirectoriesInDomains(
59+
FileManager.SearchPathDirectory.applicationSupportDirectory,
60+
FileManager.SearchPathDomainMask.userDomainMask,
61+
true
62+
).first!))
63+
XCTAssert(path!.hasSuffix("Example"))
64+
#endif
65+
}
66+
67+
func testGetLibraryDirectory() throws {
68+
let plugin = PathProviderPlugin()
69+
let path = plugin.getDirectoryPath(type: .library)
70+
XCTAssertEqual(
71+
path,
72+
NSSearchPathForDirectoriesInDomains(
73+
FileManager.SearchPathDirectory.libraryDirectory,
74+
FileManager.SearchPathDomainMask.userDomainMask,
75+
true
76+
).first)
77+
}
78+
79+
func testGetDownloadsDirectory() throws {
80+
let plugin = PathProviderPlugin()
81+
let path = plugin.getDirectoryPath(type: .downloads)
82+
XCTAssertEqual(
83+
path,
84+
NSSearchPathForDirectoriesInDomains(
85+
FileManager.SearchPathDirectory.downloadsDirectory,
86+
FileManager.SearchPathDomainMask.userDomainMask,
87+
true
88+
).first)
89+
}
90+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
3+
#
4+
Pod::Spec.new do |s|
5+
s.name = 'path_provider_foundation'
6+
s.version = '0.0.1'
7+
s.summary = 'An iOS and macOS implementation of the path_provider plugin.'
8+
s.description = <<-DESC
9+
An iOS and macOS implementation of the Flutter plugin for getting commonly used locations on the filesystem.
10+
DESC
11+
s.homepage = 'https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider_foundation'
12+
s.license = { :type => 'BSD', :file => '../LICENSE' }
13+
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
14+
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider_foundation' }
15+
s.source_files = 'path_provider_foundation/Sources/path_provider_foundation/**/*.swift'
16+
s.ios.dependency 'Flutter'
17+
s.osx.dependency 'FlutterMacOS'
18+
s.ios.deployment_target = '13.0'
19+
s.osx.deployment_target = '10.15'
20+
s.ios.xcconfig = {
21+
'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift',
22+
'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift',
23+
}
24+
s.swift_version = '5.0'
25+
s.resource_bundles = {'path_provider_foundation_privacy' => ['path_provider_foundation/Sources/path_provider_foundation/Resources/PrivacyInfo.xcprivacy']}
26+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version: 5.9
2+
3+
// Copyright 2013 The Flutter Authors
4+
// Use of this source code is governed by a BSD-style license that can be
5+
// found in the LICENSE file.
6+
7+
import PackageDescription
8+
9+
let package = Package(
10+
name: "path_provider_foundation",
11+
platforms: [
12+
.iOS("13.0"),
13+
.macOS("10.15"),
14+
],
15+
products: [
16+
.library(name: "path-provider-foundation", targets: ["path_provider_foundation"])
17+
],
18+
dependencies: [],
19+
targets: [
20+
.target(
21+
name: "path_provider_foundation",
22+
dependencies: [],
23+
resources: [
24+
.process("Resources")
25+
]
26+
)
27+
]
28+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import Foundation
6+
7+
#if os(iOS)
8+
import Flutter
9+
#elseif os(macOS)
10+
import FlutterMacOS
11+
#endif
12+
13+
public class PathProviderPlugin: NSObject, FlutterPlugin, PathProviderApi {
14+
public static func register(with registrar: FlutterPluginRegistrar) {
15+
let instance = PathProviderPlugin()
16+
// Workaround for https://github.com/flutter/flutter/issues/118103.
17+
#if os(iOS)
18+
let messenger = registrar.messenger()
19+
#else
20+
let messenger = registrar.messenger
21+
#endif
22+
PathProviderApiSetup.setUp(binaryMessenger: messenger, api: instance)
23+
}
24+
25+
func getDirectoryPath(type: DirectoryType) -> String? {
26+
var path = getDirectory(ofType: fileManagerDirectoryForType(type))
27+
#if os(macOS)
28+
// In a non-sandboxed app, these are shared directories where applications are
29+
// expected to use its bundle ID as a subdirectory. (For non-sandboxed apps,
30+
// adding the extra path is harmless).
31+
// This is not done for iOS, for compatibility with older versions of the
32+
// plugin.
33+
if type == .applicationSupport || type == .applicationCache {
34+
if let basePath = path {
35+
let basePathURL = URL.init(fileURLWithPath: basePath)
36+
path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path
37+
}
38+
}
39+
#endif
40+
return path
41+
}
42+
43+
// Returns the path for the container of the specified app group.
44+
func getContainerPath(appGroupIdentifier: String) -> String? {
45+
return FileManager.default.containerURL(
46+
forSecurityApplicationGroupIdentifier: appGroupIdentifier)?.path
47+
}
48+
}
49+
50+
/// Returns the FileManager constant corresponding to the given type.
51+
private func fileManagerDirectoryForType(_ type: DirectoryType) -> FileManager.SearchPathDirectory {
52+
switch type {
53+
case .applicationCache:
54+
return FileManager.SearchPathDirectory.cachesDirectory
55+
case .applicationDocuments:
56+
return FileManager.SearchPathDirectory.documentDirectory
57+
case .applicationSupport:
58+
return FileManager.SearchPathDirectory.applicationSupportDirectory
59+
case .downloads:
60+
return FileManager.SearchPathDirectory.downloadsDirectory
61+
case .library:
62+
return FileManager.SearchPathDirectory.libraryDirectory
63+
case .temp:
64+
return FileManager.SearchPathDirectory.cachesDirectory
65+
}
66+
}
67+
68+
/// Returns the user-domain directory of the given type.
69+
private func getDirectory(ofType directory: FileManager.SearchPathDirectory) -> String? {
70+
let paths = NSSearchPathForDirectoriesInDomains(
71+
directory,
72+
FileManager.SearchPathDomainMask.userDomainMask,
73+
true)
74+
return paths.first
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSPrivacyTrackingDomains</key>
6+
<array/>
7+
<key>NSPrivacyAccessedAPITypes</key>
8+
<array/>
9+
<key>NSPrivacyCollectedDataTypes</key>
10+
<array/>
11+
<key>NSPrivacyTracking</key>
12+
<false/>
13+
</dict>
14+
</plist>

0 commit comments

Comments
 (0)