| #!/bin/bash | |
| # Copyright 2017 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| ### build target/all then sync artifacts to device | |
| ## usage: fx build-sync [target, ...] | |
| set -e | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh | |
| fx-config-read | |
| function __fbuild_make_batch { | |
| # parse a bootfs manifest, compare inputs to a stamp file and append | |
| # sftp commands to a batch file to update changed files. | |
| local manifest stamp_file batch_file userfs_path build_path | |
| manifest=$1 | |
| stamp_file=$2 | |
| batch_file=$3 | |
| while IFS=\= read userfs_path build_path; do | |
| if [[ -z "${build_path}" ]]; then | |
| continue | |
| fi | |
| if [[ $build_path -nt $stamp_file ]]; then | |
| local device_path=/system/${userfs_path} | |
| echo "Updating ${device_path} with ${build_path}" | |
| echo "-rm ${device_path}" >> "$batch_file" | |
| echo "put ${build_path} ${device_path}" >> "$batch_file" | |
| fi | |
| done < "$manifest" | |
| } | |
| function main { | |
| local stamp_file status_file batch_file package host | |
| stamp_file="${FUCHSIA_BUILD_DIR}/.fbuild-sync-stamp" | |
| status_file="${FUCHSIA_BUILD_DIR}/.fbuild-sync-status" | |
| batch_file="${FUCHSIA_BUILD_DIR}/.fbuild-sync-batchfile" | |
| touch "${status_file}" | |
| if [[ "$(cat "${status_file}")" != "failed" ]]; then | |
| touch "${stamp_file}" | |
| fi | |
| fx-command-run build "$@" | |
| if [[ $? -ne 0 ]]; then | |
| echo "failed" > "${status_file}" | |
| return 1 | |
| fi | |
| echo -n > "${batch_file}" | |
| __fbuild_make_batch \ | |
| "${FUCHSIA_BUILD_DIR}/gen/build/gn/system.bootfs.manifest" \ | |
| "${stamp_file}" "${batch_file}" | |
| while read package; do | |
| __fbuild_make_batch \ | |
| "${FUCHSIA_BUILD_DIR}/package/${package}/system_manifest" \ | |
| "${stamp_file}" "${batch_file}" | |
| done < ${FUCHSIA_BUILD_DIR}/gen/build/gn/packages | |
| echo "Syncing changed system.bootfs files..." | |
| host="$(fx-command-run netaddr --fuchsia)" | |
| fx-command-run sftp -q -b "${batch_file}" "[${host}]" > /dev/null | |
| if [ $? -ne 0 ]; then | |
| echo "failed" > "${status_file}" | |
| return 1 | |
| fi | |
| rm -f "${stamp_file}" | |
| rm -f "${status_file}" | |
| rm -f "${batch_file}" | |
| } | |
| main "$@" |