@@ -6,8 +6,12 @@ import 'package:meta/meta.dart';
6
6
7
7
import '../application_package.dart' ;
8
8
import '../base/file_system.dart' ;
9
+ import '../base/io.dart' ;
10
+ import '../base/process_manager.dart' ;
11
+ import '../build_info.dart' ;
9
12
import '../globals.dart' ;
10
13
import '../ios/plist_utils.dart' as plist;
14
+ import '../project.dart' ;
11
15
12
16
/// Tests whether a [FileSystemEntity] is an macOS bundle directory
13
17
bool _isBundleDirectory (FileSystemEntity entity) =>
@@ -16,6 +20,11 @@ bool _isBundleDirectory(FileSystemEntity entity) =>
16
20
abstract class MacOSApp extends ApplicationPackage {
17
21
MacOSApp ({@required String projectBundleId}) : super (id: projectBundleId);
18
22
23
+ /// Creates a new [MacOSApp] from a macOS project directory.
24
+ factory MacOSApp .fromMacOSProject (MacOSProject project) {
25
+ return BuildableMacOSApp (project);
26
+ }
27
+
19
28
/// Creates a new [MacOSApp] from an existing app bundle.
20
29
///
21
30
/// `applicationBinary` is the path to the framework directory created by an
@@ -24,21 +33,33 @@ abstract class MacOSApp extends ApplicationPackage {
24
33
/// which is expected to start the application and send the observatory
25
34
/// port over stdout.
26
35
factory MacOSApp .fromPrebuiltApp (FileSystemEntity applicationBinary) {
27
- final FileSystemEntityType entityType = fs.typeSync (applicationBinary.path);
36
+ final _ExecutableAndId executableAndId = _executableFromBundle (applicationBinary);
37
+ final Directory applicationBundle = fs.directory (applicationBinary);
38
+ return PrebuiltMacOSApp (
39
+ bundleDir: applicationBundle,
40
+ bundleName: applicationBundle.path,
41
+ projectBundleId: executableAndId.id,
42
+ executable: executableAndId.executable,
43
+ );
44
+ }
45
+
46
+ /// Look up the executable name for a macOS application bundle.
47
+ static _ExecutableAndId _executableFromBundle (Directory applicationBundle) {
48
+ final FileSystemEntityType entityType = fs.typeSync (applicationBundle.path);
28
49
if (entityType == FileSystemEntityType .notFound) {
29
- printError ('File "${applicationBinary .path }" does not exist.' );
50
+ printError ('File "${applicationBundle .path }" does not exist.' );
30
51
return null ;
31
52
}
32
53
Directory bundleDir;
33
54
if (entityType == FileSystemEntityType .directory) {
34
- final Directory directory = fs.directory (applicationBinary );
55
+ final Directory directory = fs.directory (applicationBundle );
35
56
if (! _isBundleDirectory (directory)) {
36
- printError ('Folder "${applicationBinary .path }" is not an app bundle.' );
57
+ printError ('Folder "${applicationBundle .path }" is not an app bundle.' );
37
58
return null ;
38
59
}
39
- bundleDir = fs.directory (applicationBinary );
60
+ bundleDir = fs.directory (applicationBundle );
40
61
} else {
41
- printError ('Folder "${applicationBinary .path }" is not an app bundle.' );
62
+ printError ('Folder "${applicationBundle .path }" is not an app bundle.' );
42
63
return null ;
43
64
}
44
65
final String plistPath = fs.path.join (bundleDir.path, 'Contents' , 'Info.plist' );
@@ -55,37 +76,76 @@ abstract class MacOSApp extends ApplicationPackage {
55
76
final String executable = fs.path.join (bundleDir.path, 'Contents' , 'MacOS' , executableName);
56
77
if (! fs.file (executable).existsSync ()) {
57
78
printError ('Could not find macOS binary at $executable ' );
58
- return null ;
59
79
}
60
- return PrebuiltMacOSApp (
61
- bundleDir: bundleDir,
62
- bundleName: fs.path.basename (bundleDir.path),
63
- projectBundleId: id,
64
- executable: executable,
65
- );
80
+ return _ExecutableAndId (executable, id);
66
81
}
67
82
68
83
@override
69
84
String get displayName => id;
70
85
71
- String get executable;
86
+ String applicationBundle (BuildMode buildMode);
87
+
88
+ String executable (BuildMode buildMode);
72
89
}
73
90
74
91
class PrebuiltMacOSApp extends MacOSApp {
75
92
PrebuiltMacOSApp ({
76
93
@required this .bundleDir,
77
94
@required this .bundleName,
78
95
@required this .projectBundleId,
79
- @required this .executable,
80
- }) : super (projectBundleId: projectBundleId);
96
+ @required String executable,
97
+ }) : _executable = executable,
98
+ super (projectBundleId: projectBundleId);
81
99
82
100
final Directory bundleDir;
83
101
final String bundleName;
84
102
final String projectBundleId;
85
103
86
- @override
87
- final String executable;
104
+ final String _executable;
88
105
89
106
@override
90
107
String get name => bundleName;
108
+
109
+ @override
110
+ String applicationBundle (BuildMode buildMode) => bundleDir.path;
111
+
112
+ @override
113
+ String executable (BuildMode buildMode) => _executable;
114
+ }
115
+
116
+ class BuildableMacOSApp extends MacOSApp {
117
+ BuildableMacOSApp (this .project);
118
+
119
+ final MacOSProject project;
120
+
121
+ @override
122
+ String get name => 'macOS' ;
123
+
124
+ @override
125
+ String applicationBundle (BuildMode buildMode) {
126
+ final ProcessResult result = processManager.runSync (< String > [
127
+ project.nameScript.path,
128
+ buildMode == BuildMode .debug ? 'debug' : 'release'
129
+ ], runInShell: true );
130
+ final String directory = result.stdout.toString ().trim ();
131
+ return directory;
132
+ }
133
+
134
+ @override
135
+ String executable (BuildMode buildMode) {
136
+ final ProcessResult result = processManager.runSync (< String > [
137
+ project.nameScript.path,
138
+ buildMode == BuildMode .debug ? 'debug' : 'release'
139
+ ], runInShell: true );
140
+ final String directory = result.stdout.toString ().trim ();
141
+ final _ExecutableAndId executableAndId = MacOSApp ._executableFromBundle (fs.directory (directory));
142
+ return executableAndId.executable;
143
+ }
144
+ }
145
+
146
+ class _ExecutableAndId {
147
+ _ExecutableAndId (this .executable, this .id);
148
+
149
+ final String executable;
150
+ final String id;
91
151
}
0 commit comments