xref: /aosp_15_r20/external/libaom/update_libaom.sh (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1#!/bin/bash -e
2#
3# Copyright (c) 2012 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This tool is used to update libaom source code to a revision of the upstream
8# repository. Modified from Chromium src/third_party/libvpx/update_libvpx.sh
9
10# Usage:
11#
12# $ ./update_libaom.sh [branch | revision | file or url containing a revision]
13# When specifying a branch it may be necessary to prefix with origin/
14
15# Tools required for running this tool:
16#
17# 1. Linux / Mac
18# 2. git
19
20export LC_ALL=C
21
22die() {
23  echo "$@"
24  exit 1
25}
26
27cleanup() {
28  git remote remove $REMOTE 2>/dev/null
29}
30
31# Location for the remote git repository.
32GIT_REPO="https://aomedia.googlesource.com/aom"
33
34# Update to TOT by default.
35GIT_BRANCH="main"
36
37BASE_DIR=`pwd`
38
39if [ -n "$1" ]; then
40  GIT_BRANCH="$1"
41  if [ -f "$1"  ]; then
42    GIT_BRANCH=$(<"$1")
43  elif [[ $1 = http* ]]; then
44    GIT_BRANCH=`curl $1`
45  fi
46fi
47
48prev_hash="$(egrep "^Commit: [[:alnum:]]" README.android | awk '{ print $2 }')"
49echo "prev_hash:$prev_hash"
50
51REMOTE="update_upstream"
52
53trap cleanup EXIT
54
55# Add a remote for upstream git repository
56git remote add $REMOTE $GIT_REPO
57
58# Fetch remote's GIT_BRANCH
59git fetch $REMOTE $GIT_BRANCH --tags
60
61# Get commit id corresponding to branch/revision in upstream repository
62REMOTE_BRANCHES="$(git remote show $REMOTE)"
63
64if [[ "$REMOTE_BRANCHES" == *"$GIT_BRANCH"* ]]; then
65  UPSTREAM_COMMIT=$(git rev-list -n 1 $REMOTE/$GIT_BRANCH)
66else
67  UPSTREAM_COMMIT=$(git rev-list -n 1 $GIT_BRANCH)
68fi
69
70[ -z "$UPSTREAM_COMMIT" ] \
71  && die "Unable to get upstream commit corresponding to ${GIT_BRANCH}";
72
73# Defer the commit until after updating METADATA & README.android.
74git merge --no-commit $UPSTREAM_COMMIT
75
76# Get the current commit hash.
77hash=$(git log $UPSTREAM_COMMIT -1 --format="%H")
78
79# Update date and commit info in METADATA & README.android.
80sed -E -i'' \
81  -e "s/^([[:space:]]+year:).*/\1 $(date +'%Y')/" \
82  -e "s/^([[:space:]]+month:).*/\1 $(date +'%-m')/" \
83  -e "s/^([[:space:]]+day:).*/\1 $(date +'%-d')/" \
84  METADATA
85sed -E -i'' \
86  -e "s/^(Date:).*/\1 $(date +'%A %B %d %Y')/" \
87  -e "s/^(Branch:).*/\1 $GIT_BRANCH/" \
88  -e "s/^(Commit:).*/\1 $hash/" \
89  README.android
90
91git commit -a -v
92
93echo "Update the version field in README.android and METADATA."
94
95chmod 755 build/cmake/*.pl
96