Skip to content

Commit

Permalink
Separate config home directories for analysis SDKs. (#7502)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Feb 23, 2024
1 parent 4334f1b commit b871f58
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Important changes to data models, configuration, and migrations between each
AppEngine version, listed here to ease deployment and troubleshooting.

## Next Release (replace with git tag when deployed)
* Note: Analysis SDK directories with separate config homes.

## `20240223t113900-all`
* Note: removed alert block syntax from markdown rendering.
Expand Down
14 changes: 8 additions & 6 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ COPY --chown=worker:worker . /home/worker/pub-dev
WORKDIR /home/worker/pub-dev

# A config directory for preview SDKs.
# TODO(https://github.com/dart-lang/pub-dev/issues/7270): Use per-SDK config directory.
RUN mkdir -p /home/worker/config/preview
RUN mkdir -p /home/worker/config/dart-stable
RUN mkdir -p /home/worker/config/dart-preview
RUN mkdir -p /home/worker/config/flutter-stable
RUN mkdir -p /home/worker/config/flutter-preview

# Setup Dart SDK into /home/worker/dart/{stable,preview}/
RUN tool/setup-dart.sh /home/worker/dart/stable 3.3.0
RUN XDG_CONFIG_HOME=/home/worker/config/preview tool/setup-dart.sh /home/worker/dart/preview 3.4.0-131.0.dev
RUN XDG_CONFIG_HOME=/home/worker/config/dart-stable tool/setup-dart.sh /home/worker/dart/stable 3.3.0
RUN XDG_CONFIG_HOME=/home/worker/config/dart-preview tool/setup-dart.sh /home/worker/dart/preview 3.4.0-131.0.dev

# Setup Flutter SDK into /home/worker/flutter/{stable,preview}/
RUN tool/setup-flutter.sh /home/worker/flutter/stable 3.19.0
RUN XDG_CONFIG_HOME=/home/worker/config/preview tool/setup-flutter.sh /home/worker/flutter/preview 3.20.0-1.1.pre
RUN XDG_CONFIG_HOME=/home/worker/config/flutter-stable tool/setup-flutter.sh /home/worker/flutter/stable 3.19.0
RUN XDG_CONFIG_HOME=/home/worker/config/flutter-preview tool/setup-flutter.sh /home/worker/flutter/preview 3.20.0-1.1.pre

# Setup webp
RUN tool/setup-webp.sh /home/worker/bin
Expand Down
6 changes: 3 additions & 3 deletions app/test/shared/versions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ void main() {
final dockerfileContent = await File('../Dockerfile.worker').readAsString();
expect(
dockerfileContent.contains(
'RUN tool/setup-dart.sh /home/worker/dart/stable stable/raw/hash/') ||
'tool/setup-dart.sh /home/worker/dart/stable stable/raw/hash/') ||
dockerfileContent.contains(
'RUN tool/setup-dart.sh /home/worker/dart/stable $toolStableDartSdkVersion'),
'tool/setup-dart.sh /home/worker/dart/stable $toolStableDartSdkVersion'),
isTrue);
expect(
dockerfileContent,
Expand All @@ -99,7 +99,7 @@ void main() {
expect(
dockerfileContent,
contains(
'RUN tool/setup-flutter.sh /home/worker/flutter/stable $toolStableFlutterSdkVersion'));
'tool/setup-flutter.sh /home/worker/flutter/stable $toolStableFlutterSdkVersion'));
expect(
dockerfileContent,
contains(
Expand Down
24 changes: 13 additions & 11 deletions pkg/pub_worker/lib/src/bin/pana_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ Future<void> main(List<String> args) async {
).writeAsString(json.encode(summary));
}

final _workerPreviewConfigDirectory = Directory('/home/worker/config/preview');
late final _workerPreviewConfigPath = _workerPreviewConfigDirectory.existsSync()
? _workerPreviewConfigDirectory.path
: null;
final _workerConfigDirectory = Directory('/home/worker/config');
late final _workerConfigPath =
_workerConfigDirectory.existsSync() ? _workerConfigDirectory.path : null;
String? _configHomePath(String sdk, String kind) {
if (_workerConfigPath == null) {
return null;
}
return p.join(_workerConfigPath!, '$sdk-$kind');
}

Future<(SdkConfig, SdkConfig)> _detectSdks(Pubspec pubspec) async {
// Discover installed Dart and Flutter SDKs.
Expand All @@ -173,15 +178,12 @@ Future<(SdkConfig, SdkConfig)> _detectSdks(Pubspec pubspec) async {
flutterSdks.firstWhereOrNull((sdk) => !sdk.version.isPreRelease) ??
(flutterSdks.isNotEmpty ? flutterSdks.first : null);

// NOTE: This is a temporary workaround to use a different config directory for preview SDKs.
// TODO(https://github.com/dart-lang/pub-dev/issues/7270): Use per-SDK config directory.
String? configDir;

final needsNewer = _needsNewer(dartSdk?.version, pubspec.dartSdkConstraint) ||
_needsNewer(flutterSdk?.version, pubspec.flutterSdkConstraint);

String configKind = 'stable';
if (needsNewer) {
configDir = _workerPreviewConfigPath;
configKind = 'preview';
dartSdk =
dartSdks.firstWhereOrNull((sdk) => sdk.version.isPreRelease) ?? dartSdk;
flutterSdk =
Expand All @@ -192,11 +194,11 @@ Future<(SdkConfig, SdkConfig)> _detectSdks(Pubspec pubspec) async {
return (
SdkConfig(
rootPath: dartSdk?.path,
configHomePath: configDir,
configHomePath: _configHomePath('dart', configKind),
),
SdkConfig(
rootPath: flutterSdk?.path,
configHomePath: configDir,
configHomePath: _configHomePath('flutter', configKind),
),
);
}
Expand Down

0 comments on commit b871f58

Please sign in to comment.