691f5d1
#!/bin/bash
691f5d1
# Generates the 'source tarball' for JDK projects.
691f5d1
#
691f5d1
# Example:
691f5d1
# When used from local repo set REPO_ROOT pointing to file:// with your repo
691f5d1
# if your local repo follows upstream forests conventions, you may be enough by setting OPENJDK_URL
691f5d1
# if you wont to use local copy of patch PR2126 set path to it to PR2126 variable
691f5d1
#
691f5d1
# In any case you have to set PROJECT_NAME REPO_NAME and VERSION. eg:
691f5d1
# PROJECT_NAME=jdk
691f5d1
# REPO_NAME=jdk
691f5d1
# VERSION=tip
691f5d1
# or to eg prepare systemtap:
691f5d1
# icedtea7's jstack and other tapsets
691f5d1
# VERSION=6327cf1cea9e
691f5d1
# REPO_NAME=icedtea7-2.6
691f5d1
# PROJECT_NAME=release
691f5d1
# OPENJDK_URL=http://icedtea.classpath.org/hg/
691f5d1
# TO_COMPRESS="*/tapset"
691f5d1
# 
691f5d1
# They are used to create correct name and are used in construction of sources url (unless REPO_ROOT is set)
691f5d1
691f5d1
# This script creates a single source tarball out of the repository
691f5d1
# based on the given tag and removes code not allowed in fedora/rhel. For
691f5d1
# consistency, the source tarball will always contain 'openjdk' as the top
691f5d1
# level folder, name is created, based on parameter
691f5d1
#
691f5d1
691f5d1
if [ ! "x$PR2126" = "x" ] ; then
691f5d1
  if [ ! -f "$PR2126" ] ; then
691f5d1
    echo "You have specified PR2126 as $PR2126 but it does not exists. exiting"
691f5d1
    exit 1
691f5d1
  fi
691f5d1
fi
691f5d1
691f5d1
set -e
691f5d1
691f5d1
OPENJDK_URL_DEFAULT=http://hg.openjdk.java.net
691f5d1
COMPRESSION_DEFAULT=xz
691f5d1
691f5d1
if [ "x$1" = "xhelp" ] ; then
691f5d1
    echo -e "Behaviour may be specified by setting the following variables:\n"
691f5d1
    echo "VERSION - the version of the specified OpenJDK project"
691f5d1
    echo "PROJECT_NAME -- the name of the OpenJDK project being archived (optional; only needed by defaults)"
691f5d1
    echo "REPO_NAME - the name of the OpenJDK repository (optional; only needed by defaults)"
691f5d1
    echo "OPENJDK_URL - the URL to retrieve code from (optional; defaults to ${OPENJDK_URL_DEFAULT})"
691f5d1
    echo "COMPRESSION - the compression type to use (optional; defaults to ${COMPRESSION_DEFAULT})"
691f5d1
    echo "FILE_NAME_ROOT - name of the archive, minus extensions (optional; defaults to PROJECT_NAME-REPO_NAME-VERSION)"
691f5d1
    echo "REPO_ROOT - the location of the Mercurial repository to archive (optional; defaults to OPENJDK_URL/PROJECT_NAME/REPO_NAME)"
691f5d1
    echo "TO_COMPRESS - what part of clone to pack (default is openjdk)"
691f5d1
    echo "PR2126 - the path to the PR2126 patch to apply (optional; downloaded if unavailable)"
691f5d1
    exit 1;
691f5d1
fi
691f5d1
691f5d1
691f5d1
if [ "x$VERSION" = "x" ] ; then
691f5d1
    echo "No VERSION specified"
691f5d1
    exit -2
691f5d1
fi
691f5d1
echo "Version: ${VERSION}"
691f5d1
    
691f5d1
# REPO_NAME is only needed when we default on REPO_ROOT and FILE_NAME_ROOT
691f5d1
if [ "x$FILE_NAME_ROOT" = "x" -o "x$REPO_ROOT" = "x" ] ; then
691f5d1
  if [ "x$PROJECT_NAME" = "x" ] ; then
691f5d1
    echo "No PROJECT_NAME specified"
691f5d1
    exit -1
691f5d1
  fi
691f5d1
  echo "Project name: ${PROJECT_NAME}"
691f5d1
  if [ "x$REPO_NAME" = "x" ] ; then
691f5d1
    echo "No REPO_NAME specified"
691f5d1
    exit -3
691f5d1
  fi
691f5d1
  echo "Repository name: ${REPO_NAME}"
691f5d1
fi
691f5d1
691f5d1
if [ "x$OPENJDK_URL" = "x" ] ; then
691f5d1
    OPENJDK_URL=${OPENJDK_URL_DEFAULT}
691f5d1
    echo "No OpenJDK URL specified; defaulting to ${OPENJDK_URL}"
691f5d1
else
691f5d1
    echo "OpenJDK URL: ${OPENJDK_URL}"
691f5d1
fi
691f5d1
691f5d1
if [ "x$COMPRESSION" = "x" ] ; then
691f5d1
    # rhel 5 needs tar.gz
691f5d1
    COMPRESSION=${COMPRESSION_DEFAULT}
691f5d1
fi
691f5d1
echo "Creating a tar.${COMPRESSION} archive"
691f5d1
691f5d1
if [ "x$FILE_NAME_ROOT" = "x" ] ; then
691f5d1
    FILE_NAME_ROOT=${PROJECT_NAME}-${REPO_NAME}-${VERSION}
691f5d1
    echo "No file name root specified; default to ${FILE_NAME_ROOT}"
691f5d1
fi
691f5d1
if [ "x$REPO_ROOT" = "x" ] ; then
691f5d1
    REPO_ROOT="${OPENJDK_URL}/${PROJECT_NAME}/${REPO_NAME}"
691f5d1
    echo "No repository root specified; default to ${REPO_ROOT}"
691f5d1
fi;
691f5d1
691f5d1
if [ "x$TO_COMPRESS" = "x" ] ; then
691f5d1
    TO_COMPRESS="openjdk"
691f5d1
    echo "No to be compressed targets specified, ; default to ${TO_COMPRESS}"
691f5d1
fi;
691f5d1
691f5d1
if [ -d ${FILE_NAME_ROOT} ] ; then
691f5d1
  echo "exists exists exists exists exists exists exists "
691f5d1
  echo "reusing reusing reusing reusing reusing reusing "
691f5d1
  echo ${FILE_NAME_ROOT}
691f5d1
else
691f5d1
  mkdir "${FILE_NAME_ROOT}"
691f5d1
  pushd "${FILE_NAME_ROOT}"
691f5d1
    echo "Cloning ${VERSION} root repository from ${REPO_ROOT}"
691f5d1
    hg clone ${REPO_ROOT} openjdk -r ${VERSION}
691f5d1
  popd
691f5d1
fi
691f5d1
pushd "${FILE_NAME_ROOT}"
691f5d1
    if [ -d openjdk/src ]; then 
691f5d1
        pushd openjdk
691f5d1
            echo "Removing EC source code we don't build"
691f5d1
            CRYPTO_PATH=src/jdk.crypto.ec/share/native/libsunec/impl
691f5d1
            rm -vrf $CRYPTO_PATH
691f5d1
            echo "Syncing EC list with NSS"
691f5d1
            if [ "x$PR2126" = "x" ] ; then
691f5d1
                # orriginally for 8:
691f5d1
                # get pr2126.patch (from http://icedtea.classpath.org/hg/icedtea?cmd=changeset;node=8d2c9a898f50) from most correct tag
691f5d1
                # Do not push it or publish it (see http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=2126)
691f5d1
                # there is currnetly no "upstram version of this patch, hardcoding custom version
691f5d1
                PR2126="../../pr2126-11.patch"
691f5d1
            fi;
691f5d1
            echo "Applying ${PR2126}"
691f5d1
            patch -Np1 < $PR2126
691f5d1
            find . -name '*.orig' -exec rm -vf '{}' ';'
691f5d1
        popd
691f5d1
    fi
691f5d1
691f5d1
    echo "Compressing remaining forest"
691f5d1
    if [ "X$COMPRESSION" = "Xxz" ] ; then
691f5d1
        SWITCH=cJf
691f5d1
    else
691f5d1
        SWITCH=czf
691f5d1
    fi
691f5d1
    tar --exclude-vcs -$SWITCH ${FILE_NAME_ROOT}.tar.${COMPRESSION} $TO_COMPRESS
691f5d1
    mv ${FILE_NAME_ROOT}.tar.${COMPRESSION}  ..
691f5d1
popd
691f5d1
echo "Done. You may want to remove the uncompressed version - $FILE_NAME_ROOT."
691f5d1
691f5d1