Skip to content

Commit

Permalink
Merge branch 'dart-lang:master' into fix/cronet-sdk-version
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Jan 4, 2024
2 parents fe2c474 + 473a892 commit d85ac82
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
15 changes: 10 additions & 5 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Configuration for .github/workflows/pull_request_label.yml.

'type-infra':
- '.github/**'
- changed-files:
- any-glob-to-any-file: '.github/**'

'package:cronet_http':
- 'pkgs/cronet_http/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/cronet_http/**'

'package:cupertino_http':
- 'pkgs/cupertino_http/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/cupertino_http/**'

'package:http':
- 'pkgs/http/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/http/**'

'package:http_client_conformance_tests':
- 'pkgs/http_client_conformance_tests/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/http_client_conformance_tests/**'
41 changes: 29 additions & 12 deletions pkgs/cronet_http/tool/prepare_for_embedded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ final _cronetVersionUri = Uri.https(
'dl.google.com',
'android/maven2/org/chromium/net/group-index.xml',
);
// Finds the Google Play Services Cronet dependency line. For example:
// ' implementation "com.google.android.gms:play-services-cronet:18.0.1"'
final implementationRegExp = RegExp(
'^\\s*implementation [\'"]'
'$_gmsDependencyName'
':\\d+.\\d+.\\d+[\'"]',
multiLine: true,
);

void main(List<String> args) async {
if (Directory.current.path.endsWith('tool')) {
Expand All @@ -51,7 +59,8 @@ void main(List<String> args) async {
}

final latestVersion = await _getLatestCronetVersion();
updateCronetDependency(latestVersion);
updateBuildGradle(latestVersion);
updateExampleBuildGradle();
updatePubSpec();
updateReadme();
updateLibraryName();
Expand All @@ -75,22 +84,30 @@ Future<String> _getLatestCronetVersion() async {
}

/// Update android/build.gradle.
void updateCronetDependency(String latestVersion) {
final fBuildGradle = File('${_packageDirectory.path}/android/build.gradle');
final gradleContent = fBuildGradle.readAsStringSync();
final implementationRegExp = RegExp(
'^\\s*implementation [\'"]'
'$_gmsDependencyName'
':\\d+.\\d+.\\d+[\'"]',
multiLine: true,
);
void updateBuildGradle(String latestVersion) {
final buildGradle = File('${_packageDirectory.path}/android/build.gradle');
final gradleContent = buildGradle.readAsStringSync();
final newImplementation = '$_embeddedDependencyName:$latestVersion';
print('Patching $newImplementation');
print('Updating ${buildGradle.path}: adding $newImplementation');
final newGradleContent = gradleContent.replaceAll(
implementationRegExp,
' implementation "$newImplementation"',
);
fBuildGradle.writeAsStringSync(newGradleContent);
buildGradle.writeAsStringSync(newGradleContent);
}

/// Remove the cronet reference from ./example/android/app/build.gradle.
void updateExampleBuildGradle() {
final buildGradle =
File('${_packageDirectory.path}/example/android/app/build.gradle');
final gradleContent = buildGradle.readAsStringSync();

print('Updating ${buildGradle.path}: removing cronet reference');
final newGradleContent = gradleContent.replaceAll(
implementationRegExp,
' // NOTE: removed in package:cronet_http_embedded',
);
buildGradle.writeAsStringSync(newGradleContent);
}

/// Update pubspec.yaml and example/pubspec.yaml.
Expand Down

0 comments on commit d85ac82

Please sign in to comment.