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
7ab653c6
Unverified
Commit
7ab653c6
authored
Oct 11, 2019
by
Jonah Williams
Committed by
GitHub
Oct 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add error logging to flutter generate (#42209)
parent
4416c4f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
6 deletions
+109
-6
generate.dart
packages/flutter_tools/lib/src/commands/generate.dart
+27
-6
generate_test.dart
...ter_tools/test/commands.shard/hermetic/generate_test.dart
+82
-0
No files found.
packages/flutter_tools/lib/src/commands/generate.dart
View file @
7ab653c6
...
...
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'../base/
common
.dart'
;
import
'../base/
file_system
.dart'
;
import
'../cache.dart'
;
import
'../codegen.dart'
;
import
'../convert.dart'
;
import
'../globals.dart'
;
import
'../project.dart'
;
import
'../runner/flutter_command.dart'
;
...
...
@@ -18,9 +20,6 @@ class GenerateCommand extends FlutterCommand {
@override
String
get
name
=>
'generate'
;
@override
bool
get
hidden
=>
true
;
@override
Future
<
Set
<
DevelopmentArtifact
>>
get
requiredArtifacts
async
=>
const
<
DevelopmentArtifact
>{
DevelopmentArtifact
.
universal
,
...
...
@@ -34,12 +33,34 @@ class GenerateCommand extends FlutterCommand {
codegenDaemon
.
startBuild
();
await
for
(
CodegenStatus
codegenStatus
in
codegenDaemon
.
buildResults
)
{
if
(
codegenStatus
==
CodegenStatus
.
Failed
)
{
throwToolExit
(
'Code generation failed'
);
printError
(
'Code generation failed.'
);
break
;
}
if
(
codegenStatus
==
CodegenStatus
.
Succeeded
)
{
break
;
}
}
return
null
;
// Check for errors output in the build_runner cache.
final
Directory
buildDirectory
=
flutterProject
.
dartTool
.
childDirectory
(
'build'
);
final
Directory
errorCacheParent
=
buildDirectory
.
listSync
().
firstWhere
((
FileSystemEntity
entity
)
{
return
entity
is
Directory
&&
entity
.
childDirectory
(
'error_cache'
).
existsSync
();
},
orElse:
()
=>
null
);
if
(
errorCacheParent
==
null
)
{
return
null
;
}
final
Directory
errorCache
=
errorCacheParent
.
childDirectory
(
'error_cache'
);
for
(
File
errorFile
in
errorCache
.
listSync
(
recursive:
true
).
whereType
<
File
>())
{
try
{
final
List
<
Object
>
errorData
=
json
.
decode
(
errorFile
.
readAsStringSync
());
final
List
<
Object
>
stackData
=
errorData
[
1
];
printError
(
errorData
.
first
);
printError
(
stackData
[
0
]);
printError
(
stackData
[
1
]);
printError
(
StackTrace
.
fromString
(
stackData
[
2
]).
toString
());
}
catch
(
err
)
{
printError
(
'Error reading error in
${errorFile.path}
'
);
}
}
return
const
FlutterCommandResult
(
ExitStatus
.
fail
);
}
}
packages/flutter_tools/test/commands.shard/hermetic/generate_test.dart
0 → 100644
View file @
7ab653c6
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/codegen.dart'
;
import
'package:flutter_tools/src/commands/generate.dart'
;
import
'package:flutter_tools/src/convert.dart'
;
import
'package:flutter_tools/src/globals.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../../src/common.dart'
;
import
'../../src/mocks.dart'
;
import
'../../src/testbed.dart'
;
void
main
(
)
{
Testbed
testbed
;
MockCodeGenerator
mockCodeGenerator
;
MockCodegenDaemon
mockCodegenDaemon
;
setUpAll
(()
{
Cache
.
disableLocking
();
});
tearDownAll
(()
{
Cache
.
enableLocking
();
});
setUp
(()
{
mockCodegenDaemon
=
MockCodegenDaemon
();
mockCodeGenerator
=
MockCodeGenerator
();
when
(
mockCodegenDaemon
.
buildResults
).
thenAnswer
((
Invocation
invocation
)
{
return
Stream
<
CodegenStatus
>.
fromIterable
(<
CodegenStatus
>[
CodegenStatus
.
Started
,
CodegenStatus
.
Succeeded
,
]);
});
when
(
mockCodeGenerator
.
daemon
(
any
)).
thenAnswer
((
Invocation
invocation
)
async
{
return
mockCodegenDaemon
;
});
testbed
=
Testbed
(
overrides:
<
Type
,
Generator
>{
CodeGenerator:
()
=>
mockCodeGenerator
,
});
});
test
(
'Outputs error information from flutter generate'
,
()
=>
testbed
.
run
(()
async
{
final
GenerateCommand
command
=
GenerateCommand
();
final
BufferLogger
bufferLogger
=
logger
;
applyMocksToCommand
(
command
);
fs
.
file
(
fs
.
path
.
join
(
'lib'
,
'main.dart'
))
..
createSync
(
recursive:
true
);
fs
.
currentDirectory
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'build'
)
.
childDirectory
(
'abcdefg'
)
.
childDirectory
(
'error_cache'
)
.
childFile
(
'foo_error'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
json
.
encode
(<
dynamic
>[
'foo builder'
,
<
dynamic
>[
'a'
,
'b'
,
StackTrace
.
current
.
toString
(),
]
]));
await
createTestCommandRunner
(
command
)
.
run
(
const
<
String
>[
'generate'
]);
expect
(
bufferLogger
.
errorText
,
contains
(
'a'
));
expect
(
bufferLogger
.
errorText
,
contains
(
'b'
));
expect
(
bufferLogger
.
errorText
,
contains
(
'foo builder'
));
expect
(
bufferLogger
.
errorText
,
isNot
(
contains
(
'Error reading error'
)));
}));
}
class
MockCodeGenerator
extends
Mock
implements
CodeGenerator
{
}
class
MockCodegenDaemon
extends
Mock
implements
CodegenDaemon
{
}
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