Alex Light | a02094f | 2018-12-11 10:41:52 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2018 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 | |
| 17 | # This will build a target using linux_bionic. It can be called with normal make |
| 18 | # flags. |
| 19 | # |
| 20 | # TODO This runs a 'm clean' prior to building the targets in order to ensure |
| 21 | # that obsolete kati files don't mess up the build. |
| 22 | |
| 23 | if [[ -z $ANDROID_BUILD_TOP ]]; then |
| 24 | pushd . |
| 25 | else |
| 26 | pushd $ANDROID_BUILD_TOP |
| 27 | fi |
| 28 | |
| 29 | if [ ! -d art ]; then |
| 30 | echo "Script needs to be run at the root of the android tree" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
Martin Stjernholm | f7e4c3d | 2021-07-23 00:17:36 +0100 | [diff] [blame] | 34 | # TODO(b/194433871): Set MODULE_BUILD_FROM_SOURCE to disable prebuilt modules, |
Colin Cross | 0a42f1e | 2021-10-28 16:31:03 -0700 | [diff] [blame] | 35 | # which Soong otherwise can create duplicate install rules for in --soong-only |
Martin Stjernholm | f7e4c3d | 2021-07-23 00:17:36 +0100 | [diff] [blame] | 36 | # mode. |
| 37 | soong_args="MODULE_BUILD_FROM_SOURCE=true" |
Martin Stjernholm | 6906910 | 2020-06-16 13:26:40 +0100 | [diff] [blame] | 38 | |
| 39 | # Switch the build system to unbundled mode in the reduced manifest branch. |
Martin Stjernholm | 6906910 | 2020-06-16 13:26:40 +0100 | [diff] [blame] | 40 | if [ ! -d frameworks/base ]; then |
| 41 | soong_args="$soong_args TARGET_BUILD_UNBUNDLED=true" |
| 42 | fi |
| 43 | |
Alex Light | a02094f | 2018-12-11 10:41:52 -0800 | [diff] [blame] | 44 | source build/envsetup.sh >&/dev/null # for get_build_var |
| 45 | # Soong needs a bunch of variables set and will not run if they are missing. |
| 46 | # The default values of these variables is only contained in make, so use |
| 47 | # nothing to create the variables then remove all the other artifacts. |
Alex Light | ba2add1 | 2020-03-09 13:48:20 -0700 | [diff] [blame] | 48 | # Lunch since it seems we cannot find the build-number otherwise. |
| 49 | lunch aosp_x86-eng |
Martin Stjernholm | 6906910 | 2020-06-16 13:26:40 +0100 | [diff] [blame] | 50 | build/soong/soong_ui.bash --make-mode $soong_args nothing |
Alex Light | a6ea602 | 2019-01-29 11:02:03 -0800 | [diff] [blame] | 51 | |
Alex Light | a02094f | 2018-12-11 10:41:52 -0800 | [diff] [blame] | 52 | if [ $? != 0 ]; then |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
| 56 | out_dir=$(get_build_var OUT_DIR) |
| 57 | host_out=$(get_build_var HOST_OUT) |
| 58 | |
| 59 | # TODO(b/31559095) Figure out a better way to do this. |
| 60 | # |
| 61 | # There is no good way to force soong to generate host-bionic builds currently |
| 62 | # so this is a hacky workaround. |
| 63 | tmp_soong_var=$(mktemp --tmpdir soong.variables.bak.XXXXXX) |
Alex Light | ba2add1 | 2020-03-09 13:48:20 -0700 | [diff] [blame] | 64 | tmp_build_number=$(cat ${out_dir}/soong/build_number.txt) |
Alex Light | a02094f | 2018-12-11 10:41:52 -0800 | [diff] [blame] | 65 | |
| 66 | cat $out_dir/soong/soong.variables > ${tmp_soong_var} |
Alex Light | cefcbc0 | 2018-12-21 09:45:03 -0800 | [diff] [blame] | 67 | |
Alex Light | a6ea602 | 2019-01-29 11:02:03 -0800 | [diff] [blame] | 68 | # See comment above about b/123645297 for why we cannot just do m clean. Clear |
Paul Duffin | f2e1bc7 | 2021-04-23 10:51:25 +0100 | [diff] [blame] | 69 | # out all files except for intermediates and installed files and dexpreopt.config. |
Alex Light | a6ea602 | 2019-01-29 11:02:03 -0800 | [diff] [blame] | 70 | find $out_dir/ -maxdepth 1 -mindepth 1 \ |
| 71 | -not -name soong \ |
| 72 | -not -name host \ |
| 73 | -not -name target | xargs -I '{}' rm -rf '{}' |
| 74 | find $out_dir/soong/ -maxdepth 1 -mindepth 1 \ |
| 75 | -not -name .intermediates \ |
| 76 | -not -name host \ |
Paul Duffin | f2e1bc7 | 2021-04-23 10:51:25 +0100 | [diff] [blame] | 77 | -not -name dexpreopt.config \ |
Alex Light | a6ea602 | 2019-01-29 11:02:03 -0800 | [diff] [blame] | 78 | -not -name target | xargs -I '{}' rm -rf '{}' |
Alex Light | a02094f | 2018-12-11 10:41:52 -0800 | [diff] [blame] | 79 | |
| 80 | python3 <<END - ${tmp_soong_var} ${out_dir}/soong/soong.variables |
| 81 | import json |
| 82 | import sys |
| 83 | x = json.load(open(sys.argv[1])) |
| 84 | x['Allow_missing_dependencies'] = True |
| 85 | x['HostArch'] = 'x86_64' |
| 86 | x['CrossHost'] = 'linux_bionic' |
| 87 | x['CrossHostArch'] = 'x86_64' |
| 88 | if 'CrossHostSecondaryArch' in x: |
| 89 | del x['CrossHostSecondaryArch'] |
Alex Light | a02094f | 2018-12-11 10:41:52 -0800 | [diff] [blame] | 90 | json.dump(x, open(sys.argv[2], mode='w')) |
| 91 | END |
| 92 | |
| 93 | rm $tmp_soong_var |
| 94 | |
Alex Light | 3cddf45 | 2019-05-22 11:22:31 -0700 | [diff] [blame] | 95 | # Write a new build-number |
Alex Light | ba2add1 | 2020-03-09 13:48:20 -0700 | [diff] [blame] | 96 | echo ${tmp_build_number}_SOONG_ONLY_BUILD > ${out_dir}/soong/build_number.txt |
Alex Light | 3cddf45 | 2019-05-22 11:22:31 -0700 | [diff] [blame] | 97 | |
Colin Cross | 0a42f1e | 2021-10-28 16:31:03 -0700 | [diff] [blame] | 98 | build/soong/soong_ui.bash --make-mode --skip-config --soong-only $soong_args $@ |