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
7b54a30e
Unverified
Commit
7b54a30e
authored
Mar 30, 2023
by
Sigurd Meldgaard
Committed by
GitHub
Mar 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notify about existing caches when preloading (#122592)
parent
a72a8baa
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
459 additions
and
281 deletions
+459
-281
pub.dart
packages/flutter_tools/lib/src/dart/pub.dart
+66
-25
pub_get_test.dart
...s/flutter_tools/test/general.shard/dart/pub_get_test.dart
+393
-256
No files found.
packages/flutter_tools/lib/src/dart/pub.dart
View file @
7b54a30e
...
...
@@ -34,28 +34,6 @@ const String _kPubCacheEnvironmentKey = 'PUB_CACHE';
typedef
MessageFilter
=
String
?
Function
(
String
message
);
/// Load any package-files stored in [preloadCacheDir] into the pub cache if it
/// exists.
///
/// Deletes the [preloadCacheDir].
@visibleForTesting
void
preloadPubCache
(
{
required
Directory
preloadCacheDir
,
required
ProcessManager
processManager
,
required
Logger
logger
,
required
List
<
String
>
pubCommand
,
})
{
if
(
preloadCacheDir
.
existsSync
())
{
final
Iterable
<
String
>
cacheFiles
=
preloadCacheDir
.
listSync
()
.
map
((
FileSystemEntity
f
)
=>
f
.
path
)
.
where
((
String
path
)
=>
path
.
endsWith
(
'.tar.gz'
));
processManager
.
runSync
(<
String
>[...
pubCommand
,
'cache'
,
'preload'
,...
cacheFiles
]);
_tryDeleteDirectory
(
preloadCacheDir
,
logger
);
}
}
bool
_tryDeleteDirectory
(
Directory
directory
,
Logger
logger
)
{
try
{
if
(
directory
.
existsSync
())
{
...
...
@@ -614,13 +592,76 @@ class _DefaultPub implements Pub {
if
(
_platform
.
environment
.
containsKey
(
_kPubCacheEnvironmentKey
))
{
return
_platform
.
environment
[
_kPubCacheEnvironmentKey
];
}
_preloadPubCache
();
// Use pub's default location by returning null.
return
null
;
}
/// Load any package-files stored in FLUTTER_ROOT/.pub-preload-cache into the
/// pub cache if it exists.
///
/// Deletes the [preloadCacheDir].
void
_preloadPubCache
()
{
final
String
flutterRootPath
=
Cache
.
flutterRoot
!;
final
Directory
flutterRoot
=
_fileSystem
.
directory
(
flutterRootPath
);
final
Directory
preloadCacheDir
=
flutterRoot
.
childDirectory
(
'.pub-preload-cache'
);
preloadPubCache
(
preloadCacheDir:
preloadCacheDir
,
logger:
_logger
,
processManager:
_processManager
,
pubCommand:
_pubCommand
);
// Use pub's default location by returning null.
return
null
;
if
(
preloadCacheDir
.
existsSync
())
{
/// We only want to inform about existing caches on first run of a freshly
/// downloaded Flutter SDK. Therefore it is conditioned on the existence
/// of the .pub-preload-cache dir.
_informAboutExistingCaches
();
final
Iterable
<
String
>
cacheFiles
=
preloadCacheDir
.
listSync
()
.
map
((
FileSystemEntity
f
)
=>
f
.
path
)
.
where
((
String
path
)
=>
path
.
endsWith
(
'.tar.gz'
));
_processManager
.
runSync
(<
String
>[...
_pubCommand
,
'cache'
,
'preload'
,
...
cacheFiles
]);
_tryDeleteDirectory
(
preloadCacheDir
,
_logger
);
}
}
/// Issues a log message if there is an existing pub cache and or an existing
/// Dart Analysis Server cache.
void
_informAboutExistingCaches
()
{
final
String
?
pubCachePath
=
_pubCacheDefaultLocation
();
if
(
pubCachePath
!=
null
)
{
final
Directory
pubCacheDirectory
=
_fileSystem
.
directory
(
pubCachePath
);
if
(
pubCacheDirectory
.
existsSync
())
{
_logger
.
printStatus
(
'''
Found an existing Pub cache at
$pubCachePath
.
It can be repaired by running `dart pub cache repair`.
It can be reset by running `dart pub cache clear`.'''
);
}
}
final
String
?
home
=
_platform
.
environment
[
'HOME'
];
if
(
home
!=
null
)
{
final
String
dartServerCachePath
=
_fileSystem
.
path
.
join
(
home
,
'.dartServer'
);
if
(
_fileSystem
.
directory
(
dartServerCachePath
).
existsSync
())
{
_logger
.
printStatus
(
'''
Found an existing Dart Analysis Server cache at
$dartServerCachePath
.
It can be reset by deleting
$dartServerCachePath
.'''
);
}
}
}
/// The default location of the Pub cache if the PUB_CACHE environment variable
/// is not set.
///
/// Returns null if the appropriate environment variables are unset.
String
?
_pubCacheDefaultLocation
()
{
if
(
_platform
.
isWindows
)
{
final
String
?
localAppData
=
_platform
.
environment
[
'LOCALAPPDATA'
];
if
(
localAppData
==
null
)
{
return
null
;
}
return
_fileSystem
.
path
.
join
(
localAppData
,
'Pub'
,
'Cache'
);
}
else
{
final
String
?
home
=
_platform
.
environment
[
'HOME'
];
if
(
home
==
null
)
{
return
null
;
}
return
_fileSystem
.
path
.
join
(
home
,
'.pub-cache'
);
}
}
/// The full environment used when running pub.
...
...
packages/flutter_tools/test/general.shard/dart/pub_get_test.dart
View file @
7b54a30e
This diff is collapsed.
Click to expand it.
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