macos_assemble.sh 3.26 KB
Newer Older
1
#!/usr/bin/env bash
Ian Hickson's avatar
Ian Hickson committed
2
# Copyright 2014 The Flutter Authors. All rights reserved.
3 4 5
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

6
# TODO(jonahwilliams): refactor this and xcode_backend.sh into one script
7
# once iOS is using 'assemble'.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
RunCommand() {
  if [[ -n "$VERBOSE_SCRIPT_LOGGING" ]]; then
    echo "♦ $*"
  fi
  "$@"
  return $?
}

EchoError() {
  echo "$@" 1>&2
}

# Set the working directory to the project root
project_path="${SOURCE_ROOT}/.."
RunCommand pushd "${project_path}" > /dev/null

# Set the verbose flag.
verbose_flag=""
if [[ -n "$VERBOSE_SCRIPT_LOGGING" ]]; then
    verbose_flag="--verbose"
fi

# Set the target file.
target_path="lib/main.dart"
if [[ -n "$FLUTTER_TARGET" ]]; then
    target_path="${FLUTTER_TARGET}"
fi

36 37 38 39
if [[ -n "$FLUTTER_ENGINE" ]]; then
  flutter_engine_flag="--local-engine-src-path=${FLUTTER_ENGINE}"
fi

40 41 42
# Set the build mode
build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")"

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
if [[ -n "$LOCAL_ENGINE" ]]; then
  if [[ $(echo "$LOCAL_ENGINE" | tr "[:upper:]" "[:lower:]") != *"$build_mode"* ]]; then
    EchoError "========================================================================"
    EchoError "ERROR: Requested build with Flutter local engine at '${LOCAL_ENGINE}'"
    EchoError "This engine is not compatible with FLUTTER_BUILD_MODE: '${build_mode}'."
    EchoError "You can fix this by updating the LOCAL_ENGINE environment variable, or"
    EchoError "by running:"
    EchoError "  flutter build macos --local-engine=host_${build_mode}"
    EchoError "or"
    EchoError "  flutter build macos --local-engine=host_${build_mode}_unopt"
    EchoError "========================================================================"
    exit -1
  fi
  local_engine_flag="--local-engine=${LOCAL_ENGINE}"
fi

59 60 61 62 63 64
# The path where the input/output xcfilelists are stored. These are used by xcode
# to conditionally skip this script phase if neither have changed.
ephemeral_dir="${SOURCE_ROOT}/Flutter/ephemeral"
build_inputs_path="${ephemeral_dir}/FlutterInputs.xcfilelist"
build_outputs_path="${ephemeral_dir}/FlutterOutputs.xcfilelist"

65 66 67 68 69
icon_tree_shaker_flag="false"
if [[ -n "$TREE_SHAKE_ICONS" ]]; then
  icon_tree_shaker_flag="true"
fi

70 71
RunCommand "${FLUTTER_ROOT}/bin/flutter" --suppress-analytics               \
    ${verbose_flag}                                                         \
72
    ${flutter_engine_flag}                                                  \
73 74 75 76
    ${local_engine_flag}                                                    \
    assemble                                                                \
    -dTargetPlatform=darwin-x64                                             \
    -dTargetFile="${target_path}"                                           \
77
    -dBuildMode="${build_mode}"                                             \
78 79
    -dTreeShakeIcons="${icon_tree_shaker_flag}"                             \
    -dSplitDebugInfo="${SPLIT_DEBUG_INFO}"                                  \
80 81
    --build-inputs="${build_inputs_path}"                                   \
    --build-outputs="${build_outputs_path}"                                 \
82
    --output="${ephemeral_dir}"                                             \
83
   "${build_mode}_macos_bundle_flutter_assets"