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
6e08ea0a
Unverified
Commit
6e08ea0a
authored
May 10, 2021
by
Anurag Roy
Committed by
GitHub
May 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Show linux distribution and kernel release in `flutter doctor` (#81368)
parent
c7c67e19
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
207 additions
and
0 deletions
+207
-0
os.dart
packages/flutter_tools/lib/src/base/os.dart
+79
-0
os_test.dart
packages/flutter_tools/test/general.shard/base/os_test.dart
+128
-0
No files found.
packages/flutter_tools/lib/src/base/os.dart
View file @
6e08ea0a
...
...
@@ -35,6 +35,13 @@ abstract class OperatingSystemUtils {
platform:
platform
,
processManager:
processManager
,
);
}
else
if
(
platform
.
isLinux
)
{
return
_LinuxUtils
(
fileSystem:
fileSystem
,
logger:
logger
,
platform:
platform
,
processManager:
processManager
,
);
}
else
{
return
_PosixUtils
(
fileSystem:
fileSystem
,
...
...
@@ -283,6 +290,78 @@ class _PosixUtils extends OperatingSystemUtils {
}
}
class
_LinuxUtils
extends
_PosixUtils
{
_LinuxUtils
({
required
FileSystem
fileSystem
,
required
Logger
logger
,
required
Platform
platform
,
required
ProcessManager
processManager
,
})
:
super
(
fileSystem:
fileSystem
,
logger:
logger
,
platform:
platform
,
processManager:
processManager
,
);
String
?
_name
;
@override
String
get
name
{
if
(
_name
==
null
)
{
const
String
prettyNameKey
=
'PRETTY_NAME'
;
// If "/etc/os-release" doesn't exist, fallback to "/usr/lib/os-release".
final
String
osReleasePath
=
_fileSystem
.
file
(
'/etc/os-release'
).
existsSync
()
?
'/etc/os-release'
:
'/usr/lib/os-release'
;
String
prettyName
;
String
kernelRelease
;
try
{
final
String
osRelease
=
_fileSystem
.
file
(
osReleasePath
).
readAsStringSync
();
prettyName
=
_getOsReleaseValueForKey
(
osRelease
,
prettyNameKey
);
}
on
Exception
catch
(
e
)
{
_logger
.
printTrace
(
'Failed obtaining PRETTY_NAME for Linux:
$e
'
);
prettyName
=
''
;
}
try
{
// Split the operating system version which should be formatted as
// "Linux kernelRelease build", by spaces.
final
List
<
String
>
osVersionSplitted
=
_platform
.
operatingSystemVersion
.
split
(
' '
);
if
(
osVersionSplitted
.
length
<
3
)
{
// The operating system version didn't have the expected format.
// Initialize as an empty string.
kernelRelease
=
''
;
}
else
{
kernelRelease
=
'
${osVersionSplitted[1]}
'
;
}
}
on
Exception
catch
(
e
)
{
_logger
.
printTrace
(
'Failed obtaining kernel release for Linux:
$e
'
);
kernelRelease
=
''
;
}
_name
=
'
${prettyName.isEmpty ? super.name : prettyName}$kernelRelease
'
;
}
return
_name
!;
}
String
_getOsReleaseValueForKey
(
String
osRelease
,
String
key
)
{
final
List
<
String
>
osReleaseSplitted
=
osRelease
.
split
(
'
\n
'
);
for
(
String
entry
in
osReleaseSplitted
)
{
entry
=
entry
.
trim
();
final
List
<
String
>
entryKeyValuePair
=
entry
.
split
(
'='
);
if
(
entryKeyValuePair
[
0
]
==
key
)
{
final
String
value
=
entryKeyValuePair
[
1
];
// Remove quotes from either end of the value if they exist
final
String
quote
=
value
[
0
];
if
(
quote
==
'
\'
'
||
quote
==
'"'
)
{
return
value
.
substring
(
0
,
value
.
length
-
1
).
substring
(
1
);
}
else
{
return
value
;
}
}
}
return
''
;
}
}
class
_MacOSUtils
extends
_PosixUtils
{
_MacOSUtils
({
required
FileSystem
fileSystem
,
...
...
packages/flutter_tools/test/general.shard/base/os_test.dart
View file @
6e08ea0a
...
...
@@ -380,6 +380,134 @@ void main() {
createOSUtils
(
FakePlatform
(
operatingSystem:
'macos'
));
expect
(
utils
.
name
,
'product version build darwin-x64'
);
});
testWithoutContext
(
'Windows name'
,
()
async
{
fakeProcessManager
.
addCommands
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'ver'
,
],
stdout:
'version'
,
),
]);
final
OperatingSystemUtils
utils
=
createOSUtils
(
FakePlatform
(
operatingSystem:
'windows'
));
expect
(
utils
.
name
,
'version'
);
});
testWithoutContext
(
'Linux name'
,
()
async
{
const
String
fakeOsRelease
=
'''
NAME="Name"
ID=id
ID_LIKE=id_like
BUILD_ID=build_id
PRETTY_NAME="Pretty Name"
ANSI_COLOR="ansi color"
HOME_URL="https://home.url/"
DOCUMENTATION_URL="https://documentation.url/"
SUPPORT_URL="https://support.url/"
BUG_REPORT_URL="https://bug.report.url/"
LOGO=logo
'''
;
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
directory
(
'/etc'
).
createSync
();
fileSystem
.
file
(
'/etc/os-release'
).
writeAsStringSync
(
fakeOsRelease
);
final
OperatingSystemUtils
utils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'linux'
,
operatingSystemVersion:
'Linux 1.2.3-abcd #1 SMP PREEMPT Sat Jan 1 00:00:00 UTC 2000'
,
),
processManager:
fakeProcessManager
,
);
expect
(
utils
.
name
,
'Pretty Name 1.2.3-abcd'
);
});
testWithoutContext
(
'Linux name reads from "/usr/lib/os-release" if "/etc/os-release" is missing'
,
()
async
{
const
String
fakeOsRelease
=
'''
NAME="Name"
ID=id
ID_LIKE=id_like
BUILD_ID=build_id
PRETTY_NAME="Pretty Name"
ANSI_COLOR="ansi color"
HOME_URL="https://home.url/"
DOCUMENTATION_URL="https://documentation.url/"
SUPPORT_URL="https://support.url/"
BUG_REPORT_URL="https://bug.report.url/"
LOGO=logo
'''
;
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
directory
(
'/usr/lib'
).
createSync
(
recursive:
true
);
fileSystem
.
file
(
'/usr/lib/os-release'
).
writeAsStringSync
(
fakeOsRelease
);
expect
(
fileSystem
.
file
(
'/etc/os-release'
).
existsSync
(),
false
);
final
OperatingSystemUtils
utils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'linux'
,
operatingSystemVersion:
'Linux 1.2.3-abcd #1 SMP PREEMPT Sat Jan 1 00:00:00 UTC 2000'
,
),
processManager:
fakeProcessManager
,
);
expect
(
utils
.
name
,
'Pretty Name 1.2.3-abcd'
);
});
testWithoutContext
(
'Linux name when reading "/etc/os-release" fails'
,
()
async
{
final
FileExceptionHandler
handler
=
FileExceptionHandler
();
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
(
opHandle:
handler
.
opHandle
);
fileSystem
.
directory
(
'/etc'
).
createSync
();
final
File
osRelease
=
fileSystem
.
file
(
'/etc/os-release'
);
handler
.
addError
(
osRelease
,
FileSystemOp
.
read
,
const
FileSystemException
());
final
OperatingSystemUtils
utils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'linux'
,
operatingSystemVersion:
'Linux 1.2.3-abcd #1 SMP PREEMPT Sat Jan 1 00:00:00 UTC 2000'
,
),
processManager:
fakeProcessManager
,
);
expect
(
utils
.
name
,
'Linux 1.2.3-abcd'
);
});
testWithoutContext
(
'Linux name omits kernel release if undefined'
,
()
async
{
const
String
fakeOsRelease
=
'''
NAME="Name"
ID=id
ID_LIKE=id_like
BUILD_ID=build_id
PRETTY_NAME="Pretty Name"
ANSI_COLOR="ansi color"
HOME_URL="https://home.url/"
DOCUMENTATION_URL="https://documentation.url/"
SUPPORT_URL="https://support.url/"
BUG_REPORT_URL="https://bug.report.url/"
LOGO=logo
'''
;
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
directory
(
'/etc'
).
createSync
();
fileSystem
.
file
(
'/etc/os-release'
).
writeAsStringSync
(
fakeOsRelease
);
final
OperatingSystemUtils
utils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'linux'
,
operatingSystemVersion:
'undefinedOperatingSystemVersion'
,
),
processManager:
fakeProcessManager
,
);
expect
(
utils
.
name
,
'Pretty Name'
);
});
});
testWithoutContext
(
'If unzip fails, include stderr in exception text'
,
()
{
...
...
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