blob: b2bf658e6da143c6273b3fdadb8b38f83de7a2f0 [file] [log] [blame]
#!/bin/sh
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
RunCommand() {
$@ >/dev/null
return $?
}
EchoError() {
echo "$@" 1>&2
}
AssertExists() {
RunCommand ls $1
if [ $? -ne 0 ]; then
EchoError "The path $1 does not exist"
exit -1
fi
return 0
}
PackageProject() {
# Check that the project path was specified
if [[ -z "$1" ]]; then
EchoError "Project path not specified"
exit -1
fi
# Check if pub exists
RunCommand which pub
if [[ $? -ne 0 ]]; then
EchoError "Could not find 'pub'."
EchoError "Did you install the Dart SDK?"
exit -1
fi
local pub_path="$(which pub)"
AssertExists $1
local project_path=$1
local derived_dir=${SOURCE_ROOT}/FlutterApplication/Generated
RunCommand mkdir -p $derived_dir
AssertExists $derived_dir
local dart_main=${project_path}/lib/main.dart
AssertExists $dart_main
local package_root=${project_path}/packages
AssertExists $package_root
local icons_path=${project_path}/packages/material_design_icons/icons
AssertExists $icons_path
# Remove old build artifacts
RunCommand rm -f ${derived_dir}/app.flx
# Generate the new FLX file. The pub command must be run from the directory
# containing the pubspec
RunCommand pushd ${project_path}
RunCommand ${pub_path} run sky_tools build \
--asset-base ${icons_path} \
--main ${dart_main} \
--output-file ${derived_dir}/app.flx \
--package-root ${package_root} \
--precompiled
if [[ $? -ne 0 ]]; then
EchoError "Failed to package $1 ..."
exit -1
fi
RunCommand popd
echo "Project $1 successfully packaged..."
return 0
}
PackageProject $1