Created
April 15, 2019 00:41
-
-
Save mgrebenets/8fe4289603aaec0dfeae5eacfae203d6 to your computer and use it in GitHub Desktop.
Generate Xcode archive from Buck output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
XCARCHIVE=$1 | |
APP_DIR=$2 | |
APP_NAME=$(basename "${APP_DIR}") | |
OUT_DIR=$(dirname "$PWD") | |
PBUDDY=/usr/libexec/PlistBuddy | |
# Copy directories into xcarchive | |
mkdir -p "${XCARCHIVE}/BCSymbolMaps" | |
mkdir -p "${XCARCHIVE}/dSYMs" | |
mkdir -p "${XCARCHIVE}/Products/Applications" | |
mkdir -p "${XCARCHIVE}/SwiftSupport/iphoneos" | |
cp -R "${OUT_DIR}"/**/*.dSYM "${XCARCHIVE}/dSYMs" | |
cp -R "${OUT_DIR}"/*.dSYM "${XCARCHIVE}/dSYMs" | |
cp -R "${APP_DIR}" "${XCARCHIVE}/Products/Applications" | |
cp -R "${APP_DIR}"/**/*.dylib "${XCARCHIVE}/SwiftSupport/iphoneos" | |
# Create empty plist | |
INFO_PLIST="${XCARCHIVE}/Info.plist" | |
cp "${APP_DIR}/Info.plist" "${INFO_PLIST}" | |
${PBUDDY} -x -c "Clear dict" "${INFO_PLIST}" | |
# Create plist keys | |
TODAY_DATE=$(date -u +"%a %b %d %T GMT %Y") | |
${PBUDDY} -x -c "Add :ApplicationProperties dict" \ | |
-c "Add :ApplicationProperties:ApplicationPath String Applications/${APP_NAME}" \ | |
-c "Add :ApplicationProperties:CFBundleIdentifier String" \ | |
-c "Add :ApplicationProperties:CFBundleShortVersionString String" \ | |
-c "Add :ApplicationProperties:CFBundleVersion String" \ | |
-c "Add :ApplicationProperties:SigningIdentity String" \ | |
-c "Add :ArchiveVersion Integer 2" \ | |
-c "Add :CreationDate Date ${TODAY_DATE}" \ | |
-c "Add :Name String" \ | |
-c "Add :SchemeName String" "${INFO_PLIST}" | |
# Get values from .app plist | |
BUNDLE_ID=$(${PBUDDY} -c "Print CFBundleIdentifier" "${APP_DIR}/Info.plist") | |
SHORT_VERSION=$(${PBUDDY} -c "Print CFBundleShortVersionString" "${APP_DIR}/Info.plist") | |
BUNDLE_VERSION=$(${PBUDDY} -c "Print CFBundleVersion" "${APP_DIR}/Info.plist") | |
BUNDLE_NAME=$(${PBUDDY} -c "Print CFBundleName" "${APP_DIR}/Info.plist") | |
# Set plist values | |
${PBUDDY} -c "Set ApplicationProperties:CFBundleIdentifier ${BUNDLE_ID}" \ | |
-c "Set ApplicationProperties:CFBundleShortVersionString ${SHORT_VERSION}" \ | |
-c "Set ApplicationProperties:CFBundleVersion ${BUNDLE_VERSION}" \ | |
-c "Set Name ${BUNDLE_NAME}" \ | |
-c "Set SchemeName ${BUNDLE_NAME}" "${INFO_PLIST}" | |
# Get signing identity | |
codesign -dv --verbose=4 "${APP_DIR}" &>codesign.log | |
CODE_SIGN=$(cat <codesign.log | grep "Authority" | head -n1 | cut -d "=" -f2) | |
${PBUDDY} -x -c "Set ApplicationProperties:SigningIdentity ${CODE_SIGN}" "${INFO_PLIST}" | |
rm codesign.log |
It’s been a while since I had to deal with buck. It probably does. If all the App Store certs and provisioning profiles are specified during buck build the resulting ipa should be good to be uploaded. It’s just that for the use case I used to have back then, we needed an Xcode archive to re-export and resign it later for various distribution types - that was needed for our workflow
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry to ask here, but, so buck doesn't provide mechanism to generate AppStore uploadable archive?