@@ -42,74 +42,6 @@ source "${scripts_dir}/package_managers.sh"
4242# This currently points to version 0.21.3, the last version that supports Xcode 9
4343SOURCEKITTEN_FORMULA=" https://raw.githubusercontent.com/Homebrew/homebrew-core/c5a8a094f9e1dd8e41ed24785acef07ef7092d0d/Formula/sourcekitten.rb"
4444
45- fix_bazel_imports () {
46- echo " Rewriting imports for bazel..."
47-
48- private_components () {
49- find " components/private" -type d | cut -d' /' -f3 | sort | uniq
50- }
51-
52- rewrite_tests () {
53- find " ${stashed_dir} " components/private/* /tests -type f -name ' *.swift' -exec perl -pi -e " $1 " {} + || true
54- find " ${stashed_dir} " components/private/* /tests -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
55- find " ${stashed_dir} " components/* /tests -type f -name ' *.swift' -exec perl -pi -e " $1 " {} + || true
56- find " ${stashed_dir} " components/* /tests -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
57- find " ${stashed_dir} " components/schemes/* /tests -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
58- }
59- rewrite_examples () {
60- find " ${stashed_dir} " components/private/* /examples -type f -name ' *.swift' -exec perl -pi -e " $1 " {} + || true
61- find " ${stashed_dir} " components/private/* /examples -type f -name ' *.h' -exec perl -pi -e " $1 " {} + || true
62- find " ${stashed_dir} " components/private/* /examples -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
63- find " ${stashed_dir} " components/* /examples -type f -name ' *.swift' -exec perl -pi -e " $1 " {} + || true
64- find " ${stashed_dir} " components/* /examples -type f -name ' *.h' -exec perl -pi -e " $1 " {} + || true
65- find " ${stashed_dir} " components/* /examples -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
66- }
67- rewrite_source () {
68- find " ${stashed_dir} " components/private/* /src -type f -name ' *.h' -exec perl -pi -e " $1 " {} + || true
69- find " ${stashed_dir} " components/private/* /src -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
70- find " ${stashed_dir} " components/* /src -type f -name ' *.h' -exec perl -pi -e " $1 " {} + || true
71- find " ${stashed_dir} " components/* /src -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
72- find " ${stashed_dir} " components/schemes/* /src -type f -name ' *.h' -exec perl -pi -e " $1 " {} + || true
73- find " ${stashed_dir} " components/schemes/* /src -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
74- }
75- rewrite_catalogs () {
76- find " ${stashed_dir} " catalog/MDC* -type f -name ' *.swift' -exec perl -pi -e " $1 " {} + || true
77- find " ${stashed_dir} " catalog/MDC* -type f -name ' *.m' -exec perl -pi -e " $1 " {} + || true
78- find " ${stashed_dir} " catalog/MDC* -type f -name ' *.h' -exec perl -pi -e " $1 " {} + || true
79- }
80-
81- stashed_dir=" "
82- rewrite_examples " s/import <MaterialComponentsBeta\/(.+)>/import\/\*Material beta framework import\*\/ \" \1\" /"
83- rewrite_catalogs " s/import <CatalogByConvention\/CatalogByConvention\.h>/import\/\*Material prefix framework import\*\/ \" CatalogByConvention.h\" /"
84- rewrite_examples " s/import <MaterialComponents\/Material(.+)\.h>/import\/\*Material prefix framework import\*\/ \" Material\1.h\" /"
85- rewrite_source " s/import <MaterialComponentsBeta\/(.+)>/import\/\*Material beta framework import\*\/ \" \1\" /"
86- rewrite_source " s/import <Motion(.+)\/Motion.+\.h>/import \" Motion\1.h\" /"
87- rewrite_source " s/import <MDFTextAccessibility\/MDFTextAccessibility\.h>/import \" MDFTextAccessibility.h\" /"
88- rewrite_source " s/import <MaterialComponents\/Material(.+)\.h>/import\/\*Material prefix framework import\*\/ \" Material\1.h\" /"
89- rewrite_source " s/import <MaterialComponents\/MDC(.+)\.h>/import\/\*MDC prefix framework import\*\/ \" MDC\1.h\" /"
90- rewrite_tests " s/import <MaterialComponentsBeta\/Material(.+)Beta\.h>/import\/\*Material beta prefix framework import\*\/ \" Material\1Beta.h\" /"
91- rewrite_tests " s/import <MaterialComponents\/Material(.+)\.h>/import\/\*Material prefix framework import\*\/ \" Material\1.h\" /"
92- rewrite_tests " s/import <MDFTesting\/MDFTesting\.h>/import \" MDFTesting.h\" /"
93- stashed_dir=" $( pwd) /"
94- reset_imports () {
95- echo " Undoing import rewrites for bazel..."
96-
97- # Undoes our source changes from above.
98- rewrite_tests " s/import\/\*Material beta prefix framework import\*\/ \" Material(.+).h\" /import <MaterialComponentsBeta\/Material\1\.h>/"
99- rewrite_catalogs " s/import\/\*Material prefix framework import\*\/ \" CatalogByConvention\.h\" /import <CatalogByConvention\/CatalogByConvention\.h>/"
100- rewrite_examples " s/import\/\*Material beta framework import\*\/ \" (.+)\" /import <MaterialComponentsBeta\/\1>/"
101- rewrite_examples " s/import\/\*Material prefix framework import\*\/ \" Material(.+)\.h\" /import <MaterialComponents\/Material\1\.h>/"
102- rewrite_source " s/import\/\*Material beta framework import\*\/ \" (.+)\" /import <MaterialComponentsBeta\/\1>/"
103- rewrite_source " s/import \" Motion(.+)\.h\" /import <Motion\1\/Motion\1.h>/"
104- rewrite_source " s/import \" MDFTextAccessibility\.h\" /import <MDFTextAccessibility\/MDFTextAccessibility.h>/"
105- rewrite_source " s/import\/\*Material prefix framework import\*\/ \" Material(.+)\.h\" /import <MaterialComponents\/Material\1\.h>/"
106- rewrite_source " s/import\/\*MDC prefix framework import\*\/ \" MDC(.+)\.h\" /import <MaterialComponents\/MDC\1\.h>/"
107- rewrite_tests " s/import\/\*Material prefix framework import\*\/ \" Material(.+)\.h\" /import <MaterialComponents\/Material\1\.h>/"
108- rewrite_tests " s/import \" MDFTesting\.h\" /import <MDFTesting\/MDFTesting.h>/"
109- }
110- trap reset_imports EXIT
111- }
112-
11345move_derived_data_to_tmp () {
11446 targetDir=" ${HOME} /Library/Developer/Xcode/DerivedData"
11547 if [[ -d " $targetDir " ]]; then
@@ -118,215 +50,6 @@ move_derived_data_to_tmp() {
11850 fi
11951}
12052
121- # Uploads all of the bazel test artifacts to Kokoro's artifacts storage.
122- upload_bazel_test_artifacts () {
123- logs_dir=" $KOKORO_ARTIFACTS_DIR /bazel_test_logs"
124- mkdir -p " $logs_dir "
125-
126- # Copies each file from stdin to $KOKORO_ARTIFACTS_DIR and preserves the directory structure
127- copy_to_artifacts () {
128- cat - | while read file; do
129- directory=" $logs_dir /$( dirname $file ) "
130- mkdir -p " $directory "
131- cp " $file " " $logs_dir /$file "
132- done
133- }
134-
135- brew_install rename
136-
137- # rename all test.log to sponge_log.log and then copy them to the kokoro
138- # artifacts directory.
139- find -L . -name " test.log" -type f -exec rename ' s/test.log/sponge_log.log/' {} \;
140- find -L . -name " sponge_log.log" -type f | copy_to_artifacts
141-
142- # rename all test.xml to sponge_log.xml and then copy them to kokoro
143- # artifacts directory.
144- find -L . -name " test.xml" -type f -exec rename ' s/test.xml/sponge_log.xml/' {} \;
145- find -L . -name " sponge_log.xml" -type f | copy_to_artifacts
146- }
147-
148- # Upgrades kokoro's current bazel version to at least 0.20.0
149- upgrade_kokoro_bazel_if_needed () {
150- bazel version
151-
152- if [ -f " $KOKORO_GFILE_DIR /use_bazel.sh" ]; then
153- bash " $KOKORO_GFILE_DIR /use_bazel.sh" 0.20.0
154- else
155- use_bazel.sh 0.20.0
156- fi
157- bazel version
158- }
159-
160- run_bazel_affected () {
161- echo " Checking affected targets..."
162- if [ -z " $COMMAND " ]; then
163- COMMAND=" test"
164- fi
165- if [ -z " $TARGET " ]; then
166- if [ " $COMMAND " == " test" ]; then
167- # Only return test targets.
168- bazel_kind=" test"
169- else
170- # Return all affected targets.
171- bazel_kind=" rule"
172- fi
173-
174- if [ -n " $KOKORO_BUILD_NUMBER " ]; then
175- pushd github/repo >> /dev/null
176- fi
177-
178- # `target_branch` is either the Pull Request destination branch (where it will be merged) or if
179- # none can be determined, defaults to `develop`.
180- if [ -n " $KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH " ]; then
181- target_branch=" $KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH "
182- else
183- target_branch=develop
184- fi
185-
186- # `base_sha` is the merge base of `target_branch` and the current HEAD.
187- base_sha=$( git merge-base " $target_branch " HEAD)
188-
189- # We must upgrade bazel prior to running bazel query because we rely on features in bazel
190- # 0.20.
191- if [ -n " $KOKORO_BUILD_NUMBER " ]; then
192- upgrade_kokoro_bazel_if_needed
193- fi
194-
195- # Output the affected targets to the logs. This also gives the affected_targets script the
196- # opportunity to fail.
197- scripts/affected_targets " $bazel_kind " " $base_sha ...HEAD"
198-
199- # `TARGET` is then all bazel targets affected by changes in the commit range between `base_sha`
200- # and `HEAD`. By default, that becomes all changes between the `develop` branch and the latest
201- # commit.
202- TARGET=" $( scripts/affected_targets $bazel_kind $base_sha ...HEAD) "
203-
204- if [ -n " $KOKORO_BUILD_NUMBER " ]; then
205- popd >> /dev/null
206- fi
207- fi
208-
209- if [ -z " $TARGET " ]; then
210- echo " Nothing to build."
211- exit 0
212- fi
213-
214- comment_identifier=" affected-targets"
215-
216- if [ -z " $TARGET " ]; then
217- echo " Nothing to build."
218-
219- if [ -n " $GITHUB_API_TOKEN " ]; then
220- delete_comment " $comment_identifier "
221- fi
222-
223- exit 0
224- else
225- if [ -n " $GITHUB_API_TOKEN " ]; then
226- comment_tmp_path=$( mktemp -d)
227- comment_tmp_file=" $comment_tmp_path /comment.tmp"
228- echo " bazel detected changes to the following targets:" > " $comment_tmp_file "
229- echo >> " $comment_tmp_file "
230- echo ' ```' >> " $comment_tmp_file "
231- echo " $TARGET " >> " $comment_tmp_file "
232- echo ' ```' >> " $comment_tmp_file "
233-
234- post_comment " $comment_identifier " " $comment_tmp_file "
235- fi
236- fi
237-
238- run_bazel
239- }
240-
241- run_bazel () {
242- echo " Running bazel builds..."
243-
244- if [ -n " $KOKORO_BUILD_NUMBER " ]; then
245- move_derived_data_to_tmp
246- fi
247-
248- if [ -n " $KOKORO_BUILD_NUMBER " ]; then
249- upgrade_kokoro_bazel_if_needed
250- fi
251-
252- if [ -n " $VERBOSE_OUTPUT " ]; then
253- verbosity_args=" -s"
254- fi
255-
256- if [ -z " $COMMAND " ]; then
257- COMMAND=" test"
258- fi
259- if [ -z " $TARGET " ]; then
260- TARGET=" //..."
261- fi
262-
263- if [ -n " $KOKORO_BUILD_NUMBER " ]; then
264- select_xcode " $XCODE_VERSION "
265-
266- # Move into our cloned repo
267- cd github/repo
268- fi
269-
270- # Run against whichever Xcode is currently selected.
271- selected_xcode_developer_path=$( xcode-select -p)
272- selected_xcode_contents_path=$( dirname " $selected_xcode_developer_path " )
273-
274- xcode_version=$( cat " $selected_xcode_contents_path /version.plist" \
275- | grep " CFBundleShortVersionString" -A1 \
276- | grep string \
277- | cut -d' >' -f2 \
278- | cut -d' <' -f1)
279-
280- if [ " $COMMAND " == " build" ]; then
281- echo " 🏗️ $COMMAND with Xcode $xcode_version ..."
282- elif [ " $COMMAND " == " test" ]; then
283- echo " 🛠️ $COMMAND with Xcode $xcode_version ..."
284-
285- if [ -n " $VERBOSE_OUTPUT " ]; then
286- extra_args=" --test_output=all"
287- else
288- extra_args=" --test_output=errors"
289- fi
290- fi
291-
292- fix_bazel_imports
293- if [ -n " $KOKORO_ARTIFACTS_DIR " ]; then
294- # Especially in the event of failure, we want our test artifacts to be uploaded.
295- trap upload_bazel_test_artifacts EXIT
296- fi
297-
298- snapshot_dir=" ${repo_dir} /snapshot_test_goldens/goldens"
299- tmp_img_dir=" $( mktemp -d) "
300-
301- # Install git lfs if we're performing tests on kokoro
302- if [ -n " $KOKORO_BUILD_NUMBER " ] || [ -n " $AUTOBOT_BUILD_NUMBER " ]; then
303- if [ " $COMMAND " == " test" ]; then
304- brew_install git-lfs
305- git lfs install
306- git lfs pull
307-
308- # Reset the simulators to prepare for hosted snapshot tests
309- sim_cleaner_tmp=$( mktemp -d)
310- git clone https://github.com/material-foundation/ios-simulator-utils.git " $sim_cleaner_tmp "
311- source " ${sim_cleaner_tmp} /scripts/cleanup_simulators.sh"
312- perform_pre_test_cleanup " iPhone"
313- fi
314- fi
315-
316- # Configure CI mode
317- if [ -n " $KOKORO_BUILD_NUMBER " ]; then
318- ci_mode=" kokoro"
319- elif [ -n " $AUTOBOT_BUILD_NUMBER " ]; then
320- ci_mode=" autobot"
321- fi
322-
323- bazel $COMMAND $TARGET --xcode_version $xcode_version --ios_minimum_os=9.0 \
324- --ios_multi_cpus=i386,x86_64 $extra_args $verbosity_args \
325- --test_env=" FB_REFERENCE_IMAGE_DIR=$snapshot_dir " \
326- --test_env=" IMAGE_DIFF_DIR=$tmp_img_dir " \
327- --define ci_mode=$ci_mode
328- }
329-
33053run_cocoapods () {
33154 echo " Running cocoapods builds..."
33255
@@ -611,8 +334,6 @@ if [ -n "$VERBOSE_OUTPUT" ]; then
611334fi
612335
613336case " $DEPENDENCY_SYSTEM " in
614- " bazel" ) run_bazel ;;
615- " bazel-affected" ) run_bazel_affected ;;
616337 " cocoapods" ) run_cocoapods ;;
617338 " cocoapods-podspec" ) run_cocoapods ;;
618339 " website" ) generate_website ;;
0 commit comments