Some minstr cleanup
[hiphop-php.git] / third-party / apply-quilt-patches.sh
blobdb4a475129fd1692a0681565beb5181e4d714f36
1 #!/bin/sh
3 # Copyright (c) 2015-present, Facebook, Inc.
4 # All rights reserved.
6 # This source code is licensed under the MIT license found in the
7 # LICENSE file in the root directory of this source tree.
10 # Applies a patch series maintained with the `quilt` tool
12 # The format is straightforward: if you have `foo.patch` and `bar.patch`,
13 # applied in that order, `patches/` contains:
15 # - bar.patch
16 # - foo.patch
17 # - series
19 # The 'series' file contains:
21 # ```
22 # foo.patch
23 # bar.patch
24 # ```
26 # Quilt uses the presence of a patches/ subdir to identify the root, similar
27 # to how Hack uses `.hhconfig` - so, to use quilt with an out-of-source patch
28 # dir is a little bit of work:
30 # ```
31 # $ cd ~/code/hhvm/build/third-party/fb-mysql/bundled_fbmysqlclient-prefix/src/bundled_fbmysqlclient/
32 # $ ln -s ~/code/hhvm/third-party/fb-mysql/patches
33 # $ export QUILT_PATCHES=$(pwd)/patches
34 # ```
36 # The essential commands are `quilt add`, `quilt refresh`, `quilt push`, and
37 # `quilt pop`.
39 QUILT_PATCHES="$1"
40 if [ ! -d "$QUILT_PATCHES" ]; then
41 echo "Usage: $0 /path/to/patches"
42 exit 1
45 set -e
47 if [ -n "$HHVM_TP_QUILT" ]; then
48 export QUILT_PATCHES
49 echo "$0: using quilt executable: $HHVM_TP_QUILT"
50 exec "${HHVM_TP_QUILT}" --quiltrc - push -a
53 echo "$0: applying patches in series, not using quilt."
55 cat "$QUILT_PATCHES/series" | while read PATCH_FILE; do
56 echo "Applying patch '$PATCH_FILE'..."
57 if [ -e ".quilt_$PATCH_FILE.stamp" ]; then
58 echo "...skipping, already applied."
59 elif patch -p1 --force < "$QUILT_PATCHES/$PATCH_FILE"; then
60 touch ".quilt_$PATCH_FILE.stamp"
61 echo "... applied patch $PATCH_FILE."
62 else
63 if patch -p1 --reverse --force --dry-run < "$QUILT_PATCHES/$PATCH_FILE"; then
64 echo "Failed to apply, appears to have been merged upstream."
65 else
66 echo "Failed to apply patch '$PATCH_FILE.'"
68 exit 1
70 done
71 echo "Applied all patches!"