github.com/golang/gofrontend@v0.0.0-20240429183944-60f985a78526/libgo/merge.sh (about)

     1  #!/bin/sh
     2  
     3  # Copyright 2009 The Go Authors. All rights reserved.
     4  # Use of this source code is governed by a BSD-style
     5  # license that can be found in the LICENSE file.
     6  
     7  # This script merges changes from the master copy of the Go library
     8  # into the libgo library.  This does the easy stuff; the hard stuff is
     9  # left to the user.
    10  
    11  # The file MERGE should hold the Git revision number of the last
    12  # revision which was merged into these sources.  Given that, and given
    13  # the current sources, we can run the usual diff3 algorithm to merge
    14  # all changes into our sources.
    15  
    16  set -e
    17  
    18  TMPDIR=${TMPDIR:-/tmp}
    19  
    20  OLDDIR=${TMPDIR}/libgo-merge-old
    21  NEWDIR=${TMPDIR}/libgo-merge-new
    22  
    23  if ! test -f MERGE; then
    24    echo 1>&2 "merge.sh: must be run in libgo source directory"
    25    exit 1
    26  fi
    27  
    28  rev=weekly
    29  case $# in
    30  1) ;;
    31  2) rev=$2 ;;
    32  *)
    33    echo 1>&2 "merge.sh: Usage: merge.sh git-repository [revision]"
    34    exit 1
    35    ;;
    36  esac
    37  
    38  repository=$1
    39  
    40  old_rev=`sed 1q MERGE`
    41  
    42  rm -rf ${OLDDIR}
    43  git clone ${repository} ${OLDDIR}
    44  (cd ${OLDDIR} && git checkout ${old_rev})
    45  
    46  rm -rf ${NEWDIR}
    47  git clone ${repository} ${NEWDIR}
    48  (cd ${NEWDIR} && git checkout ${rev})
    49  
    50  new_rev=`cd ${NEWDIR} && git log | sed 1q | sed -e 's/commit //'`
    51  
    52  merge() {
    53    name=$1
    54    old=$2
    55    new=$3
    56    libgo=$4
    57    if test -d ${new}; then
    58      if ! test -d ${old}; then
    59        if test -f ${old}; then
    60  	echo 1>&2 "merge.sh: ${name}: FILE BECAME DIRECTORY"
    61        fi
    62      fi
    63    elif ! test -f ${new}; then
    64      # The file does not exist in the new version.
    65      if ! test -f ${old}; then
    66        echo 1>&2 "merge.sh internal error no files $old $new"
    67        exit 1
    68      fi
    69      if ! test -f ${libgo}; then
    70        # File removed in new version and libgo.
    71        :;
    72      else
    73        echo "merge.sh: ${name}: REMOVED"
    74        rm -f ${libgo}
    75      fi
    76    elif test -f ${old}; then
    77      # The file exists in the old version.
    78      if ! test -f ${libgo}; then
    79        if ! cmp -s ${old} ${new}; then
    80          echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
    81        fi
    82        return
    83      fi
    84      if cmp -s ${old} ${libgo}; then
    85        # The libgo file is unchanged from the old version.
    86        if cmp -s ${new} ${libgo}; then
    87          # File is unchanged from old to new version.
    88  	return
    89        fi
    90        # Update file in libgo.
    91        echo "merge.sh: $name: updating"
    92        cp ${new} ${libgo}
    93      else
    94        # The libgo file has local changes.
    95        set +e
    96        diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
    97        status=$?
    98        set -e
    99        case $status in
   100        0)
   101          echo "merge.sh: $name: updating"
   102          mv ${libgo}.tmp ${libgo}
   103          ;;
   104        1)
   105          echo "merge.sh: $name: CONFLICTS"
   106          mv ${libgo}.tmp ${libgo}
   107          ;;
   108        *)
   109          echo 1>&2 "merge.sh: $name: DIFF3 FAILURE"
   110          ;;
   111        esac
   112      fi
   113    else
   114      # The file does not exist in the old version.
   115      if test -f ${libgo}; then
   116        if ! cmp -s ${new} ${libgo}; then
   117          echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
   118        fi
   119      else
   120        echo "merge.sh: $name: NEW"
   121        dir=`dirname ${libgo}`
   122        if ! test -d ${dir}; then
   123          mkdir -p ${dir}
   124        fi
   125        cp ${new} ${libgo}
   126      fi
   127    fi
   128  }
   129  
   130  echo ${rev} > VERSION
   131  
   132  (cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do
   133    skip=false
   134    case "$f" in
   135    ./cmd/buildid/* | ./cmd/cgo/* | ./cmd/go/* | ./cmd/gofmt/* | ./cmd/test2json/* | ./cmd/vet/* | ./cmd/internal/browser/* | ./cmd/internal/buildid/* | ./cmd/internal/codesign/* | ./cmd/internal/edit/* | ./cmd/internal/objabi/* | ./cmd/internal/quoted/* | ./cmd/internal/test2json/* | ./cmd/internal/sys/* | ./cmd/internal/traceviewer/* | ./cmd/vendor/golang.org/x/tools/* | ./cmd/vendor/golang.org/x/mod/* | ./cmd/vendor/golang.org/x/xerrors/* | ./cmd/vendor/golang.org/x/crypto/ed25519 | ./cmd/vendor/golang.org/x/sync/semaphore)
   136      ;;
   137    ./cmd/*)
   138      skip=true
   139      ;;
   140    ./runtime/race/*)
   141      skip=true
   142      ;;
   143    esac
   144    if test "$skip" = "true"; then
   145      continue
   146    fi
   147  
   148    oldfile=${OLDDIR}/src/$f
   149    newfile=${NEWDIR}/src/$f
   150    libgofile=go/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
   151    merge $f ${oldfile} ${newfile} ${libgofile}
   152  done
   153  
   154  (cd ${NEWDIR}/src && find . -name 'go.mod' -print) | while read f; do
   155    oldfile=${OLDDIR}/src/$f
   156    newfile=${NEWDIR}/src/$f
   157    libgofile=go/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
   158    merge $f ${oldfile} ${newfile} ${libgofile}
   159  done
   160  
   161  (cd ${NEWDIR}/src && find . -name 'modules.txt' -print) | while read f; do
   162    oldfile=${OLDDIR}/src/$f
   163    newfile=${NEWDIR}/src/$f
   164    libgofile=go/$f
   165    merge $f ${oldfile} ${newfile} ${libgofile}
   166  done
   167  
   168  (cd ${NEWDIR}/src && find . -name testdata -print) | while read d; do
   169    skip=false
   170    case "$d" in
   171    ./cmd/buildid/* | ./cmd/cgo/* | ./cmd/go/* | ./cmd/gofmt/* | ./cmd/test2json/* | ./cmd/vet/* | ./cmd/internal/browser/* | ./cmd/internal/buildid/* | ./cmd/internal/codesign/* | ./cmd/internal/diff/* | ./cmd/internal/edit/* | ./cmd/internal/objabi/* | ./cmd/internal/test2json/* | ./cmd/internal/sys/* | ./cmd/internal/traceviewer/* | ./cmd/vendor/golang.org/x/tools/*)
   172      ;;
   173    ./cmd/*)
   174      skip=true
   175      ;;
   176    ./runtime/race/* | ./runtime/cgo/*)
   177      skip=true
   178      ;;
   179    esac
   180    if test "$skip" = "true"; then
   181      continue
   182    fi
   183  
   184    oldtd=${OLDDIR}/src/$d
   185    newtd=${NEWDIR}/src/$d
   186    libgotd=go/`echo $d | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
   187    if ! test -d ${oldtd}; then
   188      echo "merge.sh: $d: NEWDIR"
   189      continue
   190    fi
   191    (cd ${oldtd} && git ls-files .) | while read f; do
   192      if test "`basename -- $f`" = ".gitignore"; then
   193        continue
   194      fi
   195      name=$d/$f
   196      oldfile=${oldtd}/$f
   197      newfile=${newtd}/$f
   198      libgofile=${libgotd}/$f
   199      merge ${name} ${oldfile} ${newfile} ${libgofile}
   200    done
   201    (cd ${newtd} && git ls-files .) | while read f; do
   202      if test "`basename -- $f`" = ".gitignore"; then
   203        continue
   204      fi
   205      oldfile=${oldtd}/$f
   206      if ! test -f ${oldfile}; then
   207        name=$d/$f
   208        newfile=${newtd}/$f
   209        libgofile=${libgotd}/$f
   210        merge ${name} ${oldfile} ${newfile} ${libgofile}
   211      fi
   212    done
   213  done
   214  
   215  (cd ${NEWDIR}/misc/cgo && find . -type f -print) | while read f; do
   216    oldfile=${OLDDIR}/misc/cgo/$f
   217    newfile=${NEWDIR}/misc/cgo/$f
   218    libgofile=misc/cgo/$f
   219    merge $f ${oldfile} ${newfile} ${libgofile}
   220  done
   221  
   222  (cd ${OLDDIR}/src && find . -name '*.go' -print) | while read f; do
   223    oldfile=${OLDDIR}/src/$f
   224    newfile=${NEWDIR}/src/$f
   225    libgofile=go/$f
   226    if test -f ${newfile}; then
   227      continue
   228    fi
   229    if ! test -f ${libgofile}; then
   230      continue
   231    fi
   232    echo "merge.sh: ${libgofile}: REMOVED"
   233    rm -f ${libgofile}
   234  done
   235  
   236  (cd ${OLDDIR}/misc/cgo && find . -type f -print) | while read f; do
   237    oldfile=${OLDDIR}/misc/cgo/$f
   238    newfile=${NEWDIR}/misc/cgo/$f
   239    libgofile=misc/cgo/$f
   240    if test -f ${newfile}; then
   241      continue
   242    fi
   243    if ! test -f ${libgofile}; then
   244      continue
   245    fi
   246    echo "merge.sh: ${libgofile}: REMOVED"
   247    rm -f ${libgofile}
   248  done
   249  
   250  (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp
   251  mv MERGE.tmp MERGE