diff --git a/.ci/Dockerfile b/.ci/Dockerfile new file mode 100644 index 00000000..b08e7e82 --- /dev/null +++ b/.ci/Dockerfile @@ -0,0 +1,9 @@ +FROM cirrusci/flutter:latest + +RUN yes | sdkmanager \ + "platforms;android-27" \ + "build-tools;27.0.3" \ + "extras;google;m2repository" \ + "extras;android;m2repository" + +RUN yes | sdkmanager --licenses \ No newline at end of file diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 00000000..17189792 --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,77 @@ +task: + use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true' && $CIRRUS_PR == '' + container: + dockerfile: .ci/Dockerfile + cpu: 4 + memory: 8G + upgrade_script: + - flutter channel master + - flutter upgrade + - git fetch origin master + activate_script: pub global activate flutter_plugin_tools + matrix: + - name: publishable + script: ./script/check_publish.sh + - name: test+format + install_script: + - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + - sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main" + - sudo apt-get update + - sudo apt-get install -y --allow-unauthenticated clang-format-7 + format_script: ./script/incremental_build.sh format --travis --clang-format=clang-format-7 + test_script: ./script/incremental_build.sh test + - name: analyze + script: ./script/incremental_build.sh analyze + - name: build_all_plugins_apk + script: ./script/build_all_plugins_app.sh apk + - name: build-apks+java-test+drive-examples + env: + matrix: + PLUGIN_SHARDING: "--shardIndex 0 --shardCount 2" + PLUGIN_SHARDING: "--shardIndex 1 --shardCount 2" + script: + # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they + # might include non-ASCII characters which makes Gradle crash. + # See: https://github.com/flutter/flutter/issues/24935 + # This is a temporary workaround until we figure how to properly configure + # a UTF8 locale on Cirrus (or until the Gradle bug is fixed). + # TODO(amirh): Set the locale to UTF8. + - echo "$CIRRUS_CHANGE_MESSAGE" > /tmp/cirrus_change_message.txt + - echo "$CIRRUS_COMMIT_MESSAGE" > /tmp/cirrus_commit_message.txt + - export CIRRUS_CHANGE_MESSAGE="" + - export CIRRUS_COMMIT_MESSAGE="" + - ./script/incremental_build.sh build-examples --apk + - ./script/incremental_build.sh java-test # must come after apk build + - export CIRRUS_CHANGE_MESSAGE=`cat /tmp/cirrus_change_message.txt` + - export CIRRUS_COMMIT_MESSAGE=`cat /tmp/cirrus_commit_message.txt` + +task: + use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true' + osx_instance: + image: mojave-xcode-10.2-flutter + setup_script: + - pod repo update + upgrade_script: + - flutter channel master + - flutter upgrade + - git fetch origin master + activate_script: + - pub global activate flutter_plugin_tools + create_simulator_script: + - xcrun simctl list + - xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-X com.apple.CoreSimulator.SimRuntime.iOS-12-2 | xargs xcrun simctl boot + matrix: + - name: build_all_plugins_ipa + script: ./script/build_all_plugins_app.sh ios --no-codesign + - name: build-ipas+drive-examples + env: + PATH: $PATH:/usr/local/bin + matrix: + PLUGIN_SHARDING: "--shardIndex 0 --shardCount 4" + PLUGIN_SHARDING: "--shardIndex 1 --shardCount 4" + PLUGIN_SHARDING: "--shardIndex 2 --shardCount 4" + PLUGIN_SHARDING: "--shardIndex 3 --shardCount 4" + SIMCTL_CHILD_MAPS_API_KEY: ENCRYPTED[596a9f6bca436694625ac50851dc5da6b4d34cba8025f7db5bc9465142e8cd44e15f69e3507787753accebfc4910d550] + build_script: + - ./script/incremental_build.sh build-examples --ipa + - ./script/incremental_build.sh drive-examples \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..c450df61 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf + +[pubspec.yaml] +trim_trailing_whitespace = false + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..81c7ab17 --- /dev/null +++ b/.gitignore @@ -0,0 +1,75 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# Visual Studio Code related +.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins +.packages +.pub-cache/ +.pub/ +/build/ +/packages/**/build/* + +# Android related +**/android/**/gradle-wrapper.jar +**/android/.gradle +**/android/captures/ +**/android/gradlew +**/android/gradlew.bat +**/android/local.properties +**/android/**/GeneratedPluginRegistrant.java + +# iOS/XCode related +**/ios/**/*.mode1v3 +**/ios/**/*.mode2v3 +**/ios/**/*.moved-aside +**/ios/**/*.pbxuser +**/ios/**/*.perspectivev3 +**/ios/**/*sync/ +**/ios/**/.sconsign.dblite +**/ios/**/.tags* +**/ios/**/.vagrant/ +**/ios/**/DerivedData/ +**/ios/**/Icon? +**/ios/**/Pods/ +**/ios/**/.symlinks/ +**/ios/**/profile +**/ios/**/xcuserdata +**/ios/.generated/ +**/ios/Flutter/App.framework +**/ios/Flutter/Flutter.framework +**/ios/Flutter/Generated.xcconfig +**/ios/Flutter/app.flx +**/ios/Flutter/app.zip +**/ios/Flutter/flutter_assets/ +**/ios/Flutter/flutter_export_environment.sh +**/ios/ServiceDefinitions.json +**/ios/Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!**/ios/**/default.mode1v3 +!**/ios/**/default.mode2v3 +!**/ios/**/default.pbxuser +!**/ios/**/default.perspectivev3 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages + +# Additional packages +packages/**/pubspec.lock diff --git a/packages/auto_animated/.gitignore b/packages/auto_animated/.gitignore deleted file mode 100644 index e9dc58d3..00000000 --- a/packages/auto_animated/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.DS_Store -.dart_tool/ - -.packages -.pub/ - -build/ diff --git a/packages/native_color/.gitignore b/packages/native_color/.gitignore deleted file mode 100644 index e9dc58d3..00000000 --- a/packages/native_color/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.DS_Store -.dart_tool/ - -.packages -.pub/ - -build/ diff --git a/packages/native_pdf_renderer/.gitignore b/packages/native_pdf_renderer/.gitignore deleted file mode 100644 index 5fbae0c1..00000000 --- a/packages/native_pdf_renderer/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -.idea/ -.dart_tool/ -*/ios/Flutter/flutter_export_environment.sh - -.packages -.pub/ -pubspec.lock - -build/ diff --git a/packages/native_pdf_renderer/ios/Classes/NativePDFRendererPlugin.h b/packages/native_pdf_renderer/ios/Classes/NativePDFRendererPlugin.h index 21526d21..5390db8a 100644 --- a/packages/native_pdf_renderer/ios/Classes/NativePDFRendererPlugin.h +++ b/packages/native_pdf_renderer/ios/Classes/NativePDFRendererPlugin.h @@ -1,4 +1,4 @@ #import -@interface NativePDFRendererPlugin : NSObject +@interface NativePDFRendererPlugin : NSObject @end diff --git a/packages/native_pdf_renderer/pubspec.lock b/packages/native_pdf_renderer/pubspec.lock new file mode 100644 index 00000000..5204cee4 --- /dev/null +++ b/packages/native_pdf_renderer/pubspec.lock @@ -0,0 +1,57 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.11" + extension: + dependency: "direct main" + description: + name: extension + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.5" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + meta: + dependency: "direct main" + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.7" + pedantic: + dependency: "direct dev" + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.6" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.8" +sdks: + dart: ">=2.2.2 <3.0.0" diff --git a/packages/native_pdf_view/.gitignore b/packages/native_pdf_view/.gitignore deleted file mode 100644 index 7897bed4..00000000 --- a/packages/native_pdf_view/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.DS_Store -.idea/ -.dart_tool/ - -.packages -.pub/ -pubspec.lock - -build/ diff --git a/packages/native_pdf_view/android/src/main/java/io/scer/pdf_viewer/NativePDFViewPlugin.java b/packages/native_pdf_view/android/src/main/java/io/scer/pdf_viewer/NativePDFViewPlugin.java index 903628b1..6a207133 100644 --- a/packages/native_pdf_view/android/src/main/java/io/scer/pdf_viewer/NativePDFViewPlugin.java +++ b/packages/native_pdf_view/android/src/main/java/io/scer/pdf_viewer/NativePDFViewPlugin.java @@ -7,7 +7,11 @@ import android.os.Build; import android.os.ParcelFileDescriptor; import android.util.Log; - +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; +import io.flutter.plugin.common.PluginRegistry.Registrar; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -17,155 +21,148 @@ import java.util.List; import java.util.UUID; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.PluginRegistry.Registrar; - -/** - * NativePDFViewPlugin - */ +/** NativePDFViewPlugin */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class NativePDFViewPlugin implements MethodCallHandler { - private PdfRenderer mPdfRenderer; - private PdfRenderer.Page mCurrentPage; - private ParcelFileDescriptor mFileDescriptor; - private Registrar registrar; - - private NativePDFViewPlugin(Registrar registrar) { - this.registrar = registrar; + private PdfRenderer mPdfRenderer; + private PdfRenderer.Page mCurrentPage; + private ParcelFileDescriptor mFileDescriptor; + private Registrar registrar; + + private NativePDFViewPlugin(Registrar registrar) { + this.registrar = registrar; + } + + /** Plugin registration. */ + public static void registerWith(Registrar registrar) { + final MethodChannel channel = new MethodChannel(registrar.messenger(), "io.scer.pdf_renderer"); + channel.setMethodCallHandler(new NativePDFViewPlugin(registrar)); + } + + @Override + public void onMethodCall(MethodCall call, Result result) { + if (call.method.equals("renderPdf")) { + try { + String path = call.argument("path"); + Boolean isAsset = call.argument("isAsset"); + result.success(renderPdf(path, isAsset)); + } catch (IOException e) { + result.error("RENDER_ERROR", "Can't load file", null); + } + } else { + result.notImplemented(); } + } - /** - * Plugin registration. - */ - public static void registerWith(Registrar registrar) { - final MethodChannel channel = new MethodChannel(registrar.messenger(), "io.scer.pdf_renderer"); - channel.setMethodCallHandler(new NativePDFViewPlugin(registrar)); + private List renderPdf(String filePath, Boolean isAsset) throws IOException { + InputStream inputStream = + isAsset + ? registrar.context().getAssets().open(registrar.lookupKeyForAsset(filePath)) + : new FileInputStream(filePath); + PdfRenderer renderer = openRenderer(registrar.context(), inputStream); + if (renderer == null) { + return new ArrayList<>(); } - @Override - public void onMethodCall(MethodCall call, Result result) { - if (call.method.equals("renderPdf")) { - try { - String path = call.argument("path"); - Boolean isAsset = call.argument("isAsset"); - result.success(renderPdf(path, isAsset)); - } catch (IOException e) { - result.error("RENDER_ERROR", "Can't load file", null); - } - } else { - result.notImplemented(); - } + List bitmaps = new ArrayList<>(); + int count = renderer.getPageCount(); + for (int i = 0; i < count; i++) { + Bitmap bitmap = createBitmapOfPage(registrar.context(), i); + if (bitmap != null) { + bitmaps.add(bitmap); + } } + closeRenderer(); - private List renderPdf(String filePath, Boolean isAsset) throws IOException { - InputStream inputStream = isAsset - ? registrar.context().getAssets().open(registrar.lookupKeyForAsset(filePath)) - : new FileInputStream(filePath); - PdfRenderer renderer = openRenderer(registrar.context(), inputStream); - if (renderer == null) { - return new ArrayList<>(); - } - - List bitmaps = new ArrayList<>(); - int count = renderer.getPageCount(); - for (int i = 0; i < count; i++) { - Bitmap bitmap = createBitmapOfPage(registrar.context(), i); - if (bitmap != null) { - bitmaps.add(bitmap); - } + // Send bitmaps to flutter + List list = new ArrayList<>(); + for (Bitmap bitmap : bitmaps) { + String s = saveBitmap(bitmap); + list.add(s); + } + return list; + } + + private PdfRenderer openRenderer(Context context, InputStream asset) throws IOException { + File file = new File(context.getCacheDir(), generateRandomFilename() + ".pdf"); + Log.d("openRenderer", "created file: " + file); + if (!file.exists()) { + try { + FileOutputStream output = null; + output = new FileOutputStream(file); + final byte[] buffer = new byte[1024]; + int size; + + while ((size = asset.read(buffer)) != -1) { + output.write(buffer, 0, size); } - closeRenderer(); + asset.close(); + output.close(); - // Send bitmaps to flutter - List list = new ArrayList<>(); - for (Bitmap bitmap : bitmaps) { - String s = saveBitmap(bitmap); - list.add(s); - } - return list; + } catch (IOException e) { + e.printStackTrace(); + } } - private PdfRenderer openRenderer(Context context, InputStream asset) throws IOException { - File file = new File(context.getCacheDir(), generateRandomFilename() + ".pdf"); - Log.d("openRenderer", "created file: " + file); - if (!file.exists()) { - try { - FileOutputStream output = null; - output = new FileOutputStream(file); - final byte[] buffer = new byte[1024]; - int size; - - while ((size = asset.read(buffer)) != -1) { - output.write(buffer, 0, size); - } - asset.close(); - output.close(); - - } catch (IOException e) { - e.printStackTrace(); - } - } + mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); + if (mFileDescriptor != null) { + return mPdfRenderer = new PdfRenderer(mFileDescriptor); + } - mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); - if (mFileDescriptor != null) { - return mPdfRenderer = new PdfRenderer(mFileDescriptor); - } + return null; + } - return null; + private Bitmap createBitmapOfPage(Context context, int index) { + // Show the first page. + if (mPdfRenderer.getPageCount() <= index) { + return null; } - private Bitmap createBitmapOfPage(Context context, int index) { - // Show the first page. - if (mPdfRenderer.getPageCount() <= index) { - return null; - } - - // Make sure to close the current page before opening another one. - if (null != mCurrentPage) { - mCurrentPage.close(); - } + // Make sure to close the current page before opening another one. + if (null != mCurrentPage) { + mCurrentPage.close(); + } - mCurrentPage = mPdfRenderer.openPage(index); + mCurrentPage = mPdfRenderer.openPage(index); - final float widthPixels = context.getResources().getDisplayMetrics().widthPixels; - final float heightPixels = context.getResources().getDisplayMetrics().heightPixels; + final float widthPixels = context.getResources().getDisplayMetrics().widthPixels; + final float heightPixels = context.getResources().getDisplayMetrics().heightPixels; - Bitmap bitmap = Bitmap.createBitmap( + Bitmap bitmap = + Bitmap.createBitmap( Math.round(mCurrentPage.getWidth() * 2), Math.round(mCurrentPage.getHeight() * 2), Bitmap.Config.ARGB_8888); - // Now render the page onto the Bitmap. - mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); - - if (null != mCurrentPage) { - mCurrentPage.close(); - mCurrentPage = null; - } + // Now render the page onto the Bitmap. + mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); - return bitmap; + if (null != mCurrentPage) { + mCurrentPage.close(); + mCurrentPage = null; } - private void closeRenderer() throws IOException { - mPdfRenderer.close(); - mFileDescriptor.close(); - } + return bitmap; + } - private String saveBitmap(Bitmap bitmap) throws IOException { - File createdPdfBitmap = new File(registrar.context().getCacheDir(), generateRandomFilename() + ".png"); - FileOutputStream fOut = new FileOutputStream(createdPdfBitmap); - bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); - fOut.flush(); - fOut.close(); + private void closeRenderer() throws IOException { + mPdfRenderer.close(); + mFileDescriptor.close(); + } - return createdPdfBitmap.getAbsolutePath(); - } + private String saveBitmap(Bitmap bitmap) throws IOException { + File createdPdfBitmap = + new File(registrar.context().getCacheDir(), generateRandomFilename() + ".png"); + FileOutputStream fOut = new FileOutputStream(createdPdfBitmap); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); + fOut.flush(); + fOut.close(); - private String generateRandomFilename() { - return UUID.randomUUID().toString().replaceAll("-", ""); - } + return createdPdfBitmap.getAbsolutePath(); + } + + private String generateRandomFilename() { + return UUID.randomUUID().toString().replaceAll("-", ""); + } } diff --git a/packages/native_pdf_view/example/pubspec.yaml b/packages/native_pdf_view/example/pubspec.yaml index 96211122..5d22002d 100644 --- a/packages/native_pdf_view/example/pubspec.yaml +++ b/packages/native_pdf_view/example/pubspec.yaml @@ -8,7 +8,7 @@ environment: dependencies: flutter: sdk: flutter - photo_view: ^0.2.1 + photo_view: ^0.5.0 path_provider: ^0.4.1 dev_dependencies: diff --git a/packages/native_pdf_view/ios/Classes/NativePDFViewPlugin.h b/packages/native_pdf_view/ios/Classes/NativePDFViewPlugin.h index 8cb19c8b..ac8f2cf7 100644 --- a/packages/native_pdf_view/ios/Classes/NativePDFViewPlugin.h +++ b/packages/native_pdf_view/ios/Classes/NativePDFViewPlugin.h @@ -1,4 +1,4 @@ #import -@interface NativePDFViewPlugin : NSObject +@interface NativePDFViewPlugin : NSObject @end diff --git a/packages/native_pdf_view/pubspec.lock b/packages/native_pdf_view/pubspec.lock new file mode 100644 index 00000000..02fa4f31 --- /dev/null +++ b/packages/native_pdf_view/pubspec.lock @@ -0,0 +1,43 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.11" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + meta: + dependency: "direct main" + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.7" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.6" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.8" +sdks: + dart: ">=2.2.2 <3.0.0" diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh new file mode 100644 index 00000000..bdfdc606 --- /dev/null +++ b/script/build_all_plugins_app.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# This script builds the app in flutter/plugins/example/all_plugins to make +# sure all first party plugins can be compiled together. + +# So that users can run this script from anywhere and it will work as expected. +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)" +REPO_DIR="$(dirname "$SCRIPT_DIR")" + +source "$SCRIPT_DIR/common.sh" +check_changed_packages > /dev/null + +(cd "$REPO_DIR" && pub global run flutter_plugin_tools all-plugins-app --exclude instrumentation_adapter) + +function error() { + echo "$@" 1>&2 +} + +failures=0 + +for version in "debug" "release"; do + (cd $REPO_DIR/all_plugins && flutter build $@ --$version) + + if [ $? -eq 0 ]; then + echo "Successfully built $version all_plugins app." + echo "All first party plugins compile together." + else + error "Failed to build $version all_plugins app." + if [[ "${#CHANGED_PACKAGE_LIST[@]}" == 0 ]]; then + error "There was a failure to compile all first party plugins together, but there were no changes detected in packages." + else + error "Changes to the following packages may prevent all first party plugins from compiling together:" + for package in "${CHANGED_PACKAGE_LIST[@]}"; do + error "$package" + done + echo "" + fi + failures=$(($failures + 1)) + fi +done + +rm -rf $REPO_DIR/all_plugins/ +exit $failures \ No newline at end of file diff --git a/script/common.sh b/script/common.sh new file mode 100755 index 00000000..d84958d7 --- /dev/null +++ b/script/common.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +function error() { + echo "$@" 1>&2 +} + +function get_branch_base_sha() { + local branch_base_sha="$(git merge-base --fork-point FETCH_HEAD HEAD || git merge-base FETCH_HEAD HEAD)" + echo "$branch_base_sha" +} + +function check_changed_packages() { + # Try get a merge base for the branch and calculate affected packages. + # We need this check because some CIs can do a single branch clones with a limited history of commits. + local packages + local branch_base_sha="$(get_branch_base_sha)" + if [[ "$branch_base_sha" != "" ]]; then + echo "Checking for changed packages from $branch_base_sha" + IFS=$'\n' packages=( $(git diff --name-only "$branch_base_sha" HEAD | grep -o "packages/[^/]*" | sed -e "s/packages\///g" | sort | uniq) ) + else + error "Cannot find a merge base for the current branch to run an incremental build..." + error "Please rebase your branch onto the latest master!" + return 1 + fi + + # Filter out any packages that don't have a pubspec.yaml: they have probably + # been deleted in this PR. Also filter out `location_background` since it + # should be removed soon. + CHANGED_PACKAGES="" + CHANGED_PACKAGE_LIST=() + for package in "${packages[@]}"; do + if [ -f "$REPO_DIR/packages/$package/pubspec.yaml" ] && [ $package != "location_background" ]; then + CHANGED_PACKAGES="${CHANGED_PACKAGES},$package" + CHANGED_PACKAGE_LIST=("${CHANGED_PACKAGE_LIST[@]}" "$package") + fi + done + + if [[ "${#CHANGED_PACKAGE_LIST[@]}" == 0 ]]; then + echo "No changes detected in packages." + else + echo "Detected changes in the following ${#CHANGED_PACKAGE_LIST[@]} package(s):" + for package in "${CHANGED_PACKAGE_LIST[@]}"; do + echo "$package" + done + echo "" + fi + return 0 +} \ No newline at end of file diff --git a/script/incremental_build.sh b/script/incremental_build.sh new file mode 100755 index 00000000..09be9bd1 --- /dev/null +++ b/script/incremental_build.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" +REPO_DIR="$(dirname "$SCRIPT_DIR")" + +source "$SCRIPT_DIR/common.sh" + +# Set some default actions if run without arguments. +ACTIONS=("$@") +if [[ "${#ACTIONS[@]}" == 0 ]]; then + ACTIONS=("test" "analyze" "java-test") +fi + +BRANCH_NAME="${BRANCH_NAME:-"$(git rev-parse --abbrev-ref HEAD)"}" +if [[ "${BRANCH_NAME}" == "master" ]]; then + echo "Running for all packages" + (cd "$REPO_DIR" && pub global run flutter_plugin_tools "${ACTIONS[@]}" $PLUGIN_SHARDING) +else + # Sets CHANGED_PACKAGES + check_changed_packages + + if [[ "$CHANGED_PACKAGES" == "" ]]; then + echo "No changes detected in packages." + else + (cd "$REPO_DIR" && pub global run flutter_plugin_tools "${ACTIONS[@]}" --plugins="$CHANGED_PACKAGES" $PLUGIN_SHARDING) + echo "Running version check for changed packages" + (cd "$REPO_DIR" && pub global run flutter_plugin_tools version-check --base_sha="$(get_branch_base_sha)") + fi +fi \ No newline at end of file