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
b5d0b912
Unverified
Commit
b5d0b912
authored
Jun 10, 2020
by
Ming Lyu (CareF)
Committed by
GitHub
Jun 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup devicelab framework duplicate (#59046)
* combine forwardStandardStreams * combine exec and eval
parent
e13b44d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
36 deletions
+65
-36
utils.dart
dev/devicelab/lib/framework/utils.dart
+65
-36
No files found.
dev/devicelab/lib/framework/utils.dart
View file @
b5d0b912
...
...
@@ -324,8 +324,39 @@ Future<int> exec(
bool
canFail
=
false
,
// as in, whether failures are ok. False means that they are fatal.
String
workingDirectory
,
})
async
{
final
Process
process
=
await
startProcess
(
executable
,
arguments
,
environment:
environment
,
workingDirectory:
workingDirectory
);
await
forwardStandardStreams
(
process
);
return
_execute
(
executable
,
arguments
,
environment:
environment
,
canFail
:
canFail
,
workingDirectory:
workingDirectory
,
);
}
Future
<
int
>
_execute
(
String
executable
,
List
<
String
>
arguments
,
{
Map
<
String
,
String
>
environment
,
bool
canFail
=
false
,
// as in, whether failures are ok. False means that they are fatal.
String
workingDirectory
,
StringBuffer
output
,
// if not null, the stdout will be written here
StringBuffer
stderr
,
// if not null, the stderr will be written here
bool
printStdout
=
true
,
bool
printStderr
=
true
,
})
async
{
final
Process
process
=
await
startProcess
(
executable
,
arguments
,
environment:
environment
,
workingDirectory:
workingDirectory
,
);
await
forwardStandardStreams
(
process
,
output:
output
,
stderr:
stderr
,
printStdout:
printStdout
,
printStderr:
printStderr
,
);
final
int
exitCode
=
await
process
.
exitCode
;
if
(
exitCode
!=
0
&&
!
canFail
)
...
...
@@ -335,26 +366,42 @@ Future<int> exec(
}
/// Forwards standard out and standard error from [process] to this process'
/// respective outputs.
/// respective outputs. Also writes stdout to [output] and stderr to [stderr]
/// if they are not null.
///
/// Returns a future that completes when both out and error streams a closed.
Future
<
void
>
forwardStandardStreams
(
Process
process
)
{
Future
<
void
>
forwardStandardStreams
(
Process
process
,
{
StringBuffer
output
,
StringBuffer
stderr
,
bool
printStdout
=
true
,
bool
printStderr
=
true
,
})
{
final
Completer
<
void
>
stdoutDone
=
Completer
<
void
>();
final
Completer
<
void
>
stderrDone
=
Completer
<
void
>();
process
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
printStdout
)
{
print
(
'stdout:
$line
'
);
}
output
?.
writeln
(
line
);
},
onDone:
()
{
stdoutDone
.
complete
();
});
process
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
printStderr
)
{
print
(
'stderr:
$line
'
);
}
stderr
?.
writeln
(
line
);
},
onDone:
()
{
stderrDone
.
complete
();
});
return
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutDone
.
future
,
stderrDone
.
future
]);
return
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutDone
.
future
,
stderrDone
.
future
,
]);
}
/// Executes a command and returns its standard output as a String.
...
...
@@ -370,36 +417,18 @@ Future<String> eval(
bool
printStdout
=
true
,
bool
printStderr
=
true
,
})
async
{
final
Process
process
=
await
startProcess
(
executable
,
arguments
,
environment:
environment
,
workingDirectory:
workingDirectory
);
final
StringBuffer
output
=
StringBuffer
();
final
Completer
<
void
>
stdoutDone
=
Completer
<
void
>();
final
Completer
<
void
>
stderrDone
=
Completer
<
void
>();
process
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
printStdout
)
{
print
(
'stdout:
$line
'
);
}
output
.
writeln
(
line
);
},
onDone:
()
{
stdoutDone
.
complete
();
});
process
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
printStderr
)
{
print
(
'stderr:
$line
'
);
}
stderr
?.
writeln
(
line
);
},
onDone:
()
{
stderrDone
.
complete
();
});
await
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutDone
.
future
,
stderrDone
.
future
]);
final
int
exitCode
=
await
process
.
exitCode
;
if
(
exitCode
!=
0
&&
!
canFail
)
fail
(
'Executable "
$executable
" failed with exit code
$exitCode
.'
);
await
_execute
(
executable
,
arguments
,
environment:
environment
,
canFail:
canFail
,
workingDirectory:
workingDirectory
,
output:
output
,
stderr:
stderr
,
printStdout:
printStdout
,
printStderr:
printStderr
,
);
return
output
.
toString
().
trimRight
();
}
...
...
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