2
0

Adjust darwin build configuration to new project structure.

This commit is contained in:
Maarten Billemont
2017-03-06 17:25:59 -05:00
parent 18fce4eaf8
commit 94159ed11a
1013 changed files with 305 additions and 572 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,60 @@
#! /usr/bin/env bash
source bashlib
isIn() {
local key=$1; shift
for value
do [[ $value = "$key" ]] && return; done
}
cd "${0%/*}/../../"
emit "Enumerating localization keys"
code=$(find Classes -type f -exec grep -o 'NSLocalizedString(@"[^"]*"' {} + | sed -n 's/.*\("[^"]*"\).*/\1/p' | sort -bu)
for l in Resources/*.lproj/Localizable.strings; do
k=${l#*/}; k=${k%%/*}
emit " - Found language: ${k%.lproj}"
lang+=( "$k" )
lprojLocal+=( "$(sed -n '/\/\/[^"]*\[REMOTE\][^"]*$/!s/^\("[^"]*"\).*/\1/p' "$l" | sort -bu)" )
lprojAll+=( "$(sed -n 's/^\("[^"]*"\).*/\1/p' "$l" | sort -u)" )
done
allhealthy=1
healthy=1
echo; emit "Looking for unused localization keys"
for l in "${!lang[@]}"; do
while read; do
(( healthy )) && emit -y "Not used in code or marked '// [REMOTE]':"
allhealthy=0
healthy=0
emit -y " ${lang[l]}: ${REPLY##*([[:space:]])} "
done < <(comm -1 -3 <(printf '%s\n' "$code") <(printf '%s\n' "${lprojLocal[l]}"))
done
(( healthy )) && emit "No unused keys."
healthy=1
echo; emit "Looking for missing localization keys"
for l in "${!lang[@]}"; do
chealthy=1
while read; do
(( chealthy )) && emit -y "Used by code:"
allhealthy=0
chealthy=0
healthy=0
emit -r " ${lang[l]}: ${REPLY##*([[:space:]])} "
done < <(comm -2 -3 <(printf '%s\n' "$code") <(printf '%s\n' "${lprojAll[l]}"))
khealthy=1
while read; do
(( khealthy )) && emit -y "Present in other languages:"
allhealthy=0
khealthy=0
healthy=0
emit -r " ${lang[l]}: ${REPLY##*([[:space:]])} "
done < <(for ol in "${!lang[@]}"; do comm -1 -3 <(printf '%s\n' "${lprojAll[l]}") <(printf '%s\n' "${lprojAll[ol]}"); done | sort -bu)
done
(( healthy )) && emit "No missing keys."
echo
(( allhealthy )) && emit "All good." || emit -y "Some issues detected."

View File

@@ -0,0 +1,76 @@
#! /usr/bin/env bash
source bashlib
cd "${0%/*}/../Resources/Media"
PATH+=:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
temp="${TMPDIR:-/tmp}/.$$.convertImages"
mkdir "$temp" || err "Couldn't create temp directory." || return
trap 'rmdir "$temp"' EXIT
downsize() {
local from=$1 to=$2 size=${3:-50%}
convert "$from" -filter box -resize "$size" -unsharp 1x1+1+0.4 "$to"
pngcrush -d "$temp" -rem gAMA -rem cHRM -rem sRGB -rem iCCP "$to" && mv "$temp/"* "$to"
}
inf "Converting appiconsets"
declare -A icons=(
["ios-Icon-60@2x.png"]=120
["ios-Icon-40@2x.png"]=80
["ios-Icon-40~ipad.png"]=40
["ios-Icon-40~ipad@2x.png"]=80
["ios-Icon-Small@2x.png"]=58
["ios-Icon-Small~ipad.png"]=29
["ios-Icon-Small~ipad@2x.png"]=58
["ios-Icon-76~ipad.png"]=76
["ios-Icon-76~ipad@2x.png"]=152
["mac-icon_512x512.png"]=512
["mac-icon_512x512@2x.png"]=1024
["mac-icon_256x256@2x.png"]=512
["mac-icon_256x256.png"]=256
["mac-icon_128x128@2x.png"]=256
["mac-icon_128x128.png"]=128
["mac-icon_32x32@2x.png"]=64
["mac-icon_32x32.png"]=32
["mac-icon_16x16@2x.png"]=32
["mac-icon_16x16.png"]=16
)
for name in "${!icons[@]}"; do
size=${icons[$name]}
source=${name%%-*}-icon@2x.png
file=Images.xcassets/AppIcon.appiconset/${name#*-}
echo "$PWD/$file"
if [[ $source -nt $file ]]; then
pinf "$file ($size px)"
downsize "$source" "$file" "${size}x${size}"
fnip
fi
done
hr
inf "Converting @2x/-hd artwork"
for file in ./**/*{@2x,-ipadhd,-hd}.png; do
inArray "${file##*/}" "${icons[@]}" && continue
[[ ! -e $file ]] && continue
dest=${file/@(@2x|-hd)}
dest=${dest/-ipadhd/-ipad}
if [[ $file = Default* ]]; then
read width height < <(identify -format '%w %h' "$file")
if (( width > height )); then
emit "Rotating $file" --
mogrify -rotate 90 "$file"
emit -$?
fi
fi
if [[ ! -e $dest || "$dest" -ot "$file" ]]; then
pinf "$file -> $dest"
downsize "$file" "$dest"
fnip
fi
done

187
platform-darwin/Scripts/genassets Executable file
View File

@@ -0,0 +1,187 @@
#!/usr/bin/env bash
# See https://developer.apple.com/library/ios/qa/qa1686/_index.html
cd "${BASH_SOURCE%/*}"
source bashlib
set -e
cd ..
export PATH+=:/usr/local/bin
# icons format: [pixel size]@[scale]@[idiom]@[os]:[filename] -- if os is "anything lower", omit it
icons=(
# Mac
16@1@mac@:
32@2@mac@:
32@1@mac@:
64@2@mac@:
128@1@mac@:
256@2@mac@:
256@1@mac@:
512@2@mac@:
512@1@mac@:
1024@2@mac@:
# iPhone
180@3@iphone@8.0:Icon-60@3x.png
120@3@iphone@8.0:Icon-Small-40@3x.png
120@2@iphone@7.0:Icon-60@2x.png
80@2@iphone@7.0:Icon-Small-40@2x.png
# 114@2@iphone@:Icon@2x.png
87@3@iphone@:Icon-Small@3x.png
58@2@iphone@:Icon-Small@2x.png
# 57@1@iphone@:Icon.png
# 29@1@iphone@:Icon-Small.png
# iPad
76@1@ipad@7.0:Icon-76.png
152@2@ipad@7.0:Icon-76@2x.png
40@1@ipad@7.0:Icon-Small-40.png
80@2@ipad@7.0:Icon-Small-40@2x.png
29@1@ipad@:Icon-Small.png
58@2@ipad@:Icon-Small@2x.png
# 72@1@ipad@:Icon-72.png
# 144@2@ipad@:Icon-72@2x.png
# 50@1@ipad@:Icon-Small-50.png
# 100@2@ipad@:Icon-Small-50@2x.png
)
# splashes format: [size name]@[scale]@[idiom]@[os] -- if scale is 1, omit it. if os is "anything lower", omit it
splashes=(
414-736@3@iphone@8.0
375-667@2@iphone@8.0
320-568@2@iphone@7.0
320-568@2@iphone@
320-480@2@iphone@7.0
320-480@2@iphone@
320-480@@iphone@
)
copyImage() {
local src=$1 dst=$2
if [[ $src = *.9.png || $src = *.9@*.png ]]; then
pinf '%s -> %s (ninepatch)' "${src##*/}" "${dst##*/}"
niftyNinePatch=$(java -Dapple.awt.UIElement=true -jar Scripts/NiftyNinePatchHelper.jar "$src" "$dst") || return
while IFS='=' read var value; do
[[ $var = imageMode ]] && value=${value#'"resize:'} value=${value%'"'} && IFS=, read capLeft capWidth capRight capTop _ _ _ capHeight _ _ _ capBottom <<< "$value"
[[ $var = padding ]] && IFS=, read paddingTop paddingRight paddingBottom paddingLeft <<< "${value//[px\"]}"
uinf 'caps: [%d, %d, %d, %d], padding: [%d, %d, %d, %d]' "$capTop" "$capRight" "$capBottom" "$capLeft" "$paddingTop" "$paddingRight" "$paddingBottom" "$paddingLeft"
printf ',"resizing":{"capInsets":{"bottom":%d,"left":%d,"right":%d,"top":%d},"center":{"height":%d,"mode":"fill","width":%d},"mode":"9-part"}' \
"$capBottom" "$capLeft" "$capRight" "$capTop" "$capHeight" "$capWidth"
done <<< "$niftyNinePatch"
fnip
else
pinf '%s -> %s' "${src##*/}" "${dst##*/}"
cp "$src" "$dst"
fnip
fi
}
xcassets=Resources/Media/Images.xcassets
appiconset="$xcassets/AppIcon.appiconset"
launchimage="$xcassets/LaunchImage.launchimage"
ios_icon=Resources/Media/ios/icon
ios_launch=Resources/Media/ios/launch
mac_icon=Resources/Media/mac/icon
if [[ "$(latest "$ios_icon"/*)" -nt "$appiconset/Contents.json" ]] ||
[[ "$(latest "$mac_icon"/*)" -nt "$appiconset/Contents.json" ]]; then
rm -rf "$appiconset"; mkdir -p "$appiconset"
{
comma=
printf '{"images":['
for icon in "${icons[@]}"; do
IFS=: read icon filename <<< "$icon"
IFS=@ read px scale idiom os <<< "$icon"
pt=$(( px / scale ))
suffix=
[[ $scale != 1 ]] && suffix=@${scale}x
[[ $filename ]] || filename="icon_${pt}x${pt}${suffix}.png"
source=$ios_icon/$filename
if [[ ! -e $source ]]; then
source=$mac_icon/$filename
if [[ ! -e $source ]]; then
err 'No icon for: %s' "$filename"
exit 1
fi
fi
if imageProps=$(copyImage "$source" "$appiconset/$filename"); then
printf '%s{"size":"%dx%d","filename":"%s","scale":"%sx"' \
"$comma" "$pt" "$pt" "$filename" "$scale"
[[ $idiom ]] && printf ',"idiom":"%s"' "$idiom"
[[ $os ]] && printf ',"minimum-system-version":"%s"' "$os"
[[ $imageProps ]] && printf '%s' "$imageProps"
printf '}'
comma=,
else
rm "$appiconset/Contents.json"
exit
fi
done
printf '],"info":{"version":1,"author":"genassets"},"properties":{"pre-rendered":true}}\n'
} > "$appiconset/Contents.json"
fi
if [[ "$(latest "$ios_launch"/*)" -nt "$launchimage/Contents.json" ]]; then
rm -rf "$launchimage"; mkdir -p "$launchimage"
{
comma=
printf '{"images":['
for splash in "${splashes[@]}"; do
IFS=@ read name scale idiom os <<< "$splash"
case "$name" in
*-568) subtype=retina4 ;;
*-667) subtype=667h ;;
*-736) subtype=736h ;;
*) subtype= ;;
esac
filename="Default${os:+-$os}${subtype:+-$subtype}${scale:+@${scale}x}${idiom:+~$idiom}.png"
if imageProps=$(copyImage "$ios_launch/$name${scale:+@${scale}x}.png" "$launchimage/$filename"); then
printf '%s{"extent":"full-screen","filename":"%s","orientation":"portrait","scale":"%sx"' \
"$comma" "$filename" "${scale:-1}"
[[ $idiom ]] && printf ',"idiom":"%s"' "$idiom"
[[ $os ]] && printf ',"minimum-system-version":"%s"' "$os"
[[ $subtype ]] && printf ',"subtype":"%s"' "$subtype"
[[ $imageProps ]] && printf '%s' "$imageProps"
printf '}'
comma=,
else
rm "$launchimage/Contents.json"
exit
fi
done
printf '],"info":{"version":1,"author":"genassets"}}\n'
} > "$launchimage/Contents.json"
fi
#for file in resources/images/mdpi/*.png; do
# name=${file##*/} name=${name%.*} name=${name/.9/}
# mdpiFile=$file
# xhdpiFile=${file%/*/*.*}/xhdpi/${file##*/}
# mdpiFilename=$name.png
# xhdpiFilename=$name@2x.png
#
# [[ -e "$xcassets/$name.imageset/$mdpiFilename" && $mdpiFile -ot "$xcassets/$name.imageset/$mdpiFilename" &&
# -e "$xcassets/$name.imageset/$xhdpiFilename" && $xhdpiFile -ot "$xcassets/$name.imageset/$xhdpiFilename" ]] && continue
# rm -rf "$xcassets/$name.imageset"; mkdir -p "$xcassets/$name.imageset"
#
# {
# comma=
# printf '{"images":['
# if imageProps=$(copyImage "$mdpiFile" "$xcassets/$name.imageset/$mdpiFilename"); then
# printf '%s{"idiom":"universal","scale":"1x","filename":"%s"' "$comma" "$mdpiFilename"
# [[ $imageProps ]] && printf '%s' "$imageProps"
# printf '}'
# comma=,
# fi
# if imageProps=$(copyImage "$xhdpiFile" "$xcassets/$name.imageset/$xhdpiFilename"); then
# printf '%s{"idiom":"universal","scale":"2x","filename":"%s"' "$comma" "$xhdpiFilename"
# [[ $imageProps ]] && printf '%s' "$imageProps"
# printf '}'
# comma=,
# fi
# printf '],"info":{"version":1,"author":"genassets"}}\n'
# } > "$xcassets/$name.imageset/Contents.json"
#done

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# This script should be in the 'Scripts' directory under the git repository's root.
cd "${BASH_SOURCE%/*}/.."
shopt -s extglob
## Submodules that need to be checked out.
dependencies=( External/{InAppSettingsKit,Pearl{,:External/jrswizzle,:External/uicolor-utilities},RHStatusItemView} )
## Custom migration.
# None yet.
################################################################################
isCheckedOut() {
local modulePath=$1
! git submodule status | grep -q "^-[^ ]* $modulePath"
}
# git submodule sync -- A bug causes this to init ALL external dependencies.
git submodule sync $(git submodule status | awk '/^ / { print $2 }')
# Check out our missing dependencies
for dependency in "${dependencies[@]}"; do
[[ $dependency = *:* ]] && root=${dependency%%:*} || root=.
path=${dependency#*:}
( cd "$root"; git submodule update --init "$path" )
done
# Update our modules
git submodule update
# Our modules may define a custom update script, if so, run it.
find !(Scripts)/ -name "${BASH_SOURCE##*/}" -exec {} \;
# Finally, for our modules that haven't got a custom update script, update them recursively.
git submodule update --recursive --rebase

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env bash
cd "${BASH_SOURCE%/*}"
source ./bashlib
cd ..
export PATH+=:/usr/libexec
addPlistWithKey() {
local key=$1 type=$2 value=$3 plist=${4:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
PlistBuddy -c "Delete :'$key'" "$plist" 2>/dev/null || true
PlistBuddy -c "Add :'$key' '$type' '$value'" "$plist"
}
setPlistWithKey() {
local key=$1 value=$2 plist=${3:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
PlistBuddy -c "Set :'$key' '$value'" "$plist"
}
getPlistWithKey() {
local key=$1 plist=${2:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
PlistBuddy -c "Print :'$key'" "$plist"
}
setSettingWithTitle() {
local i title=$1 value=$2 plist=${3:-"$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/Settings.bundle/Root.plist"}
for (( i=0; 1; ++i )); do
PlistBuddy -c "Print :PreferenceSpecifiers:$i" "$plist" &>/dev/null || break
inf "Checking preference specifier $i"
[[ $(PlistBuddy -c "Print :PreferenceSpecifiers:$i:Title" "$plist" 2>/dev/null) = $title ]] || continue
inf "Correct title, setting value."
PlistBuddy -c "Set :PreferenceSpecifiers:$i:DefaultValue $value" "$plist"
break
done
}
description=$(git describe --always --dirty --long --match '*-release')
version=${description%-g*}
release=${version%%-*} build=${version##*-}
printf -v version '%s.%d' "$release" "$build"
printf -v commit '%s' "${description##*-g}"
addPlistWithKey GITDescription string "$description"
setPlistWithKey CFBundleVersion "$(hr "${version%%.*}" 13).${version#*.}"
setPlistWithKey CFBundleShortVersionString "$version"
setSettingWithTitle "Build" "$commit"
setSettingWithTitle "Version" "$version"
setSettingWithTitle "Copyright" "$(getPlistWithKey NSHumanReadableCopyright)"
if [[ $DEPLOYMENT_LOCATION = YES ]]; then
# This build is a release. Do some release checks.
crashlyticsPlist="$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/Crashlytics.plist"
passed=1
[[ $description != *-dirty ]] || \
{ passed=0; err 'ERROR: Cannot release a dirty version, first commit any changes.'; }
[[ -r "$crashlyticsPlist" && $(PlistBuddy -c "Print :'API Key'" "$crashlyticsPlist" 2>/dev/null) ]] || \
{ passed=0; err 'ERROR: Cannot release: Crashlytics API key is missing.'; }
(( passed )) || \
{ ftl "Failed to pass release checks. Fix the above errors and re-try. Aborting."; exit 1; }
fi