Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
618030e0
Commit
618030e0
authored
Nov 29, 2016
by
John McCutchan
Committed by
GitHub
Nov 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More AppContext cleanups (#7073)
parent
f1938c60
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
97 additions
and
99 deletions
+97
-99
fuchsia_builder.dart
packages/flutter_tools/bin/fuchsia_builder.dart
+11
-2
executable.dart
packages/flutter_tools/lib/executable.dart
+22
-12
config.dart
packages/flutter_tools/lib/src/base/config.dart
+1
-1
context.dart
packages/flutter_tools/lib/src/base/context.dart
+9
-1
os.dart
packages/flutter_tools/lib/src/base/os.dart
+1
-3
cache.dart
packages/flutter_tools/lib/src/cache.dart
+1
-1
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+2
-2
mac.dart
packages/flutter_tools/lib/src/ios/mac.dart
+1
-1
simulators.dart
packages/flutter_tools/lib/src/ios/simulators.dart
+2
-4
flutter_command_runner.dart
.../flutter_tools/lib/src/runner/flutter_command_runner.dart
+5
-4
toolchain.dart
packages/flutter_tools/lib/src/toolchain.dart
+5
-12
usage.dart
packages/flutter_tools/lib/src/usage.dart
+1
-1
context_test.dart
packages/flutter_tools/test/context_test.dart
+3
-3
daemon_test.dart
packages/flutter_tools/test/daemon_test.dart
+4
-4
context.dart
packages/flutter_tools/test/src/context.dart
+23
-37
toolchain_test.dart
packages/flutter_tools/test/toolchain_test.dart
+6
-11
No files found.
packages/flutter_tools/bin/fuchsia_builder.dart
View file @
618030e0
...
...
@@ -8,11 +8,14 @@ import 'dart:io';
import
'package:args/args.dart'
;
import
'../lib/src/base/common.dart'
;
import
'../lib/src/base/config.dart'
;
import
'../lib/src/base/context.dart'
;
import
'../lib/src/base/logger.dart'
;
import
'../lib/src/base/os.dart'
;
import
'../lib/src/cache.dart'
;
import
'../lib/src/flx.dart'
;
import
'../lib/src/globals.dart'
;
import
'../lib/src/usage.dart'
;
const
String
_kOptionPackages
=
'packages'
;
const
String
_kOptionOutput
=
'output-file'
;
...
...
@@ -28,10 +31,16 @@ const List<String> _kRequiredOptions = const <String>[
_kOptionWorking
,
];
void
main
(
List
<
String
>
args
)
async
{
Future
<
Null
>
main
(
List
<
String
>
args
)
async
{
AppContext
executableContext
=
new
AppContext
();
executableContext
.
setVariable
(
Logger
,
new
StdoutLogger
());
executableContext
.
runInZone
(()
{
context
[
Logger
]
=
new
StdoutLogger
();
// Initialize the context with some defaults.
context
.
putIfAbsent
(
Logger
,
()
=>
new
StdoutLogger
());
context
.
putIfAbsent
(
Cache
,
()
=>
new
Cache
());
context
.
putIfAbsent
(
Config
,
()
=>
new
Config
());
context
.
putIfAbsent
(
OperatingSystemUtils
,
()
=>
new
OperatingSystemUtils
());
context
.
putIfAbsent
(
Usage
,
()
=>
new
Usage
());
return
run
(
args
);
});
}
...
...
packages/flutter_tools/lib/executable.dart
View file @
618030e0
...
...
@@ -9,10 +9,13 @@ import 'package:args/command_runner.dart';
import
'package:stack_trace/stack_trace.dart'
;
import
'src/base/common.dart'
;
import
'src/base/config.dart'
;
import
'src/base/context.dart'
;
import
'src/base/logger.dart'
;
import
'src/base/os.dart'
;
import
'src/base/process.dart'
;
import
'src/base/utils.dart'
;
import
'src/cache.dart'
;
import
'src/commands/analyze.dart'
;
import
'src/commands/build.dart'
;
import
'src/commands/channel.dart'
;
...
...
@@ -40,8 +43,12 @@ import 'src/device.dart';
import
'src/doctor.dart'
;
import
'src/globals.dart'
;
import
'src/hot.dart'
;
import
'src/usage.dart'
;
import
'src/ios/mac.dart'
;
import
'src/ios/simulators.dart'
;
import
'src/runner/flutter_command_runner.dart'
;
import
'src/toolchain.dart'
;
import
'src/usage.dart'
;
/// Main entry point for commands.
///
...
...
@@ -88,16 +95,19 @@ Future<Null> main(List<String> args) async {
// Make the context current.
_executableContext
.
runInZone
(()
{
// Initialize the context with some defaults.
if
(
context
[
Logger
]
==
null
)
context
[
Logger
]
=
new
StdoutLogger
();
if
(
context
[
DeviceManager
]
==
null
)
context
[
DeviceManager
]
=
new
DeviceManager
();
if
(
context
[
DevFSConfig
]
==
null
)
context
[
DevFSConfig
]
=
new
DevFSConfig
();
if
(
context
[
Doctor
]
==
null
)
context
[
Doctor
]
=
new
Doctor
();
if
(
context
[
HotRunnerConfig
]
==
null
)
context
[
HotRunnerConfig
]
=
new
HotRunnerConfig
();
context
.
putIfAbsent
(
Logger
,
()
=>
new
StdoutLogger
());
context
.
putIfAbsent
(
DeviceManager
,
()
=>
new
DeviceManager
());
context
.
putIfAbsent
(
DevFSConfig
,
()
=>
new
DevFSConfig
());
context
.
putIfAbsent
(
Doctor
,
()
=>
new
Doctor
());
context
.
putIfAbsent
(
HotRunnerConfig
,
()
=>
new
HotRunnerConfig
());
context
.
putIfAbsent
(
Cache
,
()
=>
new
Cache
());
context
.
putIfAbsent
(
ToolConfiguration
,
()
=>
new
ToolConfiguration
());
context
.
putIfAbsent
(
Config
,
()
=>
new
Config
());
context
.
putIfAbsent
(
OperatingSystemUtils
,
()
=>
new
OperatingSystemUtils
());
context
.
putIfAbsent
(
XCode
,
()
=>
new
XCode
());
context
.
putIfAbsent
(
IOSSimulatorUtils
,
()
=>
new
IOSSimulatorUtils
());
context
.
putIfAbsent
(
SimControl
,
()
=>
new
SimControl
());
context
.
putIfAbsent
(
Usage
,
()
=>
new
Usage
());
return
Chain
.
capture
/*<Future<Null>>*/
(()
async
{
await
runner
.
run
(
args
);
...
...
@@ -192,7 +202,7 @@ Future<String> _doctorText() async {
BufferLogger
logger
=
new
BufferLogger
();
AppContext
appContext
=
new
AppContext
();
appContext
[
Logger
]
=
logger
;
appContext
.
setVariable
(
Logger
,
logger
)
;
await
appContext
.
runInZone
(()
=>
doctor
.
diagnose
());
...
...
packages/flutter_tools/lib/src/base/config.dart
View file @
618030e0
...
...
@@ -16,7 +16,7 @@ class Config {
_values
=
JSON
.
decode
(
_configFile
.
readAsStringSync
());
}
static
Config
get
instance
=>
context
[
Config
]
??
(
context
[
Config
]
=
new
Config
())
;
static
Config
get
instance
=>
context
[
Config
];
File
_configFile
;
String
get
configPath
=>
_configFile
.
path
;
...
...
packages/flutter_tools/lib/src/base/context.dart
View file @
618030e0
...
...
@@ -36,7 +36,15 @@ class AppContext {
dynamic
operator
[](
Type
type
)
=>
getVariable
(
type
);
void
operator
[]=(
Type
type
,
dynamic
instance
)
=>
setVariable
(
type
,
instance
);
dynamic
putIfAbsent
(
Type
type
,
dynamic
ifAbsent
())
{
dynamic
value
=
getVariable
(
type
);
if
(
value
!=
null
)
{
return
value
;
}
value
=
ifAbsent
();
setVariable
(
type
,
value
);
return
value
;
}
AppContext
_calcParent
(
Zone
zone
)
{
Zone
parentZone
=
zone
.
parent
;
...
...
packages/flutter_tools/lib/src/base/os.dart
View file @
618030e0
...
...
@@ -12,9 +12,7 @@ import 'context.dart';
import
'process.dart'
;
/// Returns [OperatingSystemUtils] active in the current app context (i.e. zone).
OperatingSystemUtils
get
os
{
return
context
[
OperatingSystemUtils
]
??
(
context
[
OperatingSystemUtils
]
=
new
OperatingSystemUtils
());
}
OperatingSystemUtils
get
os
=>
context
[
OperatingSystemUtils
];
abstract
class
OperatingSystemUtils
{
factory
OperatingSystemUtils
()
{
...
...
packages/flutter_tools/lib/src/cache.dart
View file @
618030e0
...
...
@@ -99,7 +99,7 @@ class Cache {
return
_engineRevision
;
}
static
Cache
get
instance
=>
context
[
Cache
]
??
(
context
[
Cache
]
=
new
Cache
())
;
static
Cache
get
instance
=>
context
[
Cache
];
/// Return the top-level directory in the cache; this is `bin/cache`.
Directory
getRoot
()
{
...
...
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
618030e0
...
...
@@ -48,7 +48,7 @@ class DaemonCommand extends FlutterCommand {
AppContext
appContext
=
new
AppContext
();
NotifyingLogger
notifyingLogger
=
new
NotifyingLogger
();
appContext
[
Logger
]
=
notifyingLogger
;
appContext
.
setVariable
(
Logger
,
notifyingLogger
)
;
Cache
.
releaseLockEarly
();
...
...
@@ -674,7 +674,7 @@ class AppInstance {
_logger
=
new
_AppRunLogger
(
domain
,
this
);
AppContext
appContext
=
new
AppContext
();
appContext
[
Logger
]
=
_logger
;
appContext
.
setVariable
(
Logger
,
_logger
)
;
return
appContext
.
runInZone
(
method
);
}
}
...
...
packages/flutter_tools/lib/src/ios/mac.dart
View file @
618030e0
...
...
@@ -56,7 +56,7 @@ class XCode {
}
/// Returns [XCode] active in the current app context.
static
XCode
get
instance
=>
context
[
XCode
]
??
(
context
[
XCode
]
=
new
XCode
())
;
static
XCode
get
instance
=>
context
[
XCode
];
bool
get
isInstalledAndMeetsVersionCheck
=>
isInstalled
&&
xcodeVersionSatisfactory
;
...
...
packages/flutter_tools/lib/src/ios/simulators.dart
View file @
618030e0
...
...
@@ -37,9 +37,7 @@ class IOSSimulators extends PollingDeviceDiscovery {
class
IOSSimulatorUtils
{
/// Returns [IOSSimulatorUtils] active in the current app context (i.e. zone).
static
IOSSimulatorUtils
get
instance
{
return
context
[
IOSSimulatorUtils
]
??
(
context
[
IOSSimulatorUtils
]
=
new
IOSSimulatorUtils
());
}
static
IOSSimulatorUtils
get
instance
=>
context
[
IOSSimulatorUtils
];
List
<
IOSSimulator
>
getAttachedDevices
()
{
if
(!
XCode
.
instance
.
isInstalledAndMeetsVersionCheck
)
...
...
@@ -54,7 +52,7 @@ class IOSSimulatorUtils {
/// A wrapper around the `simctl` command line tool.
class
SimControl
{
/// Returns [SimControl] active in the current app context (i.e. zone).
static
SimControl
get
instance
=>
context
[
SimControl
]
??
(
context
[
SimControl
]
=
new
SimControl
())
;
static
SimControl
get
instance
=>
context
[
SimControl
];
Future
<
bool
>
boot
({
String
deviceName
})
async
{
if
(
_isAnyConnected
())
...
...
packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
View file @
618030e0
...
...
@@ -137,8 +137,10 @@ class FlutterCommandRunner extends CommandRunner<Null> {
@override
Future
<
Null
>
runCommand
(
ArgResults
globalResults
)
async
{
// Check for verbose.
if
(
globalResults
[
'verbose'
])
context
[
Logger
]
=
new
VerboseLogger
();
if
(
globalResults
[
'verbose'
])
{
// Override the logger.
context
.
setVariable
(
Logger
,
new
VerboseLogger
());
}
logger
.
quiet
=
globalResults
[
'quiet'
];
...
...
@@ -171,8 +173,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
}
// The Android SDK could already have been set by tests.
if
(!
context
.
isSet
(
AndroidSdk
))
context
[
AndroidSdk
]
=
AndroidSdk
.
locateAndroidSdk
();
context
.
putIfAbsent
(
AndroidSdk
,
()
=>
AndroidSdk
.
locateAndroidSdk
());
if
(
globalResults
[
'version'
])
{
flutterUsage
.
sendCommand
(
'version'
);
...
...
packages/flutter_tools/lib/src/toolchain.dart
View file @
618030e0
...
...
@@ -25,18 +25,11 @@ const Map<HostTool, String> _kHostToolFileName = const <HostTool, String>{
/// and the engine artifact directory for a given target platform. It is configurable
/// via command-line arguments in order to support local engine builds.
class
ToolConfiguration
{
/// [overrideCache] is configurable for testing.
ToolConfiguration
({
Cache
overrideCache
})
{
_cache
=
overrideCache
??
cache
;
}
ToolConfiguration
();
Cache
_cache
;
Cache
get
cache
=>
context
[
Cache
]
;
static
ToolConfiguration
get
instance
{
if
(
context
[
ToolConfiguration
]
==
null
)
context
[
ToolConfiguration
]
=
new
ToolConfiguration
();
return
context
[
ToolConfiguration
];
}
static
ToolConfiguration
get
instance
=>
context
[
ToolConfiguration
];
/// Override using the artifacts from the cache directory (--engine-src-path).
String
engineSrcPath
;
...
...
@@ -63,14 +56,14 @@ class ToolConfiguration {
// Create something like `android-arm` or `android-arm-release`.
String
dirName
=
getNameForTargetPlatform
(
platform
)
+
suffix
;
Directory
engineDir
=
_
cache
.
getArtifactDirectory
(
'engine'
);
Directory
engineDir
=
cache
.
getArtifactDirectory
(
'engine'
);
return
new
Directory
(
path
.
join
(
engineDir
.
path
,
dirName
));
}
}
String
getHostToolPath
(
HostTool
tool
)
{
if
(
engineBuildPath
==
null
)
{
return
path
.
join
(
_
cache
.
getArtifactDirectory
(
'engine'
).
path
,
return
path
.
join
(
cache
.
getArtifactDirectory
(
'engine'
).
path
,
getNameForHostPlatform
(
getCurrentHostPlatform
()),
_kHostToolFileName
[
tool
]);
}
...
...
packages/flutter_tools/lib/src/usage.dart
View file @
618030e0
...
...
@@ -39,7 +39,7 @@ class Usage {
}
/// Returns [Usage] active in the current app context.
static
Usage
get
instance
=>
context
[
Usage
]
??
(
context
[
Usage
]
=
new
Usage
())
;
static
Usage
get
instance
=>
context
[
Usage
];
Analytics
_analytics
;
...
...
packages/flutter_tools/test/context_test.dart
View file @
618030e0
...
...
@@ -12,7 +12,7 @@ void main() {
test
(
'error'
,
()
async
{
AppContext
context
=
new
AppContext
();
BufferLogger
mockLogger
=
new
BufferLogger
();
context
[
Logger
]
=
mockLogger
;
context
.
setVariable
(
Logger
,
mockLogger
)
;
await
context
.
runInZone
(()
{
printError
(
'foo bar'
);
...
...
@@ -26,7 +26,7 @@ void main() {
test
(
'status'
,
()
async
{
AppContext
context
=
new
AppContext
();
BufferLogger
mockLogger
=
new
BufferLogger
();
context
[
Logger
]
=
mockLogger
;
context
.
setVariable
(
Logger
,
mockLogger
)
;
await
context
.
runInZone
(()
{
printStatus
(
'foo bar'
);
...
...
@@ -40,7 +40,7 @@ void main() {
test
(
'trace'
,
()
async
{
AppContext
context
=
new
AppContext
();
BufferLogger
mockLogger
=
new
BufferLogger
();
context
[
Logger
]
=
mockLogger
;
context
.
setVariable
(
Logger
,
mockLogger
)
;
await
context
.
runInZone
(()
{
printTrace
(
'foo bar'
);
...
...
packages/flutter_tools/test/daemon_test.dart
View file @
618030e0
...
...
@@ -32,11 +32,11 @@ void main() {
setUp
(()
{
appContext
=
new
AppContext
();
notifyingLogger
=
new
NotifyingLogger
();
appContext
[
Logger
]
=
notifyingLogger
;
appContext
[
Doctor
]
=
new
Doctor
(
);
appContext
.
setVariable
(
Logger
,
notifyingLogger
)
;
appContext
.
setVariable
(
Doctor
,
new
Doctor
()
);
if
(
Platform
.
isMacOS
)
appContext
[
XCode
]
=
new
XCode
(
);
appContext
[
DeviceManager
]
=
new
MockDeviceManager
(
);
appContext
.
setVariable
(
XCode
,
new
XCode
()
);
appContext
.
setVariable
(
DeviceManager
,
new
MockDeviceManager
()
);
});
tearDown
(()
{
...
...
packages/flutter_tools/test/src/context.dart
View file @
618030e0
...
...
@@ -3,17 +3,19 @@
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:io'
;
import
'package:flutter_tools/src/base/config.dart'
;
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/devfs.dart'
;
import
'package:flutter_tools/src/doctor.dart'
;
import
'package:flutter_tools/src/hot.dart'
;
import
'package:flutter_tools/src/ios/mac.dart'
;
import
'package:flutter_tools/src/ios/simulators.dart'
;
import
'package:flutter_tools/src/toolchain.dart'
;
import
'package:flutter_tools/src/usage.dart'
;
import
'package:mockito/mockito.dart'
;
...
...
@@ -32,49 +34,33 @@ void testUsingContext(String description, dynamic testMethod(), {
test
(
description
,
()
async
{
AppContext
testContext
=
new
AppContext
();
// Apply all overrides to the test context.
overrides
.
forEach
((
Type
type
,
dynamic
value
)
{
testContext
[
type
]
=
value
;
testContext
.
setVariable
(
type
,
value
)
;
});
if
(!
overrides
.
containsKey
(
Logger
))
testContext
[
Logger
]
=
new
BufferLogger
();
if
(!
overrides
.
containsKey
(
DeviceManager
))
testContext
[
DeviceManager
]
=
new
MockDeviceManager
();
if
(!
overrides
.
containsKey
(
Doctor
))
testContext
[
Doctor
]
=
new
MockDoctor
();
if
(!
overrides
.
containsKey
(
SimControl
))
testContext
[
SimControl
]
=
new
MockSimControl
();
if
(!
overrides
.
containsKey
(
Usage
))
testContext
[
Usage
]
=
new
MockUsage
();
if
(!
overrides
.
containsKey
(
OperatingSystemUtils
))
{
// Initialize the test context with some default mocks.
testContext
.
putIfAbsent
(
Logger
,
()
=>
new
BufferLogger
());
testContext
.
putIfAbsent
(
DeviceManager
,
()
=>
new
MockDeviceManager
());
testContext
.
putIfAbsent
(
DevFSConfig
,
()
=>
new
DevFSConfig
());
testContext
.
putIfAbsent
(
Doctor
,
()
=>
new
MockDoctor
());
testContext
.
putIfAbsent
(
HotRunnerConfig
,
()
=>
new
HotRunnerConfig
());
testContext
.
putIfAbsent
(
Cache
,
()
=>
new
Cache
());
testContext
.
putIfAbsent
(
ToolConfiguration
,
()
=>
new
ToolConfiguration
());
testContext
.
putIfAbsent
(
Config
,
()
=>
new
Config
());
testContext
.
putIfAbsent
(
OperatingSystemUtils
,
()
{
MockOperatingSystemUtils
os
=
new
MockOperatingSystemUtils
();
when
(
os
.
isWindows
).
thenReturn
(
false
);
testContext
[
OperatingSystemUtils
]
=
os
;
}
if
(!
overrides
.
containsKey
(
DevFSConfig
))
{
testContext
[
DevFSConfig
]
=
new
DevFSConfig
();
}
if
(!
overrides
.
containsKey
(
HotRunnerConfig
))
{
testContext
[
HotRunnerConfig
]
=
new
HotRunnerConfig
();
}
if
(!
overrides
.
containsKey
(
IOSSimulatorUtils
))
{
return
os
;
});
testContext
.
putIfAbsent
(
XCode
,
()
=>
new
XCode
());
testContext
.
putIfAbsent
(
IOSSimulatorUtils
,
()
{
MockIOSSimulatorUtils
mock
=
new
MockIOSSimulatorUtils
();
when
(
mock
.
getAttachedDevices
()).
thenReturn
(<
IOSSimulator
>[]);
testContext
[
IOSSimulatorUtils
]
=
mock
;
}
if
(
Platform
.
isMacOS
)
{
if
(!
overrides
.
containsKey
(
XCode
))
testContext
[
XCode
]
=
new
XCode
();
}
return
mock
;
});
testContext
.
putIfAbsent
(
SimControl
,
()
=>
new
MockSimControl
());
testContext
.
putIfAbsent
(
Usage
,
()
=>
new
MockUsage
());
try
{
return
await
testContext
.
runInZone
(
testMethod
);
...
...
packages/flutter_tools/test/toolchain_test.dart
View file @
618030e0
...
...
@@ -14,19 +14,10 @@ import 'src/context.dart';
void
main
(
)
{
group
(
'ToolConfiguration'
,
()
{
Directory
tempDir
;
setUp
(()
{
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_temp'
);
});
tearDown
(()
{
tempDir
.
deleteSync
(
recursive:
true
);
});
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_temp'
);
testUsingContext
(
'using cache'
,
()
{
ToolConfiguration
toolConfig
=
new
ToolConfiguration
(
overrideCache:
new
Cache
(
rootOverride:
tempDir
)
);
ToolConfiguration
toolConfig
=
new
ToolConfiguration
();
expect
(
toolConfig
.
getEngineArtifactsDirectory
(
TargetPlatform
.
android_arm
,
BuildMode
.
debug
).
path
,
...
...
@@ -36,6 +27,10 @@ void main() {
toolConfig
.
getEngineArtifactsDirectory
(
TargetPlatform
.
android_arm
,
BuildMode
.
release
).
path
,
endsWith
(
'cache/artifacts/engine/android-arm-release'
)
);
expect
(
tempDir
,
isNotNull
);
tempDir
.
deleteSync
(
recursive:
true
);
},
overrides:
<
Type
,
dynamic
>
{
Cache:
new
Cache
(
rootOverride:
tempDir
)
});
testUsingContext
(
'using enginePath'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment