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
fa35698e
Unverified
Commit
fa35698e
authored
Apr 08, 2020
by
Jonah Williams
Committed by
GitHub
Apr 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] allow passing non-config inputs (#54228)
parent
589b14d8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
15 deletions
+79
-15
build_system.dart
...ages/flutter_tools/lib/src/build_system/build_system.dart
+15
-0
assemble.dart
packages/flutter_tools/lib/src/commands/assemble.dart
+21
-9
assemble_test.dart
...ter_tools/test/commands.shard/hermetic/assemble_test.dart
+18
-6
build_system_test.dart
...ls/test/general.shard/build_system/build_system_test.dart
+25
-0
No files found.
packages/flutter_tools/lib/src/build_system/build_system.dart
View file @
fa35698e
...
...
@@ -295,6 +295,7 @@ class Environment {
@required
ProcessManager
processManager
,
Directory
buildDir
,
Map
<
String
,
String
>
defines
=
const
<
String
,
String
>{},
Map
<
String
,
String
>
inputs
=
const
<
String
,
String
>{},
})
{
// Compute a unique hash of this build's particular environment.
// Sort the keys by key so that the result is stable. We always
...
...
@@ -325,6 +326,7 @@ class Environment {
logger:
logger
,
artifacts:
artifacts
,
processManager:
processManager
,
inputs:
inputs
,
);
}
...
...
@@ -338,6 +340,7 @@ class Environment {
Directory
flutterRootDir
,
Directory
buildDir
,
Map
<
String
,
String
>
defines
=
const
<
String
,
String
>{},
Map
<
String
,
String
>
inputs
=
const
<
String
,
String
>{},
@required
FileSystem
fileSystem
,
@required
Logger
logger
,
@required
Artifacts
artifacts
,
...
...
@@ -350,6 +353,7 @@ class Environment {
flutterRootDir:
flutterRootDir
??
testDirectory
,
buildDir:
buildDir
,
defines:
defines
,
inputs:
inputs
,
fileSystem:
fileSystem
,
logger:
logger
,
artifacts:
artifacts
,
...
...
@@ -369,6 +373,7 @@ class Environment {
@required
this
.
logger
,
@required
this
.
fileSystem
,
@required
this
.
artifacts
,
@required
this
.
inputs
,
});
/// The [Source] value which is substituted with the path to [projectDir].
...
...
@@ -420,6 +425,16 @@ class Environment {
/// which prevents the config from leaking into different builds.
final
Map
<
String
,
String
>
defines
;
/// Additional input files passed to the build targets.
///
/// Unlike [defines], values set here do not force a new build configuration.
/// This is useful for passing file inputs that may have changing paths
/// without running builds from scratch.
///
/// It is the responsibility of the [Target] to declare that an input was
/// used in an output depfile.
final
Map
<
String
,
String
>
inputs
;
/// The root build directory shared by all builds.
final
Directory
rootBuildDir
;
...
...
packages/flutter_tools/lib/src/commands/assemble.dart
View file @
fa35698e
...
...
@@ -64,6 +64,13 @@ class AssembleCommand extends FlutterCommand {
abbr:
'd'
,
help:
'Allows passing configuration to a target with --define=target=key=value.'
,
);
argParser
.
addMultiOption
(
'input'
,
abbr:
'i'
,
help:
'Allows passing additional inputs with --input=key=value. Unlike '
'defines, additional inputs do not generate a new configuration, instead '
'they are treated as dependencies of the targets that use them.'
);
argParser
.
addOption
(
'depfile'
,
help:
'A file path where a depfile will be written. '
'This contains all build inputs and outputs in a make style syntax'
);
...
...
@@ -99,7 +106,7 @@ class AssembleCommand extends FlutterCommand {
return
const
<
CustomDimensions
,
String
>{};
}
try
{
final
Environment
localEnvironment
=
environment
;
final
Environment
localEnvironment
=
createEnvironment
()
;
return
<
CustomDimensions
,
String
>{
CustomDimensions
.
commandBuildBundleTargetPlatform
:
localEnvironment
.
defines
[
'TargetPlatform'
],
CustomDimensions
.
commandBuildBundleIsModule
:
'
${futterProject.isModule}
'
,
...
...
@@ -111,7 +118,7 @@ class AssembleCommand extends FlutterCommand {
}
/// The target(s) we are building.
List
<
Target
>
get
targets
{
List
<
Target
>
createTargets
()
{
if
(
argResults
.
rest
.
isEmpty
)
{
throwToolExit
(
'missing target name for flutter assemble.'
);
}
...
...
@@ -132,7 +139,7 @@ class AssembleCommand extends FlutterCommand {
}
/// The environmental configuration for a build invocation.
Environment
get
environment
{
Environment
createEnvironment
()
{
final
FlutterProject
flutterProject
=
FlutterProject
.
current
();
String
output
=
stringArg
(
'output'
);
if
(
output
==
null
)
{
...
...
@@ -149,6 +156,7 @@ class AssembleCommand extends FlutterCommand {
.
childDirectory
(
'flutter_build'
),
projectDir:
flutterProject
.
directory
,
defines:
_parseDefines
(
stringsArg
(
'define'
)),
inputs:
_parseDefines
(
stringsArg
(
'input'
)),
cacheDir:
globals
.
cache
.
getRoot
(),
flutterRootDir:
globals
.
fs
.
directory
(
Cache
.
flutterRoot
),
artifacts:
globals
.
artifacts
,
...
...
@@ -179,13 +187,17 @@ class AssembleCommand extends FlutterCommand {
@override
Future
<
FlutterCommandResult
>
runCommand
()
async
{
final
List
<
Target
>
targets
=
this
.
targets
;
final
List
<
Target
>
targets
=
createTargets
()
;
final
Target
target
=
targets
.
length
==
1
?
targets
.
single
:
_CompositeTarget
(
targets
);
final
BuildResult
result
=
await
globals
.
buildSystem
.
build
(
target
,
environment
,
buildSystemConfig:
BuildSystemConfig
(
resourcePoolSize:
argResults
.
wasParsed
(
'resource-pool-size'
)
?
int
.
tryParse
(
stringArg
(
'resource-pool-size'
))
:
null
,
));
final
BuildResult
result
=
await
globals
.
buildSystem
.
build
(
target
,
createEnvironment
(),
buildSystemConfig:
BuildSystemConfig
(
resourcePoolSize:
argResults
.
wasParsed
(
'resource-pool-size'
)
?
int
.
tryParse
(
stringArg
(
'resource-pool-size'
))
:
null
,
),
);
if
(!
result
.
success
)
{
for
(
final
ExceptionMeasurement
measurement
in
result
.
exceptions
.
values
)
{
globals
.
printError
(
'Target
${measurement.target}
failed:
${measurement.exception}
'
,
...
...
packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart
View file @
fa35698e
...
...
@@ -23,7 +23,7 @@ void main() {
Cache:
()
=>
FakeCache
(),
});
testbed
.
test
(
'
C
an run a build'
,
()
async
{
testbed
.
test
(
'
flutter assemble c
an run a build'
,
()
async
{
when
(
globals
.
buildSystem
.
build
(
any
,
any
,
buildSystemConfig:
anyNamed
(
'buildSystemConfig'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
return
BuildResult
(
success:
true
);
...
...
@@ -34,7 +34,7 @@ void main() {
expect
(
testLogger
.
traceText
,
contains
(
'build succeeded.'
));
});
testbed
.
test
(
'
C
an parse defines whose values contain ='
,
()
async
{
testbed
.
test
(
'
flutter assemble c
an parse defines whose values contain ='
,
()
async
{
when
(
globals
.
buildSystem
.
build
(
any
,
any
,
buildSystemConfig:
anyNamed
(
'buildSystemConfig'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
expect
((
invocation
.
positionalArguments
[
1
]
as
Environment
).
defines
,
containsPair
(
'FooBar'
,
'fizz=2'
));
...
...
@@ -46,7 +46,19 @@ void main() {
expect
(
testLogger
.
traceText
,
contains
(
'build succeeded.'
));
});
testbed
.
test
(
'Throws ToolExit if not provided with output'
,
()
async
{
testbed
.
test
(
'flutter assemble can parse inputs'
,
()
async
{
when
(
globals
.
buildSystem
.
build
(
any
,
any
,
buildSystemConfig:
anyNamed
(
'buildSystemConfig'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
expect
((
invocation
.
positionalArguments
[
1
]
as
Environment
).
inputs
,
containsPair
(
'Foo'
,
'Bar.txt'
));
return
BuildResult
(
success:
true
);
});
final
CommandRunner
<
void
>
commandRunner
=
createTestCommandRunner
(
AssembleCommand
());
await
commandRunner
.
run
(<
String
>[
'assemble'
,
'-o Output'
,
'-iFoo=Bar.txt'
,
'debug_macos_bundle_flutter_assets'
]);
expect
(
testLogger
.
traceText
,
contains
(
'build succeeded.'
));
});
testbed
.
test
(
'flutter assemble throws ToolExit if not provided with output'
,
()
async
{
when
(
globals
.
buildSystem
.
build
(
any
,
any
,
buildSystemConfig:
anyNamed
(
'buildSystemConfig'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
return
BuildResult
(
success:
true
);
...
...
@@ -57,7 +69,7 @@ void main() {
throwsToolExit
());
});
testbed
.
test
(
'
T
hrows ToolExit if called with non-existent rule'
,
()
async
{
testbed
.
test
(
'
flutter assemble t
hrows ToolExit if called with non-existent rule'
,
()
async
{
when
(
globals
.
buildSystem
.
build
(
any
,
any
,
buildSystemConfig:
anyNamed
(
'buildSystemConfig'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
return
BuildResult
(
success:
true
);
...
...
@@ -68,7 +80,7 @@ void main() {
throwsToolExit
());
});
testbed
.
test
(
'
D
oes not log stack traces during build failure'
,
()
async
{
testbed
.
test
(
'
flutter assemble d
oes not log stack traces during build failure'
,
()
async
{
final
StackTrace
testStackTrace
=
StackTrace
.
current
;
when
(
globals
.
buildSystem
.
build
(
any
,
any
,
buildSystemConfig:
anyNamed
(
'buildSystemConfig'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
...
...
@@ -84,7 +96,7 @@ void main() {
expect
(
testLogger
.
errorText
,
isNot
(
contains
(
testStackTrace
.
toString
())));
});
testbed
.
test
(
'
O
nly writes input and output files when the values change'
,
()
async
{
testbed
.
test
(
'
flutter assemble o
nly writes input and output files when the values change'
,
()
async
{
when
(
globals
.
buildSystem
.
build
(
any
,
any
,
buildSystemConfig:
anyNamed
(
'buildSystemConfig'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
return
BuildResult
(
...
...
packages/flutter_tools/test/general.shard/build_system/build_system_test.dart
View file @
fa35698e
...
...
@@ -375,6 +375,31 @@ void main() {
expect
(
environmentA
.
buildDir
.
path
,
isNot
(
environmentB
.
buildDir
.
path
));
});
testWithoutContext
(
'Additional inputs do not change the build configuration'
,
()
async
{
final
Environment
environmentA
=
Environment
.
test
(
fileSystem
.
currentDirectory
,
artifacts:
MockArtifacts
(),
processManager:
FakeProcessManager
.
any
(),
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
inputs:
<
String
,
String
>{
'C'
:
'D'
,
}
);
final
Environment
environmentB
=
Environment
.
test
(
fileSystem
.
currentDirectory
,
artifacts:
MockArtifacts
(),
processManager:
FakeProcessManager
.
any
(),
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
inputs:
<
String
,
String
>{
'A'
:
'B'
,
}
);
expect
(
environmentA
.
buildDir
.
path
,
equals
(
environmentB
.
buildDir
.
path
));
});
testWithoutContext
(
'A target with depfile dependencies can delete stale outputs on the first run'
,
()
async
{
final
BuildSystem
buildSystem
=
setUpBuildSystem
(
fileSystem
);
int
called
=
0
;
...
...
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