Alex Kashchenko af80df1
#!/bin/bash
Alex Kashchenko af80df1
# Generates the 'source tarball' for JDK 8 projects.
Alex Kashchenko af80df1
#
Alex Kashchenko af80df1
# Example:
Alex Kashchenko af80df1
# When used from local repo set REPO_ROOT pointing to file:// with your repo
Alex Kashchenko af80df1
# If your local repo follows upstream forests conventions, it may be enough to set OPENJDK_URL
Alex Kashchenko af80df1
# If you want to use a local copy of patch PR3667, set the path to it in the PR3667 variable
Alex Kashchenko af80df1
#
Alex Kashchenko af80df1
# In any case you have to set PROJECT_NAME REPO_NAME and VERSION. eg:
Alex Kashchenko af80df1
# PROJECT_NAME=jdk8u   OR   aarch64-port 
Alex Kashchenko af80df1
# REPO_NAME=jdk8u60    OR   jdk8u60 
Alex Kashchenko af80df1
# VERSION=jdk8u60-b27  OR aarch64-jdk8u65-b17 OR for head, keyword 'tip' should do the job there
Alex Kashchenko af80df1
# 
Alex Kashchenko af80df1
# They are used to create correct name and are used in construction of sources url (unless REPO_ROOT is set)
Alex Kashchenko af80df1
Alex Kashchenko af80df1
# This script creates a single source tarball out of the repository
Alex Kashchenko af80df1
# based on the given tag and removes code not allowed in fedora/rhel. For
Alex Kashchenko af80df1
# consistency, the source tarball will always contain 'openjdk' as the top
Alex Kashchenko af80df1
# level folder, name is created, based on parameter
Alex Kashchenko af80df1
#
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ ! "x$PR3667" = "x" ] ; then
Alex Kashchenko af80df1
  if [ ! -f "$PR3667" ] ; then
Alex Kashchenko af80df1
    echo "You have specified PR3667 as $PR3667 but it does not exists. exiting"
Alex Kashchenko af80df1
    exit 1
Alex Kashchenko af80df1
  fi
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
set -e
Alex Kashchenko af80df1
Alex Kashchenko af80df1
OPENJDK_URL_DEFAULT=http://hg.openjdk.java.net
Alex Kashchenko af80df1
COMPRESSION_DEFAULT=xz
Alex Kashchenko af80df1
# jdk is last for its size
Alex Kashchenko af80df1
REPOS_DEFAULT="hotspot corba jaxws jaxp langtools nashorn jdk"
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ "x$1" = "xhelp" ] ; then
Alex Kashchenko af80df1
    echo -e "Behaviour may be specified by setting the following variables:\n"
Alex Kashchenko af80df1
    echo "VERSION - the version of the specified OpenJDK project"
Alex Kashchenko af80df1
    echo "PROJECT_NAME -- the name of the OpenJDK project being archived (optional; only needed by defaults)"
Alex Kashchenko af80df1
    echo "REPO_NAME - the name of the OpenJDK repository (optional; only needed by defaults)"
Alex Kashchenko af80df1
    echo "OPENJDK_URL - the URL to retrieve code from (optional; defaults to ${OPENJDK_URL_DEFAULT})"
Alex Kashchenko af80df1
    echo "COMPRESSION - the compression type to use (optional; defaults to ${COMPRESSION_DEFAULT})"
Alex Kashchenko af80df1
    echo "FILE_NAME_ROOT - name of the archive, minus extensions (optional; defaults to PROJECT_NAME-REPO_NAME-VERSION)"
Alex Kashchenko af80df1
    echo "REPO_ROOT - the location of the Mercurial repository to archive (optional; defaults to OPENJDK_URL/PROJECT_NAME/REPO_NAME)"
Alex Kashchenko af80df1
    echo "PR3667 - the path to the PR3667 patch to apply (optional; downloaded if unavailable)"
Alex Kashchenko af80df1
    echo "REPOS - specify the repositories to use (optional; defaults to ${REPOS_DEFAULT})"
Alex Kashchenko af80df1
    exit 1;
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ "x$VERSION" = "x" ] ; then
Alex Kashchenko af80df1
    echo "No VERSION specified"
Alex Kashchenko af80df1
    exit -2
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
echo "Version: ${VERSION}"
Alex Kashchenko af80df1
    
Alex Kashchenko af80df1
# REPO_NAME is only needed when we default on REPO_ROOT and FILE_NAME_ROOT
Alex Kashchenko af80df1
if [ "x$FILE_NAME_ROOT" = "x" -o "x$REPO_ROOT" = "x" ] ; then
Alex Kashchenko af80df1
    if [ "x$PROJECT_NAME" = "x" ] ; then
Alex Kashchenko af80df1
	echo "No PROJECT_NAME specified"
Alex Kashchenko af80df1
	exit -1
Alex Kashchenko af80df1
    fi
Alex Kashchenko af80df1
    echo "Project name: ${PROJECT_NAME}"
Alex Kashchenko af80df1
    if [ "x$REPO_NAME" = "x" ] ; then
Alex Kashchenko af80df1
	echo "No REPO_NAME specified"
Alex Kashchenko af80df1
	exit -3
Alex Kashchenko af80df1
    fi
Alex Kashchenko af80df1
    echo "Repository name: ${REPO_NAME}"
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ "x$OPENJDK_URL" = "x" ] ; then
Alex Kashchenko af80df1
    OPENJDK_URL=${OPENJDK_URL_DEFAULT}
Alex Kashchenko af80df1
    echo "No OpenJDK URL specified; defaulting to ${OPENJDK_URL}"
Alex Kashchenko af80df1
else
Alex Kashchenko af80df1
    echo "OpenJDK URL: ${OPENJDK_URL}"
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ "x$COMPRESSION" = "x" ] ; then
Alex Kashchenko af80df1
# rhel 5 needs tar.gz
Alex Kashchenko af80df1
    COMPRESSION=${COMPRESSION_DEFAULT}
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
echo "Creating a tar.${COMPRESSION} archive"
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ "x$FILE_NAME_ROOT" = "x" ] ; then
Alex Kashchenko af80df1
    FILE_NAME_ROOT=${PROJECT_NAME}-${REPO_NAME}-${VERSION}
Alex Kashchenko af80df1
    echo "No file name root specified; default to ${FILE_NAME_ROOT}"
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
if [ "x$REPO_ROOT" = "x" ] ; then
Alex Kashchenko af80df1
    REPO_ROOT="${OPENJDK_URL}/${PROJECT_NAME}/${REPO_NAME}"
Alex Kashchenko af80df1
    echo "No repository root specified; default to ${REPO_ROOT}"
Alex Kashchenko af80df1
fi;
Alex Kashchenko af80df1
Alex Kashchenko af80df1
mkdir "${FILE_NAME_ROOT}"
Alex Kashchenko af80df1
pushd "${FILE_NAME_ROOT}"
Alex Kashchenko af80df1
Alex Kashchenko af80df1
echo "Cloning ${VERSION} root repository from ${REPO_ROOT}"
Alex Kashchenko af80df1
hg clone ${REPO_ROOT} openjdk -r ${VERSION}
Alex Kashchenko af80df1
pushd openjdk
Alex Kashchenko af80df1
	
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ "x$REPOS" = "x" ] ; then
Alex Kashchenko af80df1
    repos=${REPOS_DEFAULT}
Alex Kashchenko af80df1
    echo "No repositories specified; defaulting to ${repos}"
Alex Kashchenko af80df1
else
Alex Kashchenko af80df1
    repos=$REPOS
Alex Kashchenko af80df1
    echo "Repositories: ${repos}"
Alex Kashchenko af80df1
fi;
Alex Kashchenko af80df1
Alex Kashchenko af80df1
for subrepo in $repos
Alex Kashchenko af80df1
do
Alex Kashchenko af80df1
    echo "Cloning ${VERSION} ${subrepo} repository from ${REPO_ROOT}"
Alex Kashchenko af80df1
    hg clone ${REPO_ROOT}/${subrepo} -r ${VERSION}
Alex Kashchenko af80df1
done
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ -d jdk ]; then 
Alex Kashchenko af80df1
echo "Removing EC source code we don't build"
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ec2.h
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ec2_163.c
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ec2_193.c
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ec2_233.c
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ec2_aff.c
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ec2_mont.c
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ecp_192.c
Alex Kashchenko af80df1
rm -vf jdk/src/share/native/sun/security/ec/impl/ecp_224.c
Alex Kashchenko af80df1
Alex Kashchenko af80df1
echo "Syncing EC list with NSS"
Alex Kashchenko af80df1
Alex Kashchenko af80df1
if [ "x$PR3667" = "x" ] ; then
Alex Kashchenko af80df1
# get pr3667.patch (from http://icedtea.classpath.org/hg/icedtea8) from most correct tag
Alex Kashchenko af80df1
# Do not push it or publish it (see http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=3667)
Alex Kashchenko af80df1
    wget http://icedtea.classpath.org/hg/icedtea8/raw-file/tip/patches/pr3667.patch
Alex Kashchenko af80df1
    patch -Np1 < pr3667.patch
Alex Kashchenko af80df1
    rm pr3667.patch
Alex Kashchenko af80df1
else
Alex Kashchenko af80df1
    echo "Applying ${PR3667}"
Alex Kashchenko af80df1
    patch -Np1 < $PR3667
Alex Kashchenko af80df1
fi;
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
find . -name '*.orig' -exec rm -vf '{}' ';'
Alex Kashchenko af80df1
Alex Kashchenko af80df1
popd
Alex Kashchenko af80df1
echo "Compressing remaining forest"
Alex Kashchenko af80df1
if [ "X$COMPRESSION" = "Xxz" ] ; then
Alex Kashchenko af80df1
    tar --exclude-vcs -cJf ${FILE_NAME_ROOT}.tar.${COMPRESSION} openjdk
Alex Kashchenko af80df1
else
Alex Kashchenko af80df1
    tar --exclude-vcs -czf ${FILE_NAME_ROOT}.tar.${COMPRESSION} openjdk
Alex Kashchenko af80df1
fi
Alex Kashchenko af80df1
Alex Kashchenko af80df1
mv ${FILE_NAME_ROOT}.tar.${COMPRESSION}  ..
Alex Kashchenko af80df1
popd
Alex Kashchenko af80df1
echo "Done. You may want to remove the uncompressed version."
Alex Kashchenko af80df1
Alex Kashchenko af80df1