1#!/bin/bash 2# 3# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. 4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5# 6# This code is free software; you can redistribute it and/or modify it 7# under the terms of the GNU General Public License version 2 only, as 8# published by the Free Software Foundation. Oracle designates this 9# particular file as subject to the "Classpath" exception as provided 10# by Oracle in the LICENSE file that accompanied this code. 11# 12# This code is distributed in the hope that it will be useful, but WITHOUT 13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15# version 2 for more details (a copy is included in the LICENSE file that 16# accompanied this code). 17# 18# You should have received a copy of the GNU General Public License version 19# 2 along with this work; if not, write to the Free Software Foundation, 20# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21# 22# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23# or visit www.oracle.com if you need additional information or have any 24# questions. 25# 26 27# This script copies parts of an Xcode installation into a devkit suitable 28# for building OpenJDK and OracleJDK. The installation Xcode_X.X.xip needs 29# to be either installed or extracted using for example Archive Utility. 30# The easiest way to accomplish this is to right click the file in Finder 31# and choose "Open With -> Archive Utility", or possible typing 32# "open Xcode_9.2.xip" in a terminal. 33# erik.joelsson@oracle.com 34 35USAGE="$0 <Xcode.app>" 36 37if [ "$1" = "" ]; then 38 echo $USAGE 39 exit 1 40fi 41 42XCODE_APP="$1" 43XCODE_APP_DIR_NAME="${XCODE_APP##*/}" 44 45SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)" 46BUILD_DIR="${SCRIPT_DIR}/../../build/devkit" 47 48# Find the version of Xcode 49XCODE_VERSION="$($XCODE_APP/Contents/Developer/usr/bin/xcodebuild -version \ 50 | awk '/Xcode/ { print $2 }' )" 51SDK_VERSION="$(ls $XCODE_APP/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \ 52 | grep [0-9] | sort -r | head -n1 | sed 's/\.sdk//')" 53 54DEVKIT_ROOT="${BUILD_DIR}/Xcode${XCODE_VERSION}-${SDK_VERSION}" 55DEVKIT_BUNDLE="${DEVKIT_ROOT}.tar.gz" 56 57echo "Xcode version: $XCODE_VERSION" 58echo "SDK version: $SDK_VERSION" 59echo "Creating devkit in $DEVKIT_ROOT" 60 61mkdir -p $DEVKIT_ROOT 62 63################################################################################ 64# Copy the relevant parts of Xcode.app, removing things that are both big and 65# unecessary for our purposes, without building an impossibly long exclude list. 66# 67# Not including WatchSimulator.platform makes ibtool crashes in some situations. 68# It doesn't seem to matter which extra platform is included, but that is the 69# smallest one. 70 71EXCLUDE_DIRS=" \ 72 Contents/_CodeSignature \ 73 $XCODE_APP_DIR_NAME/Contents/Applications \ 74 $XCODE_APP_DIR_NAME/Contents/Resources \ 75 $XCODE_APP_DIR_NAME/Contents/Library \ 76 $XCODE_APP_DIR_NAME/Contents/XPCServices \ 77 $XCODE_APP_DIR_NAME/Contents/OtherFrameworks \ 78 $XCODE_APP_DIR_NAME/Contents/Developer/Documentation \ 79 $XCODE_APP_DIR_NAME/Contents/Developer/usr/share \ 80 $XCODE_APP_DIR_NAME/Contents/Developer/usr/libexec/git-core \ 81 $XCODE_APP_DIR_NAME/Contents/Developer/usr/bin/git* \ 82 $XCODE_APP_DIR_NAME/Contents/Developer/usr/bin/svn* \ 83 $XCODE_APP_DIR_NAME/Contents/Developer/usr/lib/libgit* \ 84 $XCODE_APP_DIR_NAME/Contents/Developer/usr/lib/libsvn* \ 85 $XCODE_APP_DIR_NAME/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/share/man \ 86 $XCODE_APP_DIR_NAME/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/${SDK_VERSION}.sdk/usr/share/man \ 87 $XCODE_APP_DIR_NAME/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/share/man \ 88 $XCODE_APP_DIR_NAME/Contents/Developer/Platforms/MacOSX.platform/usr \ 89 $XCODE_APP_DIR_NAME/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man \ 90 $XCODE_APP_DIR_NAME/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift* \ 91 $XCODE_APP_DIR_NAME/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift* \ 92 $XCODE_APP_DIR_NAME/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/sourcekitd.framework \ 93 $XCODE_APP_DIR_NAME/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec/swift* \ 94 $XCODE_APP_DIR_NAME/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/swift* \ 95 $XCODE_APP_DIR_NAME/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/arc \ 96 Platforms/AppleTVSimulator.platform \ 97 Platforms/iPhoneSimulator.platform \ 98 $XCODE_APP_DIR_NAME/Contents/SharedFrameworks/LLDB.framework \ 99 $XCODE_APP_DIR_NAME/Contents/SharedFrameworks/ModelIO.framework \ 100 $XCODE_APP_DIR_NAME/Contents/SharedFrameworks/XCSUI.framework \ 101 $XCODE_APP_DIR_NAME/Contents/SharedFrameworks/SceneKit.framework \ 102 $XCODE_APP_DIR_NAME/Contents/SharedFrameworks/XCBuild.framework \ 103 $XCODE_APP_DIR_NAME/Contents/SharedFrameworks/GPUTools.framework \ 104 $(cd $XCODE_APP/.. && ls -d $XCODE_APP_DIR_NAME/Contents/Developer/Platforms/* \ 105 | grep -v MacOSX.platform | grep -v WatchSimulator.platform) \ 106" 107 108for ex in $EXCLUDE_DIRS; do 109 EXCLUDE_ARGS+="--exclude=$ex " 110done 111 112echo "Copying Xcode.app..." 113echo rsync -rlH $INCLUDE_ARGS $EXCLUDE_ARGS "$XCODE_APP" $DEVKIT_ROOT/ 114rsync -rlH $INCLUDE_ARGS $EXCLUDE_ARGS "$XCODE_APP" $DEVKIT_ROOT/ 115 116################################################################################ 117 118echo-info() { 119 echo "$1" >> $DEVKIT_ROOT/devkit.info 120} 121 122echo "Generating devkit.info..." 123rm -f $DEVKIT_ROOT/devkit.info 124echo-info "# This file describes to configure how to interpret the contents of this devkit" 125echo-info "DEVKIT_NAME=\"Xcode $XCODE_VERSION (devkit)\"" 126echo-info "DEVKIT_TOOLCHAIN_PATH=\"\$DEVKIT_ROOT/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:\$DEVKIT_ROOT/Xcode.app/Contents/Developer/usr/bin\"" 127echo-info "DEVKIT_SYSROOT=\"\$DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/$SDK_VERSION.sdk\"" 128echo-info "DEVKIT_EXTRA_PATH=\"\$DEVKIT_TOOLCHAIN_PATH\"" 129 130################################################################################ 131# Copy this script 132 133echo "Copying this script..." 134cp $0 $DEVKIT_ROOT/ 135 136################################################################################ 137# Create bundle 138 139echo "Creating bundle..." 140GZIP=$(command -v pigz) 141if [ -z "$GZIP" ]; then 142 GZIP="gzip" 143fi 144(cd $DEVKIT_ROOT && tar c - . | $GZIP - > "$DEVKIT_BUNDLE") 145