diff --git a/tools/apps/update_homebrew/lib/src/impl.dart b/tools/apps/update_homebrew/lib/src/impl.dart index 938108bfbd9..2a07403193d 100644 --- a/tools/apps/update_homebrew/lib/src/impl.dart +++ b/tools/apps/update_homebrew/lib/src/impl.dart @@ -27,19 +27,28 @@ Future _getHash256( Future _updateFormula(String channel, File file, String version, Map hashes) async { + var contents = await file.readAsString(); + + // Replace the version identifier. Formulas with stable and pre-release + // versions have multiple identifiers and only the right one should be + // updated. + var versionId = channel == 'stable' + ? RegExp(r'version \"\d+\.\d+.\d+\"') + : RegExp(r'version \"\d+\.\d+.\d+\-.+\"'); + contents = contents.replaceAll(versionId, 'version "$version"'); + // Extract files and hashes that are stored in the formula in this format: // url "//release//sdk/.zip" // sha256 "" var filesAndHashes = RegExp( - 'channels/$channel/release' + - r'/(\d[\w\d\-\.]*)/sdk/([\w\d\-\.]+)\"\n(\s+)sha256 \"[\da-f]+\"', + 'channels/$channel/release' + r'/(\d[\w\d\-\.]*)/sdk/([\w\d\-\.]+)\"\n(\s+)sha256 \"[\da-f]+\"', multiLine: true); - var contents = await file.readAsString(); contents = contents.replaceAllMapped(filesAndHashes, (m) { var currentVersion = m.group(1); if (currentVersion == version) { throw new ArgumentError( - "Channel $channel is already at version $version in homebrew."); + 'Channel $channel is already at version $version in homebrew.'); } var artifact = m.group(2); var indent = m.group(3);