• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/bash
2#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -e
18
19. "$(dirname $0)/buildbot-utils.sh"
20
21shopt -s failglob
22
23if [ ! -d art ]; then
24  msgerror "Script needs to be run at the root of the Android tree"
25  exit 1
26fi
27
28# Logic for setting out_dir from build/make/core/envsetup.mk:
29if [[ -z $OUT_DIR ]]; then
30  if [[ -z $OUT_DIR_COMMON_BASE ]]; then
31    out_dir=out
32  else
33    out_dir=${OUT_DIR_COMMON_BASE}/${PWD##*/}
34  fi
35else
36  out_dir=${OUT_DIR}
37fi
38
39# On master-art, we need to copy ART-local riscv64 prebuilts for conscrypt and
40# statsd into their own repositories, as mainline doesn't support riscv64 yet.
41# Android.bp file changes are stored as patch files which need to be applied
42# afterwards.
43#
44# TODO(b/286551985): Remove this after riscv64 support is added to mainline.
45if [[ $TARGET_ARCH = "riscv64" && ! ( -d frameworks/base ) ]]; then
46  msginfo "Copying prebuilt dependencies for riscv64"
47  cp -u -r prebuilts/runtime/mainline/local_riscv64/prebuilts/module_sdk/conscrypt \
48    prebuilts/module_sdk
49  cp -u -r prebuilts/runtime/mainline/local_riscv64/prebuilts/module_sdk/StatsD \
50    prebuilts/module_sdk
51  for patch_file in $(find prebuilts/module_sdk -name Android.bp.patch) ; do
52    bp_file=${patch_file%.patch}
53    # Only apply the patches if they haven't been applied already. Assume the
54    # patch files contain the bug number, and look for that.
55    if grep -q b/286551985 $bp_file ; then
56      msginfo "Patch for riscv64 already present in $bp_file"
57    else
58      patch -f $bp_file < $patch_file
59    fi
60  done
61fi
62
63java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES
64common_targets="vogar core-tests core-ojtests apache-harmony-jdwp-tests-hostdex jsr166-tests libartpalette-system mockito-target desugar"
65# These build targets have different names on device and host.
66specific_targets="libjavacoretests libwrapagentproperties libwrapagentpropertiesd"
67build_host="no"
68build_target="no"
69installclean="no"
70skip_run_tests_build="no"
71j_arg="-j$(nproc)"
72showcommands=
73make_command=
74
75while true; do
76  if [[ "$1" == "--host" ]]; then
77    build_host="yes"
78    shift
79  elif [[ "$1" == "--target" ]]; then
80    build_target="yes"
81    shift
82  elif [[ "$1" == "--installclean" ]]; then
83    installclean="yes"
84    shift
85  elif [[ "$1" == "--skip-run-tests-build" ]]; then
86    skip_run_tests_build="yes"
87    shift
88  elif [[ "$1" == -j* ]]; then
89    j_arg=$1
90    shift
91  elif [[ "$1" == "--showcommands" ]]; then
92    showcommands="showcommands"
93    shift
94  elif [[ "$1" == "--dist" ]]; then
95    common_targets="$common_targets dist"
96    shift
97  elif [[ "$1" == "" ]]; then
98    break
99  else
100    msgerror "Unknown options: $@"
101    exit 1
102  fi
103done
104
105# If neither was selected, build both by default.
106if [[ $build_host == "no" ]] && [[ $build_target == "no" ]]; then
107  build_host="yes"
108  build_target="yes"
109fi
110
111implementation_libs=(
112  "heapprofd_client_api"
113  "libandroid_runtime_lazy"
114  "libartpalette-system"
115  "libbinder"
116  "libbinder_ndk"
117  "libcutils"
118  "libutils"
119  "libvndksupport"
120)
121
122if [ -d frameworks/base ]; then
123  # In full manifest branches, build the implementation libraries from source
124  # instead of using prebuilts.
125  common_targets="$common_targets ${implementation_libs[*]}"
126else
127  # Necessary to build successfully in master-art.
128  extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true"
129  # Switch the build system to unbundled mode in the reduced manifest branch.
130  extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true"
131fi
132
133apexes=(
134  "com.android.art.testing"
135  "com.android.conscrypt"
136  "com.android.i18n"
137  "com.android.runtime"
138  "com.android.tzdata"
139  "com.android.os.statsd"
140)
141
142make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands $common_targets"
143if [[ $build_host == "yes" ]]; then
144  make_command+=" build-art-host-gtests"
145  test $skip_run_tests_build == "yes" || make_command+=" build-art-host-run-tests"
146  make_command+=" dx-tests junit-host libjdwp-host"
147  for LIB in ${specific_targets} ; do
148    make_command+=" $LIB-host"
149  done
150fi
151if [[ $build_target == "yes" ]]; then
152  if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then
153    msgerror 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
154    exit 1
155  fi
156  make_command+=" build-art-target-gtests"
157  test $skip_run_tests_build == "yes" || make_command+=" build-art-target-run-tests"
158  make_command+=" debuggerd sh su toybox"
159  # Indirect dependencies in the platform, e.g. through heapprofd_client_api.
160  # These are built to go into system/lib(64) to be part of the system linker
161  # namespace.
162  make_command+=" libnetd_client-target libprocinfo libtombstoned_client libunwindstack"
163  # Stubs for other APEX SDKs, for use by vogar. Referenced from DEVICE_JARS in
164  # external/vogar/src/vogar/ModeId.java.
165  # Note these go into out/target/common/obj/JAVA_LIBRARIES which isn't removed
166  # by "m installclean".
167  make_command+=" i18n.module.public.api.stubs conscrypt.module.public.api.stubs"
168  # Targets required to generate a linker configuration for device within the
169  # chroot environment. The *.libraries.txt targets are required by
170  # the source linkerconfig but not included in the prebuilt one.
171  make_command+=" linkerconfig conv_linker_config sanitizer.libraries.txt llndk.libraries.txt"
172  # Additional targets needed for the chroot environment.
173  make_command+=" event-log-tags"
174  # Needed to extract prebuilt APEXes.
175  make_command+=" deapexer"
176  # Needed to generate the primary boot image for testing.
177  make_command+=" generate-boot-image"
178  # Data file needed by the `ArtExecTest.SetTaskProfiles` test.
179  make_command+=" task_profiles.json"
180  # Build/install the required APEXes.
181  make_command+=" ${apexes[*]}"
182  make_command+=" ${specific_targets}"
183fi
184
185if [[ $installclean == "yes" ]]; then
186  msginfo "Perform installclean"
187  ANDROID_QUIET_BUILD=true build/soong/soong_ui.bash --make-mode $extra_args installclean
188  # The common java library directory is not cleaned up by installclean. Do that
189  # explicitly to not overcache them in incremental builds.
190  rm -rf $java_libraries_dir
191else
192  msgwarning "Missing --installclean argument to buildbot-build.sh"
193  msgwarning "This is usually ok, but may cause rare odd failures."
194  echo ""
195fi
196
197msginfo "Executing" "$make_command"
198# Disable path restrictions to enable luci builds using vpython.
199eval "$make_command"
200
201if [[ $build_target == "yes" ]]; then
202  if [[ -z "${ANDROID_HOST_OUT}" ]]; then
203    msgwarning "ANDROID_HOST_OUT environment variable is empty; using $out_dir/host/linux-x86"
204    ANDROID_HOST_OUT=$out_dir/host/linux-x86
205  fi
206
207  # Extract prebuilt APEXes.
208  debugfs=$ANDROID_HOST_OUT/bin/debugfs_static
209  fsckerofs=$ANDROID_HOST_OUT/bin/fsck.erofs
210  for apex in ${apexes[@]}; do
211    dir="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
212    apexbase="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
213    unset file
214    if [ -f "${apexbase}.apex" ]; then
215      file="${apexbase}.apex"
216    elif [ -f "${apexbase}.capex" ]; then
217      file="${apexbase}.capex"
218    fi
219    if [ -n "${file}" ]; then
220      msginfo "Extracting APEX file:" "${file}"
221      rm -rf $dir
222      mkdir -p $dir
223      $ANDROID_HOST_OUT/bin/deapexer --debugfs_path $debugfs --fsckerofs_path $fsckerofs \
224        extract $file $dir
225    fi
226  done
227
228  # Replace stub libraries with implementation libraries: because we do chroot
229  # testing, we need to install an implementation of the libraries (and cannot
230  # rely on the one already installed on the device, if the device is post R and
231  # has it).
232  if [ -d prebuilts/runtime/mainline/platform/impl -a ! -d frameworks/base ]; then
233    if [[ $TARGET_ARCH = arm* ]]; then
234      arch32=arm
235      arch64=arm64
236    elif [[ $TARGET_ARCH = riscv64 ]]; then
237      arch32=none # there is no 32-bit arch for RISC-V
238      arch64=riscv64
239    else
240      arch32=x86
241      arch64=x86_64
242    fi
243    for so in ${implementation_libs[@]}; do
244      if [ -d "$ANDROID_PRODUCT_OUT/system/lib" -a $arch32 != none ]; then
245        cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch32/${so}.so $ANDROID_PRODUCT_OUT/system/lib/${so}.so"
246        msginfo "Executing" "$cmd"
247        eval "$cmd"
248      fi
249      if [ -d "$ANDROID_PRODUCT_OUT/system/lib64" -a $arch64 != none ]; then
250        cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch64/${so}.so $ANDROID_PRODUCT_OUT/system/lib64/${so}.so"
251        msginfo "Executing" "$cmd"
252        eval "$cmd"
253      fi
254    done
255  fi
256
257  # Create canonical name -> file name symlink in the symbol directory for the
258  # Testing ART APEX.
259  #
260  # This mimics the logic from `art/Android.mk`. We made the choice not to
261  # implement this in `art/Android.mk`, as the Testing ART APEX is a test artifact
262  # that should never ship with an actual product, and we try to keep it out of
263  # standard build recipes
264  #
265  # TODO(b/141004137, b/129534335): Remove this, expose the Testing ART APEX in
266  # the `art/Android.mk` build logic, and add absence checks (e.g. in
267  # `build/make/core/main.mk`) to prevent the Testing ART APEX from ending up in a
268  # system image.
269  target_out_unstripped="$ANDROID_PRODUCT_OUT/symbols"
270  link_name="$target_out_unstripped/apex/com.android.art"
271  link_command="mkdir -p $(dirname "$link_name") && ln -sf com.android.art.testing \"$link_name\""
272  msginfo "Executing" "$link_command"
273  eval "$link_command"
274
275  # Temporary fix for libjavacrypto.so dependencies in libcore and jvmti tests (b/147124225).
276  conscrypt_dir="$ANDROID_PRODUCT_OUT/system/apex/com.android.conscrypt"
277  conscrypt_libs="libjavacrypto.so libcrypto.so libssl.so"
278  if [ ! -d "${conscrypt_dir}" ]; then
279    msgerror "Missing conscrypt APEX in build output: ${conscrypt_dir}"
280    exit 1
281  fi
282  if [ ! -f "${conscrypt_dir}/javalib/conscrypt.jar" ]; then
283    msgerror "Missing conscrypt jar in build output: ${conscrypt_dir}"
284    exit 1
285  fi
286  for l in lib lib64; do
287    if [ ! -d "$ANDROID_PRODUCT_OUT/system/$l" ]; then
288      continue
289    fi
290    for so in $conscrypt_libs; do
291      src="${conscrypt_dir}/${l}/${so}"
292      dst="$ANDROID_PRODUCT_OUT/system/${l}/${so}"
293      if [ "${src}" -nt "${dst}" ]; then
294        cmd="cp -p \"${src}\" \"${dst}\""
295        msginfo "Executing" "$cmd"
296        eval "$cmd"
297      fi
298    done
299  done
300
301  # TODO(b/159355595): Ensure there is a tzdata in system to avoid warnings on
302  # stderr from Bionic.
303  if [ ! -f $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata ]; then
304    mkdir -p $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo
305    cp $ANDROID_PRODUCT_OUT/system/apex/com.android.tzdata/etc/tz/tzdata \
306      $ANDROID_PRODUCT_OUT/system/usr/share/zoneinfo/tzdata
307  fi
308
309  # Create system symlinks for the Runtime APEX. Normally handled by
310  # installSymlinkToRuntimeApex in soong/cc/binary.go, but we have to replicate
311  # it here since we don't run the install rules for the Runtime APEX.
312  for b in linker{,_asan}{,64}; do
313    msginfo "Symlinking" "/apex/com.android.runtime/bin/$b to /system/bin"
314    ln -sf /apex/com.android.runtime/bin/$b $ANDROID_PRODUCT_OUT/system/bin/$b
315  done
316  for d in $ANDROID_PRODUCT_OUT/system/apex/com.android.runtime/lib{,64}/bionic; do
317    if [ -d $d ]; then
318      for p in $d/*; do
319        lib_dir=$(expr $p : '.*/\(lib[0-9]*\)/.*')
320        lib_file=$(basename $p)
321        src=/apex/com.android.runtime/${lib_dir}/bionic/${lib_file}
322        dst=$ANDROID_PRODUCT_OUT/system/${lib_dir}/${lib_file}
323        msginfo "Symlinking" "$src into /system/${lib_dir}"
324        mkdir -p $(dirname $dst)
325        ln -sf $src $dst
326      done
327    fi
328  done
329
330  # Create linker config files. We run linkerconfig on host to avoid problems
331  # building it statically for device in an unbundled tree.
332
333  # temporary root for linkerconfig
334  linkerconfig_root=$ANDROID_PRODUCT_OUT/art_linkerconfig_root
335
336  rm -rf $linkerconfig_root
337
338  # Linkerconfig reads files from /system/etc
339  mkdir -p $linkerconfig_root/system
340  cp -r $ANDROID_PRODUCT_OUT/system/etc $linkerconfig_root/system
341
342  # Use our smaller public.libraries.txt that contains only the public libraries
343  # pushed to the chroot directory.
344  cp $ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt \
345    $linkerconfig_root/system/etc/public.libraries.txt
346
347  # For linkerconfig to pick up the APEXes correctly we need to make them
348  # available in $linkerconfig_root/apex.
349  mkdir -p $linkerconfig_root/apex
350  for apex in ${apexes[@]}; do
351    src="$ANDROID_PRODUCT_OUT/system/apex/${apex}"
352    if [[ $apex == com.android.art.* ]]; then
353      dst="$linkerconfig_root/apex/com.android.art"
354    else
355      dst="$linkerconfig_root/apex/${apex}"
356    fi
357    msginfo "Copying APEX directory" "from $src to $dst"
358    rm -rf $dst
359    cp -r $src $dst
360  done
361
362  # Linkerconfig also looks at /apex/apex-info-list.xml to check for system APEXes.
363  apex_xml_file=$linkerconfig_root/apex/apex-info-list.xml
364  msginfo "Creating" "$apex_xml_file"
365  cat <<EOF > $apex_xml_file
366<?xml version="1.0" encoding="utf-8"?>
367<apex-info-list>
368EOF
369  for apex in ${apexes[@]}; do
370    [[ $apex == com.android.art.* ]] && apex=com.android.art
371    cat <<EOF >> $apex_xml_file
372    <apex-info moduleName="${apex}" modulePath="/system/apex/${apex}.apex" preinstalledModulePath="/system/apex/${apex}.apex" versionCode="1" versionName="" isFactory="true" isActive="true">
373    </apex-info>
374EOF
375  done
376  cat <<EOF >> $apex_xml_file
377</apex-info-list>
378EOF
379
380  system_linker_config_pb=$linkerconfig_root/system/etc/linker.config.pb
381  # This list needs to be synced with provideLibs in system/etc/linker.config.pb
382  # in the targeted platform image.
383  # TODO(b/186649223): Create a prebuilt for it in platform-mainline-sdk.
384  system_provide_libs=(
385    heapprofd_client_api.so
386    libEGL.so
387    libGLESv1_CM.so
388    libGLESv2.so
389    libGLESv3.so
390    libOpenMAXAL.so
391    libOpenSLES.so
392    libRS.so
393    libaaudio.so
394    libadbd_auth.so
395    libadbd_fs.so
396    libamidi.so
397    libandroid.so
398    libandroid_net.so
399    libartpalette-system.so
400    libbinder_ndk.so
401    libc.so
402    libcamera2ndk.so
403    libcgrouprc.so
404    libclang_rt.asan-i686-android.so
405    libclang_rt.asan-x86_64-android.so
406    libdl.so
407    libdl_android.so
408    libft2.so
409    libincident.so
410    libjnigraphics.so
411    liblog.so
412    libm.so
413    libmediametrics.so
414    libmediandk.so
415    libnativewindow.so
416    libneuralnetworks_packageinfo.so
417    libselinux.so
418    libstdc++.so
419    libsync.so
420    libvndksupport.so
421    libvulkan.so
422    libz.so
423  )
424
425  msginfo "Encoding linker.config.json" "to $system_linker_config_pb"
426  $ANDROID_HOST_OUT/bin/conv_linker_config proto -s $ANDROID_BUILD_TOP/system/core/rootdir/etc/linker.config.json -o $system_linker_config_pb
427  $ANDROID_HOST_OUT/bin/conv_linker_config append -s $system_linker_config_pb -o $system_linker_config_pb --key "provideLibs" --value "${system_provide_libs[*]}"
428
429  # To avoid warnings from linkerconfig when it checks following two partitions
430  mkdir -p $linkerconfig_root/product
431  mkdir -p $linkerconfig_root/system_ext
432
433  platform_version=$(build/soong/soong_ui.bash --dumpvar-mode PLATFORM_VERSION)
434  linkerconfig_out=$ANDROID_PRODUCT_OUT/linkerconfig
435  msginfo "Generating linkerconfig" "in $linkerconfig_out"
436  rm -rf $linkerconfig_out
437  mkdir -p $linkerconfig_out
438  $ANDROID_HOST_OUT/bin/linkerconfig --target $linkerconfig_out --root $linkerconfig_root
439fi
440