From b21079712b7eabed7441ec11661f5be02505c1cd Mon Sep 17 00:00:00 2001 From: Alex Deymo Date: Tue, 4 Oct 2016 23:09:45 -0700 Subject: Add README.version and update script. This patch adds an update_curl script that fetches a new curl version from upstream and applies the changes on top of our copy. Since we don't have a common history with upstream, the patches are simply squashed together for a single library update commmit. Bug: 31271247 Test: ./update_curl.sh [sha] Change-Id: I1e44ca8845c9f90df262a94ac2bbd36d3ddccb61 --- README.version | 10 ++++ update_curl.sh | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 README.version create mode 100755 update_curl.sh diff --git a/README.version b/README.version new file mode 100644 index 0000000..f5c6e2d --- /dev/null +++ b/README.version @@ -0,0 +1,10 @@ +URL: https://curl.haxx.se/download/curl-7.49.1.tar.gz +Version: 7.49.1 +Upstream commit: cf93a7b364a70b56150cf6ea77492b799ec02a45 +License: MIT +License File: NOTICE +BugComponent: 31714 +Owners: deymo, enh + +Description: +Curl is a command line tool for transferring data specified with URL syntax. diff --git a/update_curl.sh b/update_curl.sh new file mode 100755 index 0000000..b628bab --- /dev/null +++ b/update_curl.sh @@ -0,0 +1,174 @@ +#!/bin/bash +# +# Copyright (C) 2016 The Android Open-Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -e -u + +base_dir=$(realpath $(dirname $0)) +cd "${base_dir}" + +UPSTREAM_GIT="https://github.com/curl/curl" +UPSTREAM="github_curl" +README_FILE="README.version" + +TEMP_FILES=() +cleanup() { + trap - INT TERM ERR EXIT + if [[ ${#TEMP_FILES[@]} -ne 0 ]]; then + rm -f "${TEMP_FILES[@]}" + fi +} +trap cleanup INT TERM ERR EXIT + +# Prints the URL to the package for the passed version. +upstream_url() { + local version="$1" + echo "https://curl.haxx.se/download/curl-${version}.tar.gz" +} + +# Update the contents of the README.version with the new version string passed +# as the first parameter. +update_readme() { + local version="$1" + local sha="$2" + local tmp_readme=$(mktemp update_readme.XXXXXX) + TEMP_FILES+=("${tmp_readme}") + local url + url=$(upstream_url "${version}") + + cat >"${tmp_readme}" <>"${tmp_readme}" 2>/dev/null || true + cp "${tmp_readme}" "${README_FILE}" +} + + +# Print the current branch name. +git_current_branch() { + git rev-parse --abbrev-ref HEAD +} + +# Setup and fetch the upstream remote. While we have mirroring setup of the +# remote, we need to fetch all the tags from upstream to identify the latest +# release. +setup_git() { + local current_branch + current_branch=$(git_current_branch) + if [[ "${current_branch}" == "HEAD" ]]; then + echo "Not working on a branch, please run 'repo start [branch_name] .'" \ + " first." >&2 + exit 1 + fi + + # Setup and fetch the remote. + if ! git remote show | grep "^${UPSTREAM}\$" >/dev/null; then + echo "Adding remote ${UPSTREAM} to ${UPSTREAM_GIT}" + git remote add -t master "${UPSTREAM}" "${UPSTREAM_GIT}" + fi + + TRACKING_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) + OUR_REMOTE="${TRACKING_BRANCH%/*}" + + echo "Fetching latest upstream code..." + git fetch --quiet "${UPSTREAM}" master +} + + +main() { + setup_git + + # Load the current version's upstream hash. + local current_sha current_version + current_version=$(grep '^Version: ' "${README_FILE}" | cut -d ' ' -f 2-) + current_sha=$(grep '^Upstream commit: ' "${README_FILE}" | cut -d ' ' -f 3) + + if [[ -z "${current_sha}" ]]; then + echo "Couldn't determine the upstream commit the current code is at." \ + "Please update ${README_FILE} to include it." >&2 + exit 1 + fi + + local target_sha target_versio + target_sha="${1:-}" + if [[ -z "${target_sha}" ]]; then + cat >&2 <&2 + exit 1 + fi + + echo "Current version: ${current_version} / ${current_sha}" + echo "Target version: ${target_version} / ${target_sha}" + echo + + # Generate the log message. + local log_message=$(mktemp log_message.XXXXXX) + TEMP_FILES+=("${log_message}") + + (cat <"${log_message}" + + # Land the changes and commit. + update_readme "${target_version}" "${target_sha}" + git add "README.version" + + git cherry-pick --no-commit "${target_sha}" --not "${current_sha}" + git commit --file="${log_message}" + + cat <