xref: /freebsd/contrib/jemalloc/FREEBSD-upgrade (revision c99b67a7947ea215f9c1d44ec022680e98920cd1)
1#!/bin/sh
2# $FreeBSD$
3#
4# Usage: cd /usr/src/contrib/jemalloc
5#        ./FREEBSD-upgrade <command> [args]
6#
7# At least the following ports are required when importing jemalloc:
8# - devel/autoconf
9# - devel/git
10# - devel/gmake
11# - textproc/docbook-xsl
12# - textproc/libxslt
13#
14# The normal workflow for importing a new release is:
15#
16#   cd /usr/src/contrib/jemalloc
17#
18# Merge local changes that were made since the previous import:
19#
20#   ./FREEBSD-upgrade merge-changes
21#   ./FREEBSD-upgrade rediff
22#
23# Extract latest jemalloc release.
24#
25#   ./FREEBSD-upgrade extract <rev>
26#
27# Fix patch conflicts as necessary, then regenerate diffs to update line
28# offsets:
29#
30#   ./FREEBSD-upgrade rediff
31#   ./FREEBSD-upgrade extract <rev>
32#
33# Do multiple buildworld/installworld rounds.  If problems arise and patches
34# are needed, edit the code in ${work} as necessary, then:
35#
36#   ./FREEBSD-upgrade rediff
37#   ./FREEBSD-upgrade extract <rev>
38#
39# The rediff/extract order is important because rediff saves the local
40# changes, then extract blows away the work tree and re-creates it with the
41# diffs applied.
42#
43# Finally, to clean up:
44#
45#  ./FREEBSD-upgrade clean
46
47set -e
48set -x
49
50if [ ! -x "FREEBSD-upgrade" ] ; then
51  echo "Run from within src/contrib/jemalloc/" >&2
52  exit 1
53fi
54
55if [ "x${JEMALLOC_REPO}" = "x" ] ; then
56  JEMALLOC_REPO=https://github.com/jemalloc/jemalloc.git
57fi
58
59src=`pwd`
60
61jemalloc_tmp="jemalloc.tmp"
62tmpdir="${src}/../${jemalloc_tmp}"
63bare_repo="${tmpdir}/jemalloc_bare.git"
64work="jemalloc_work.git"
65work_repo="${tmpdir}/${work}"
66namespace_repo="${tmpdir}/jemalloc_namespace.git"
67changes="${src}/FREEBSD-changes"
68
69do_fetch() {
70  local rev=$1
71  if [ ! -d "${bare_repo}" ] ; then
72    mkdir -p "${bare_repo}"
73    git clone --bare ${JEMALLOC_REPO} ${bare_repo}
74  fi
75  (
76    cd ${bare_repo}
77    git fetch origin ${rev}
78  )
79}
80
81do_extract_helper() {
82  local rev=$1
83  local repo=$2
84  do_fetch ${rev}
85  rm -rf ${repo}
86  git clone ${bare_repo} ${repo}
87  (
88    cd ${repo}
89    if [ "x${rev}" != "x" ] ; then
90      # Use optional rev argument to check out a revision other than HEAD on
91      # master.
92      git checkout ${rev}
93    fi
94  )
95}
96
97do_autogen() {
98  ./autogen.sh --enable-xmalloc --enable-utrace \
99    --with-xslroot=/usr/local/share/xsl/docbook --with-private-namespace=__ \
100    --with-lg-page-sizes=12,13,14,16
101}
102
103do_extract_diff() {
104  local rev=$1
105  local repo=$2
106  do_extract_helper ${rev} ${repo}
107  (
108    cd ${repo}
109    # Apply diffs before generating files.
110    patch -p1 < "${src}/FREEBSD-diffs"
111    find . -name '*.orig' -delete
112    # Generate files.
113    do_autogen
114    gmake dist
115  )
116}
117
118do_extract_namespace() {
119  local rev=$1
120  local repo=$2
121  do_extract_helper ${rev} ${repo}
122  (
123    cd ${repo}
124    # Generate files.
125    do_autogen
126    gmake include/jemalloc/internal/private_namespace.h
127  )
128}
129
130do_extract() {
131  local rev=$1
132  do_fetch ${rev}
133  do_extract_diff ${rev} ${work_repo}
134  do_extract_namespace ${rev} ${namespace_repo}
135}
136
137do_diff() {
138  (
139    cd ${work_repo}
140    find . -name '*.orig' -delete
141    find . -name '*.rej' -delete
142    git add -A
143    git diff --cached
144  ) > FREEBSD-diffs
145}
146
147command=$1
148shift
149case "${command}" in
150  merge-changes) # Merge local changes that were made since the previous import.
151    rev=`cat VERSION |tr 'g' ' ' |awk '{print $2}'`
152    # Extract code corresponding to most recent import.
153    do_extract ${rev}
154    # Compute local differences to the upstream+patches and apply them.
155    (
156      cd ${tmpdir}
157      diff -ru -X ${src}/FREEBSD-Xlist ${work} ../jemalloc > ${changes} || true
158    )
159    (
160      cd ${work_repo}
161      patch -p1 < ${changes} || true
162      find . -name '*.orig' -delete
163    )
164    # Update diff.
165    do_diff
166    ;;
167  extract) # Extract upstream sources, apply patches, copy to contrib/jemalloc.
168    rev=$1
169    do_extract ${rev}
170    # Delete existing files so that cruft doesn't silently remain.
171    rm -rf ChangeLog COPYING VERSION doc include src
172    # Copy files over.
173    tar cf - -C ${work_repo} -X FREEBSD-Xlist . |tar xvf -
174    internal_dir="include/jemalloc/internal"
175    grep -v ' isthreaded ' \
176      "${namespace_repo}/${internal_dir}/private_namespace.h" \
177      > "${internal_dir}/private_namespace.h"
178    ;;
179  rediff) # Regenerate diffs based on working tree.
180    do_diff
181    ;;
182  clean) # Remove working tree and temporary files.
183    rm -rf ${tmpdir} ${changes}
184    ;;
185  *)
186    echo "Unsupported command: \"${command}\"" >&2
187    exit 1
188    ;;
189esac
190