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
a7eb2c8a
Unverified
Commit
a7eb2c8a
authored
Apr 27, 2021
by
Ian Hickson
Committed by
GitHub
Apr 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use "aliases" in args to fix some technical debt (#81073)
parent
858123dc
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
105 additions
and
76 deletions
+105
-76
assemble.dart
packages/flutter_tools/lib/src/commands/assemble.dart
+8
-13
attach.dart
packages/flutter_tools/lib/src/commands/attach.dart
+10
-9
screenshot.dart
packages/flutter_tools/lib/src/commands/screenshot.dart
+15
-14
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+9
-6
attach_test.dart
...utter_tools/test/commands.shard/hermetic/attach_test.dart
+2
-2
screenshot_command_test.dart
...test/commands.shard/hermetic/screenshot_command_test.dart
+3
-3
args_test.dart
packages/flutter_tools/test/general.shard/args_test.dart
+36
-26
command_output_test.dart
...ter_tools/test/integration.shard/command_output_test.dart
+22
-3
No files found.
packages/flutter_tools/lib/src/commands/assemble.dart
View file @
a7eb2c8a
...
...
@@ -85,11 +85,6 @@ List<Target> _kDefaultTargets = <Target>[
const
ReleaseBundleWindowsAssetsUwp
(),
];
// TODO(ianh): https://github.com/dart-lang/args/issues/181 will allow us to remove useLegacyNames
// and just switch to arguments that use the regular style, which still supporting the old names.
// When fixing this, remove the hack in test/general.shard/args_test.dart that ignores these names.
const
bool
useLegacyNames
=
true
;
/// Assemble provides a low level API to interact with the flutter tool build
/// system.
class
AssembleCommand
extends
FlutterCommand
{
...
...
@@ -128,8 +123,8 @@ class AssembleCommand extends FlutterCommand {
'files will be written. Must be either absolute or relative from the '
'root of the current Flutter project.'
,
);
usesExtraDartFlagOptions
(
verboseHelp:
verboseHelp
,
useLegacyNames:
useLegacyNames
);
usesDartDefineOption
(
useLegacyNames:
useLegacyNames
);
usesExtraDartFlagOptions
(
verboseHelp:
verboseHelp
);
usesDartDefineOption
();
argParser
.
addOption
(
'resource-pool-size'
,
help:
'The maximum number of concurrent tasks the build system will run.'
,
...
...
@@ -263,18 +258,18 @@ class AssembleCommand extends FlutterCommand {
final
String
value
=
chunk
.
substring
(
indexEquals
+
1
);
results
[
key
]
=
value
;
}
if
(
argResults
.
wasParsed
(
useLegacyNames
?
kExtraGenSnapshotOptions
:
FlutterOptions
.
kExtraGenSnapshotOptions
))
{
results
[
kExtraGenSnapshotOptions
]
=
(
argResults
[
useLegacyNames
?
kExtraGenSnapshotOptions
:
FlutterOptions
.
kExtraGenSnapshotOptions
]
as
List
<
String
>).
join
(
','
);
if
(
argResults
.
wasParsed
(
FlutterOptions
.
kExtraGenSnapshotOptions
))
{
results
[
kExtraGenSnapshotOptions
]
=
(
argResults
[
FlutterOptions
.
kExtraGenSnapshotOptions
]
as
List
<
String
>).
join
(
','
);
}
if
(
argResults
.
wasParsed
(
useLegacyNames
?
kDartDefines
:
FlutterOptions
.
kDartDefinesOption
))
{
results
[
kDartDefines
]
=
(
argResults
[
useLegacyNames
?
kDartDefines
:
FlutterOptions
.
kDartDefinesOption
]
as
List
<
String
>).
join
(
','
);
if
(
argResults
.
wasParsed
(
FlutterOptions
.
kDartDefinesOption
))
{
results
[
kDartDefines
]
=
(
argResults
[
FlutterOptions
.
kDartDefinesOption
]
as
List
<
String
>).
join
(
','
);
}
results
[
kDeferredComponents
]
=
'false'
;
if
(
FlutterProject
.
current
().
manifest
.
deferredComponents
!=
null
&&
isDeferredComponentsTargets
()
&&
!
isDebug
())
{
results
[
kDeferredComponents
]
=
'true'
;
}
if
(
argResults
.
wasParsed
(
useLegacyNames
?
kExtraFrontEndOptions
:
FlutterOptions
.
kExtraFrontEndOptions
))
{
results
[
kExtraFrontEndOptions
]
=
(
argResults
[
useLegacyNames
?
kExtraFrontEndOptions
:
FlutterOptions
.
kExtraFrontEndOptions
]
as
List
<
String
>).
join
(
','
);
if
(
argResults
.
wasParsed
(
FlutterOptions
.
kExtraFrontEndOptions
))
{
results
[
kExtraFrontEndOptions
]
=
(
argResults
[
FlutterOptions
.
kExtraFrontEndOptions
]
as
List
<
String
>).
join
(
','
);
}
return
results
;
}
...
...
packages/flutter_tools/lib/src/commands/attach.dart
View file @
a7eb2c8a
...
...
@@ -39,7 +39,7 @@ import '../vmservice.dart';
/// With an application already running, a HotRunner can be attached to it
/// with:
/// ```
/// $ flutter attach --debug-ur
i
http://127.0.0.1:12345/QqL7EFEDNG0=/
/// $ flutter attach --debug-ur
l
http://127.0.0.1:12345/QqL7EFEDNG0=/
/// ```
///
/// If `--disable-service-auth-codes` was provided to the application at startup
...
...
@@ -77,9 +77,10 @@ class AttachCommand extends FlutterCommand {
help:
'(deprecated) Device port where the observatory is listening. Requires '
'"--disable-service-auth-codes" to also be provided to the Flutter '
'application at launch, otherwise this command will fail to connect to '
'the application. In general, "--debug-ur
i
" should be used instead.'
,
'the application. In general, "--debug-ur
l
" should be used instead.'
,
)..
addOption
(
'debug-uri'
,
// TODO(ianh): we should support --debug-url as well (leaving this as an alias).
'debug-url'
,
aliases:
<
String
>[
'debug-uri'
],
// supported for historical reasons
help:
'The URL at which the observatory is listening.'
,
)..
addOption
(
'app-id'
,
...
...
@@ -153,15 +154,15 @@ known, it can be explicitly provided to attach via the command-line, e.g.
}
Uri
get
debugUri
{
if
(
argResults
[
'debug-ur
i
'
]
==
null
)
{
if
(
argResults
[
'debug-ur
l
'
]
==
null
)
{
return
null
;
}
final
Uri
uri
=
Uri
.
tryParse
(
stringArg
(
'debug-ur
i
'
));
final
Uri
uri
=
Uri
.
tryParse
(
stringArg
(
'debug-ur
l
'
));
if
(
uri
==
null
)
{
throwToolExit
(
'Invalid `--debug-ur
i`:
${stringArg('debug-uri
')}
'
);
throwToolExit
(
'Invalid `--debug-ur
l`:
${stringArg('debug-url
')}
'
);
}
if
(!
uri
.
hasPort
)
{
throwToolExit
(
'Port not specified for `--debug-ur
i
`:
$uri
'
);
throwToolExit
(
'Port not specified for `--debug-ur
l
`:
$uri
'
);
}
return
uri
;
}
...
...
@@ -181,13 +182,13 @@ known, it can be explicitly provided to attach via the command-line, e.g.
debugPort
;
if
(
debugPort
==
null
&&
debugUri
==
null
&&
argResults
.
wasParsed
(
FlutterCommand
.
ipv6Flag
))
{
throwToolExit
(
'When the --debug-port or --debug-ur
i
is unknown, this command determines '
'When the --debug-port or --debug-ur
l
is unknown, this command determines '
'the value of --ipv6 on its own.'
,
);
}
if
(
debugPort
==
null
&&
debugUri
==
null
&&
argResults
.
wasParsed
(
FlutterCommand
.
observatoryPortOption
))
{
throwToolExit
(
'When the --debug-port or --debug-ur
i
is unknown, this command does not use '
'When the --debug-port or --debug-ur
l
is unknown, this command does not use '
'the value of --observatory-port.'
,
);
}
...
...
packages/flutter_tools/lib/src/commands/screenshot.dart
View file @
a7eb2c8a
...
...
@@ -16,7 +16,7 @@ import '../vmservice.dart';
const
String
_kOut
=
'out'
;
const
String
_kType
=
'type'
;
const
String
_kObservatoryUr
i
=
'observatory-uri'
;
// TODO(ianh): change this to "observatory-url" (but support -uri as an alias)
const
String
_kObservatoryUr
l
=
'observatory-url'
;
const
String
_kDeviceType
=
'device'
;
const
String
_kSkiaType
=
'skia'
;
const
String
_kRasterizerType
=
'rasterizer'
;
...
...
@@ -30,7 +30,8 @@ class ScreenshotCommand extends FlutterCommand {
help:
'Location to write the screenshot.'
,
);
argParser
.
addOption
(
_kObservatoryUri
,
_kObservatoryUrl
,
aliases:
<
String
>[
'observatory-url'
],
// for historical reasons
valueHelp:
'URI'
,
help:
'The Observatory URL to which to connect.
\n
'
'This is required when "--
$_kType
" is "
$_kSkiaType
" or "
$_kRasterizerType
".
\n
'
...
...
@@ -46,8 +47,8 @@ class ScreenshotCommand extends FlutterCommand {
_kDeviceType:
'Delegate to the device
\'
s native screenshot capabilities. This '
'screenshots the entire screen currently being displayed (including content '
'not rendered by Flutter, like the device status bar).'
,
_kSkiaType:
'Render the Flutter app as a Skia picture. Requires "--
$_kObservatoryUr
i
".'
,
_kRasterizerType:
'Render the Flutter app using the rasterizer. Requires "--
$_kObservatoryUr
i
."'
,
_kSkiaType:
'Render the Flutter app as a Skia picture. Requires "--
$_kObservatoryUr
l
".'
,
_kRasterizerType:
'Render the Flutter app using the rasterizer. Requires "--
$_kObservatoryUr
l
."'
,
},
defaultsTo:
_kDeviceType
,
);
...
...
@@ -65,10 +66,10 @@ class ScreenshotCommand extends FlutterCommand {
Device
device
;
Future
<
void
>
_validateOptions
(
String
screenshotType
,
String
observatoryUr
i
)
async
{
Future
<
void
>
_validateOptions
(
String
screenshotType
,
String
observatoryUr
l
)
async
{
switch
(
screenshotType
)
{
case
_kDeviceType:
if
(
observatoryUr
i
!=
null
)
{
if
(
observatoryUr
l
!=
null
)
{
throwToolExit
(
'Observatory URI cannot be provided for screenshot type
$screenshotType
'
);
}
device
=
await
findTargetDevice
();
...
...
@@ -80,18 +81,18 @@ class ScreenshotCommand extends FlutterCommand {
}
break
;
default
:
if
(
observatoryUr
i
==
null
)
{
if
(
observatoryUr
l
==
null
)
{
throwToolExit
(
'Observatory URI must be specified for screenshot type
$screenshotType
'
);
}
if
(
observatoryUr
i
.
isEmpty
||
Uri
.
tryParse
(
observatoryUri
)
==
null
)
{
throwToolExit
(
'Observatory URI "
$observatoryUr
i
" is invalid'
);
if
(
observatoryUr
l
.
isEmpty
||
Uri
.
tryParse
(
observatoryUrl
)
==
null
)
{
throwToolExit
(
'Observatory URI "
$observatoryUr
l
" is invalid'
);
}
}
}
@override
Future
<
FlutterCommandResult
>
verifyThenRunCommand
(
String
commandPath
)
async
{
await
_validateOptions
(
stringArg
(
_kType
),
stringArg
(
_kObservatoryUr
i
));
await
_validateOptions
(
stringArg
(
_kType
),
stringArg
(
_kObservatoryUr
l
));
return
super
.
verifyThenRunCommand
(
commandPath
);
}
...
...
@@ -134,8 +135,8 @@ class ScreenshotCommand extends FlutterCommand {
}
Future
<
bool
>
runSkia
(
File
outputFile
)
async
{
final
Uri
observatoryUr
i
=
Uri
.
parse
(
stringArg
(
_kObservatoryUri
));
final
FlutterVmService
vmService
=
await
connectToVmService
(
observatoryUr
i
,
logger:
globals
.
logger
);
final
Uri
observatoryUr
l
=
Uri
.
parse
(
stringArg
(
_kObservatoryUrl
));
final
FlutterVmService
vmService
=
await
connectToVmService
(
observatoryUr
l
,
logger:
globals
.
logger
);
final
vm_service
.
Response
skp
=
await
vmService
.
screenshotSkp
();
if
(
skp
==
null
)
{
globals
.
printError
(
...
...
@@ -158,8 +159,8 @@ class ScreenshotCommand extends FlutterCommand {
}
Future
<
bool
>
runRasterizer
(
File
outputFile
)
async
{
final
Uri
observatoryUr
i
=
Uri
.
parse
(
stringArg
(
_kObservatoryUri
));
final
FlutterVmService
vmService
=
await
connectToVmService
(
observatoryUr
i
,
logger:
globals
.
logger
);
final
Uri
observatoryUr
l
=
Uri
.
parse
(
stringArg
(
_kObservatoryUrl
));
final
FlutterVmService
vmService
=
await
connectToVmService
(
observatoryUr
l
,
logger:
globals
.
logger
);
final
vm_service
.
Response
response
=
await
vmService
.
screenshot
();
if
(
response
==
null
)
{
globals
.
printError
(
...
...
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
a7eb2c8a
...
...
@@ -18,7 +18,7 @@ import '../base/user_messages.dart';
import
'../base/utils.dart'
;
import
'../build_info.dart'
;
import
'../build_system/build_system.dart'
;
import
'../build_system/targets/common.dart'
show
kExtraFrontEndOptions
,
kExtraGenSnapshotOptions
;
// for
"useLegacyNames"
only
import
'../build_system/targets/common.dart'
show
kExtraFrontEndOptions
,
kExtraGenSnapshotOptions
;
// for
deprecated option name aliases
only
import
'../bundle.dart'
as
bundle
;
import
'../cache.dart'
;
import
'../dart/generate_synthetic_packages.dart'
;
...
...
@@ -527,9 +527,10 @@ abstract class FlutterCommand extends Command<void> {
valueHelp:
'x.y.z'
);
}
void
usesDartDefineOption
(
{
bool
useLegacyNames
=
false
}
)
{
void
usesDartDefineOption
()
{
argParser
.
addMultiOption
(
useLegacyNames
?
kDartDefines
:
FlutterOptions
.
kDartDefinesOption
,
FlutterOptions
.
kDartDefinesOption
,
aliases:
<
String
>[
kDartDefines
],
// supported for historical reasons
help:
'Additional key-value pairs that will be available as constants '
'from the String.fromEnvironment, bool.fromEnvironment, int.fromEnvironment, '
'and double.fromEnvironment constructors.
\n
'
...
...
@@ -700,15 +701,17 @@ abstract class FlutterCommand extends Command<void> {
/// Enables support for the hidden options --extra-front-end-options and
/// --extra-gen-snapshot-options.
void
usesExtraDartFlagOptions
({
@required
bool
verboseHelp
,
bool
useLegacyNames
=
false
})
{
argParser
.
addMultiOption
(
useLegacyNames
?
kExtraFrontEndOptions
:
FlutterOptions
.
kExtraFrontEndOptions
,
void
usesExtraDartFlagOptions
({
@required
bool
verboseHelp
})
{
argParser
.
addMultiOption
(
FlutterOptions
.
kExtraFrontEndOptions
,
aliases:
<
String
>[
kExtraFrontEndOptions
],
// supported for historical reasons
help:
'A comma-separated list of additional command line arguments that will be passed directly to the Dart front end. '
'For example, "--
${FlutterOptions.kExtraFrontEndOptions}
=--enable-experiment=nonfunction-type-aliases".'
,
valueHelp:
'--foo,--bar'
,
splitCommas:
true
,
hide:
!
verboseHelp
,
);
argParser
.
addMultiOption
(
useLegacyNames
?
kExtraGenSnapshotOptions
:
FlutterOptions
.
kExtraGenSnapshotOptions
,
argParser
.
addMultiOption
(
FlutterOptions
.
kExtraGenSnapshotOptions
,
aliases:
<
String
>[
kExtraGenSnapshotOptions
],
// supported for historical reasons
help:
'A comma-separated list of additional command line arguments that will be passed directly to the Dart native compiler. '
'(Only used in "--profile" or "--release" builds.) '
'For example, "--
${FlutterOptions.kExtraGenSnapshotOptions}
=--no-strip".'
,
...
...
packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart
View file @
a7eb2c8a
...
...
@@ -254,7 +254,7 @@ void main() {
await
expectLater
(
createTestCommandRunner
(
command
).
run
(<
String
>[
'attach'
,
'--ipv6'
]),
throwsToolExit
(
message:
'When the --debug-port or --debug-ur
i
is unknown, this command determines '
message:
'When the --debug-port or --debug-ur
l
is unknown, this command determines '
'the value of --ipv6 on its own.'
,
),
);
...
...
@@ -277,7 +277,7 @@ void main() {
await
expectLater
(
createTestCommandRunner
(
command
).
run
(<
String
>[
'attach'
,
'--observatory-port'
,
'100'
]),
throwsToolExit
(
message:
'When the --debug-port or --debug-ur
i
is unknown, this command does not use '
message:
'When the --debug-port or --debug-ur
l
is unknown, this command does not use '
'the value of --observatory-port.'
,
),
);
...
...
packages/flutter_tools/test/commands.shard/hermetic/screenshot_command_test.dart
View file @
a7eb2c8a
...
...
@@ -29,12 +29,12 @@ void main() {
};
await
expectLater
(()
=>
createTestCommandRunner
(
ScreenshotCommand
())
.
run
(<
String
>[
'screenshot'
,
'--type=skia'
,
'--observatory-ur
i
=http://localhost:8181'
]),
.
run
(<
String
>[
'screenshot'
,
'--type=skia'
,
'--observatory-ur
l
=http://localhost:8181'
]),
throwsA
(
isA
<
Exception
>().
having
((
dynamic
exception
)
=>
exception
.
toString
(),
'message'
,
contains
(
'dummy'
))),
);
await
expectLater
(()
=>
createTestCommandRunner
(
ScreenshotCommand
())
.
run
(<
String
>[
'screenshot'
,
'--type=rasterizer'
,
'--observatory-ur
i
=http://localhost:8181'
]),
.
run
(<
String
>[
'screenshot'
,
'--type=rasterizer'
,
'--observatory-ur
l
=http://localhost:8181'
]),
throwsA
(
isA
<
Exception
>().
having
((
dynamic
exception
)
=>
exception
.
toString
(),
'message'
,
contains
(
'dummy'
))),
);
});
...
...
@@ -61,7 +61,7 @@ void main() {
testUsingContext
(
'device screenshots cannot provided Observatory'
,
()
async
{
await
expectLater
(()
=>
createTestCommandRunner
(
ScreenshotCommand
())
.
run
(<
String
>[
'screenshot'
,
'--observatory-ur
i
=http://localhost:8181'
]),
.
run
(<
String
>[
'screenshot'
,
'--observatory-ur
l
=http://localhost:8181'
]),
throwsToolExit
(
message:
'Observatory URI cannot be provided for screenshot type device'
),
);
});
...
...
packages/flutter_tools/test/general.shard/args_test.dart
View file @
a7eb2c8a
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/integration.shard/command_output_test.dart
View file @
a7eb2c8a
...
...
@@ -152,7 +152,8 @@ void main() {
expect
(
versionInfo
,
containsPair
(
'flutterRoot'
,
isNotNull
));
});
testWithoutContext
(
'A tool exit is thrown for an invalid debug-uri in flutter attach'
,
()
async
{
testWithoutContext
(
'A tool exit is thrown for an invalid debug-url in flutter attach'
,
()
async
{
// This test is almost exactly like the next one; update them together please.
final
String
flutterBin
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
'flutter'
);
final
String
helloWorld
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'examples'
,
'hello_world'
);
final
ProcessResult
result
=
await
processManager
.
run
(<
String
>[
...
...
@@ -162,11 +163,29 @@ void main() {
'attach'
,
'-d'
,
'flutter-tester'
,
'--debug-ur
i
=http://127.0.0.1:3333*/'
,
'--debug-ur
l
=http://127.0.0.1:3333*/'
,
],
workingDirectory:
helloWorld
);
expect
(
result
.
exitCode
,
1
);
expect
(
result
.
stderr
,
contains
(
'Invalid `--debug-uri`: http://127.0.0.1:3333*/'
));
expect
(
result
.
stderr
,
contains
(
'Invalid `--debug-url`: http://127.0.0.1:3333*/'
));
});
testWithoutContext
(
'--debug-uri is an alias for --debug-url'
,
()
async
{
// This text is exactly the same as the previous one but with a "l" turned to an "i".
final
String
flutterBin
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
'flutter'
);
final
String
helloWorld
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'examples'
,
'hello_world'
);
final
ProcessResult
result
=
await
processManager
.
run
(<
String
>[
flutterBin
,
...
getLocalEngineArguments
(),
'--show-test-device'
,
'attach'
,
'-d'
,
'flutter-tester'
,
'--debug-uri=http://127.0.0.1:3333*/'
,
// "uri" not "url"
],
workingDirectory:
helloWorld
);
expect
(
result
.
exitCode
,
1
);
expect
(
result
.
stderr
,
contains
(
'Invalid `--debug-url`: http://127.0.0.1:3333*/'
));
// _"url"_ not "uri"!
});
testWithoutContext
(
'will load bootstrap script before starting'
,
()
async
{
...
...
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