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
30692ee4
Unverified
Commit
30692ee4
authored
Aug 04, 2023
by
Andrew Kolos
Committed by
GitHub
Aug 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make `--dart-define` override redundant values in `--dart-define-from-file` (#131088)
Fixes #130604
parent
b2381348
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
10 deletions
+46
-10
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+8
-8
assemble_test.dart
...ter_tools/test/commands.shard/hermetic/assemble_test.dart
+1
-1
build_bundle_test.dart
...ools/test/commands.shard/permeable/build_bundle_test.dart
+37
-1
No files found.
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
30692ee4
...
...
@@ -646,7 +646,8 @@ abstract class FlutterCommand extends Command<void> {
help:
'The path of a .json or .env file containing key-value pairs that will be available as environment variables.
\n
'
'These can be accessed using the String.fromEnvironment, bool.fromEnvironment, and int.fromEnvironment constructors.
\n
'
'Multiple defines can be passed by repeating "--
${FlutterOptions.kDartDefineFromFileOption}
" multiple times.'
,
'Multiple defines can be passed by repeating "--
${FlutterOptions.kDartDefineFromFileOption}
" multiple times.
\n
'
'Entries from "--
${FlutterOptions.kDartDefinesOption}
" with identical keys take precedence over entries from these files.'
,
valueHelp:
'use-define-config.json|.env'
,
splitCommas:
false
,
);
...
...
@@ -1351,14 +1352,14 @@ abstract class FlutterCommand extends Command<void> {
List
<
String
>
extractDartDefines
({
required
Map
<
String
,
Object
?>
defineConfigJsonMap
})
{
final
List
<
String
>
dartDefines
=
<
String
>[];
if
(
argParser
.
options
.
containsKey
(
FlutterOptions
.
kDartDefinesOption
))
{
dartDefines
.
addAll
(
stringsArg
(
FlutterOptions
.
kDartDefinesOption
));
}
defineConfigJsonMap
.
forEach
((
String
key
,
Object
?
value
)
{
dartDefines
.
add
(
'
$key
=
$value
'
);
});
if
(
argParser
.
options
.
containsKey
(
FlutterOptions
.
kDartDefinesOption
))
{
dartDefines
.
addAll
(
stringsArg
(
FlutterOptions
.
kDartDefinesOption
));
}
return
dartDefines
;
}
...
...
@@ -1372,9 +1373,8 @@ abstract class FlutterCommand extends Command<void> {
for
(
final
String
path
in
configFilePaths
)
{
if
(!
globals
.
fs
.
isFileSync
(
path
))
{
throwToolExit
(
'Json config define file "--
${FlutterOptions
.kDartDefineFromFileOption}
=
$path
" is not a file, '
'please fix first!'
);
throwToolExit
(
'Did not find the file passed to "--
${FlutterOptions
.kDartDefineFromFileOption}
". Path:
$path
'
);
}
final
String
configRaw
=
globals
.
fs
.
file
(
path
).
readAsStringSync
();
...
...
packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart
View file @
30692ee4
...
...
@@ -302,7 +302,7 @@ void main() {
'debug_macos_bundle_flutter_assets'
,
'--dart-define=k=v'
,
'--dart-define-from-file=config'
]),
throwsToolExit
(
message:
'
Json config define file "--dart-define-from-file=config" is not a file, please fix first!
'
));
throwsToolExit
(
message:
'
Did not find the file passed to "--dart-define-from-file". Path: config
'
));
},
overrides:
<
Type
,
Generator
>{
Cache:
()
=>
Cache
.
test
(
processManager:
FakeProcessManager
.
any
()),
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
...
...
packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart
View file @
30692ee4
...
...
@@ -559,6 +559,42 @@ void main() {
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
testUsingContext
(
'values from --dart-define supersede values from --dart-define-from-file'
,
()
async
{
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'lib'
,
'main.dart'
))
.
createSync
(
recursive:
true
);
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
globals
.
fs
.
file
(
'.env'
).
writeAsStringSync
(
'''
MY_VALUE=VALUE_FROM_ENV_FILE
'''
);
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
(
logger:
BufferLogger
.
test
(),
));
await
runner
.
run
(<
String
>[
'bundle'
,
'--no-pub'
,
'--dart-define=MY_VALUE=VALUE_FROM_COMMAND'
,
'--dart-define-from-file=.env'
,
]);
},
overrides:
<
Type
,
Generator
>{
BuildSystem:
()
=>
TestBuildSystem
.
all
(
BuildResult
(
success:
true
),
(
Target
target
,
Environment
environment
)
{
expect
(
_decodeDartDefines
(
environment
),
containsAllInOrder
(
const
<
String
>[
'MY_VALUE=VALUE_FROM_ENV_FILE'
,
'MY_VALUE=VALUE_FROM_COMMAND'
,
]),
);
}),
FileSystem:
fsFactory
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
testUsingContext
(
'--dart-define-from-file correctly parses a valid env file'
,
()
async
{
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'lib'
,
'main.dart'
))
...
...
@@ -763,7 +799,7 @@ void main() {
'bundle'
,
'--no-pub'
,
'--dart-define-from-file=config'
,
]),
throwsToolExit
(
message:
'
Json config define file "--dart-define-from-file=config" is not a file, please fix first!
'
));
]),
throwsToolExit
(
message:
'
Did not find the file passed to "--dart-define-from-file". Path: config
'
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
fsFactory
,
BuildSystem:
()
=>
TestBuildSystem
.
all
(
BuildResult
(
success:
true
)),
...
...
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