@@ -4,7 +4,6 @@ THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44
55set -e
66
7-
87#
98# Detect Xcode major version
109xcode_major_version=" "
@@ -45,14 +44,28 @@ if [ ! -z "${export_options_path}" ] && [[ "${xcode_major_version}" == "6" ]] ;
4544 export_options_path=" "
4645fi
4746
48- if [ -z " ${build_tool} " ] ; then
49- echo " [!] Missing required input: build_tool"
50- exit 1
51- elif [[ " ${build_tool} " != " xctool" && " ${build_tool} " != " xcodebuild" ]] ; then
52- echo " [!] Invalid build_tool: ${build_tool} "
47+ if [[ " ${output_tool} " != " xcpretty" && " ${output_tool} " != " xcodebuild" ]] ; then
48+ echo " [!] Invalid output_tool: ${output_tool} "
5349 exit 1
5450fi
5551
52+ set +e
53+
54+ if [[ " ${output_tool} " == " xcpretty" ]] ; then
55+ xcpretty_version=$( xcpretty --version)
56+ exit_code=$?
57+ if [[ $exit_code != 0 || -z $xcpretty_version ]] ; then
58+ echo
59+ echo " (!) xcpretty is not installed"
60+ echo " For xcpretty installation see: 'https://github.com/supermarin/xcpretty',"
61+ echo " or use 'xcodebuild' as 'output_tool'."
62+ echo
63+ exit 1
64+ fi
65+ fi
66+
67+ set -e
68+
5669#
5770# Project-or-Workspace flag
5871if [[ " ${project_path} " == * " .xcodeproj" ]]; then
8497echo
8598echo " ========== Configs =========="
8699echo " * CONFIG_xcode_project_action: ${CONFIG_xcode_project_action} "
87- echo " * build_tool : ${build_tool } "
100+ echo " * output_tool : ${output_tool } "
88101echo " * project_path: ${project_path} "
89102echo " * scheme: ${scheme} "
90103echo " * workdir: ${workdir} "
@@ -142,38 +155,40 @@ if [ -f "${ipa_path}" ] ; then
142155 rm " ${ipa_path} "
143156fi
144157
158+ echo
159+ echo
160+ echo " => Create the Archive ..."
161+
145162#
146163# Create the Archive with Xcode Command Line tools
164+ archive_cmd=" xcodebuild ${CONFIG_xcode_project_action} \" ${project_path} \" "
165+ archive_cmd=" $archive_cmd -scheme \" ${scheme} \" ${xcode_configuration} "
166+ archive_cmd=" $archive_cmd ${clean_build_param} archive -archivePath \" ${archive_path} \" "
167+
147168if [[ " ${is_force_code_sign} " == " yes" ]] ; then
148169 echo " (!) Using Force Code Signing mode!"
149170
150- echo
151- echo
152-
153- set -x
154- ${build_tool} ${CONFIG_xcode_project_action} " ${project_path} " \
155- -scheme " ${scheme} " ${xcode_configuration} \
156- ${clean_build_param} archive -archivePath " ${archive_path} " \
157- PROVISIONING_PROFILE=" ${BITRISE_PROVISIONING_PROFILE_ID} " \
158- CODE_SIGN_IDENTITY=" ${BITRISE_CODE_SIGN_IDENTITY} "
159- else
160- echo
161- echo
171+ archive_cmd=" $archive_cmd PROVISIONING_PROFILE=\" ${BITRISE_PROVISIONING_PROFILE_ID} \" "
172+ archive_cmd=" $archive_cmd CODE_SIGN_IDENTITY=\" ${BITRISE_CODE_SIGN_IDENTITY} \" "
173+ fi
162174
163- set -x
164- ${build_tool} ${CONFIG_xcode_project_action} " ${project_path} " \
165- -scheme " ${scheme} " ${xcode_configuration} \
166- ${clean_build_param} archive -archivePath " ${archive_path} "
175+ if [[ " ${output_tool} " == " xcpretty" ]] ; then
176+ archive_cmd=" set -o pipefail && $archive_cmd | xcpretty"
167177fi
168178
169- set +x
170- set +v
179+ echo
180+ echo " archive command:"
181+ echo " $archive_cmd "
182+ echo
183+
184+ eval $archive_cmd
171185
172186echo
173187echo
174188echo " => Exporting IPA from generated Archive ..."
175189echo
176- echo
190+
191+ export_command=" xcodebuild -exportArchive"
177192
178193if [[ " ${xcode_major_version} " == " 6" ]] ; then
179194 #
@@ -210,20 +225,27 @@ if [[ "${xcode_major_version}" == "6" ]] ; then
210225
211226 echo " (i) Found Profile Name for signing: ${profile_name} "
212227
213- set -v
214-
215228 #
216229 # Use the Provisioning Profile name to export the IPA
217- xcodebuild -exportArchive \
218- -exportFormat ipa \
219- -archivePath " ${archive_path} " \
220- -exportPath " ${ipa_path} " \
221- -exportProvisioningProfile " ${profile_name} "
230+ export_command=" $export_command -exportFormat ipa"
231+ export_command=" $export_command -archivePath \" ${archive_path} \" "
232+ export_command=" $export_command -exportPath \" ${ipa_path} \" "
233+ export_command=" $export_command -exportProvisioningProfile \" ${profile_name} \" "
234+
235+ if [[ " ${output_tool} " == " xcpretty" ]] ; then
236+ export_command=" set -o pipefail && $export_command | xcpretty"
237+ fi
238+
239+ echo
240+ echo " export command:"
241+ echo " $export_command "
242+ echo
243+
244+ eval $export_command
222245else
223246 echo " (i) Using Xcode 7 'exportOptionsPlist' option"
224247
225248 if [ -z " ${export_options_path} " ] ; then
226- set -x
227249 export_options_path=" ${output_dir} /export_options.plist"
228250 curr_pwd=" $( pwd) "
229251 cd " ${THIS_SCRIPT_DIR} "
@@ -232,15 +254,8 @@ else
232254 -o " ${export_options_path} " \
233255 -a " ${archive_path} "
234256 cd " ${curr_pwd} "
235- set +x
236257 fi
237258
238-
239- #
240- # Export the IPA
241- echo " Content of exportOptionsPlist file:"
242- cat " ${export_options_path} "
243-
244259 #
245260 # Because of an RVM issue which conflicts with `xcodebuild`'s new
246261 # `-exportOptionsPlist` option
@@ -255,16 +270,22 @@ else
255270 rvm use system
256271 fi
257272
258- set -x
259-
260273 tmp_dir=$( mktemp -d -t bitrise-xcarchive)
261274
262- xcodebuild -exportArchive \
263- -archivePath " ${archive_path} " \
264- -exportPath " ${tmp_dir} " \
265- -exportOptionsPlist " ${export_options_path} "
275+ export_command=" $export_command -archivePath \" ${archive_path} \" "
276+ export_command=" $export_command -exportPath \" ${tmp_dir} \" "
277+ export_command=" $export_command -exportOptionsPlist \" ${export_options_path} \" "
278+
279+ if [[ " ${output_tool} " == " xcpretty" ]] ; then
280+ export_command=" set -o pipefail && $export_command | xcpretty"
281+ fi
266282
267- set +x
283+ echo
284+ echo " export command:"
285+ echo " $export_command "
286+ echo
287+
288+ eval $export_command
268289
269290 # Searching for ipa
270291 exported_ipa_path=" "
300321 ipa_path=" ${exported_ipa_path} "
301322fi
302323
303- set +v
304-
305324
306325#
307326# Export *.ipa path
0 commit comments