| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import("//build/config/nacl/rules.gni") | 5 import("//build/config/nacl/rules.gni") |
| 6 | 6 |
| 7 assert(enable_nacl) | 7 assert(enable_nacl) |
| 8 | 8 |
| 9 if (current_cpu == "pnacl") { | 9 if (current_cpu == "pnacl") { |
| 10 if (is_nacl_nonsfi) { | 10 if (is_nacl_nonsfi) { |
| 11 nacl_toolchain_variant = "nonsfi" | 11 nacl_toolchain_variant = "nonsfi" |
| 12 } else { | 12 } else { |
| 13 nacl_toolchain_variant = "pnacl" | 13 nacl_toolchain_variant = "pnacl" |
| 14 } | 14 } |
| 15 } else if (is_nacl_glibc) { | 15 } else if (is_nacl_glibc) { |
| 16 nacl_toolchain_variant = "glibc" | 16 nacl_toolchain_variant = "glibc" |
| 17 } else { | 17 } else { |
| 18 nacl_toolchain_variant = "newlib" | 18 nacl_toolchain_variant = "newlib" |
| 19 } | 19 } |
| 20 | 20 |
| 21 # Assemble data for Native Client based test | 21 # Assemble data for Native Client based test |
| 22 # | 22 # |
| 23 # Build a Native Client based test, including any additional support files | 23 # Build a Native Client based test, including any additional support files |
| 24 # and copy them over to a toolchain-specific target directory. | 24 # and copy them over to a toolchain-specific target directory. |
| 25 # | 25 # |
| 26 # Variables: | 26 # Variables: |
| 27 # output_name: name of the ouput file other than the default | 27 # output_name: name of the ouput file other than the default |
| 28 # sources: source files for a target | 28 # sources: source files for a target |
| 29 # generate_nmf: whether to generate a manifest (default true) | 29 # generate_nmf: whether to generate a manifest (default true) |
| 30 # nonstable_pexe: use non-finalized pexe | 30 # pretranslate_pexe: whether to pre-translate pexe to nexe during build |
| 31 # debug_pexe: copy both non-finalized and finalized pexe | 31 # (default true for Non-SFI, otherwise false) |
| 32 # destination_dir: the output directory relative to the $root_build_dir | 32 # nonstable_pexe: use non-finalized pexe (default false) |
| 33 # test_files: additional test files to copy to $destination_dir | 33 # debug_pexe: copy both non-finalized and finalized pexe (default false) |
| 34 # nmfflags: additional flags for the nmf generator | 34 # destination_dir: the output directory relative to the $root_build_dir, |
| 35 # if ommitted the output directory is $root_build_dir and the manifest |
| 36 # will be suffixed with the name of the toolchain (optional) |
| 37 # test_files: additional test files to copy to $destination_dir (optional) |
| 38 # nmfflags: additional flags for the nmf generator (optional) |
| 35 template("nacl_test_data") { | 39 template("nacl_test_data") { |
| 36 assert(defined(invoker.sources)) | 40 assert(defined(invoker.sources)) |
| 37 assert(defined(invoker.destination_dir)) | |
| 38 forward_variables_from(invoker, [ "destination_dir" ]) | 41 forward_variables_from(invoker, [ "destination_dir" ]) |
| 39 | 42 |
| 40 if (defined(invoker.output_name)) { | 43 if (defined(invoker.output_name)) { |
| 41 output_name = invoker.output_name | 44 output_name = invoker.output_name |
| 42 } else { | 45 } else { |
| 43 output_name = target_name | 46 output_name = target_name |
| 44 } | 47 } |
| 45 | 48 |
| 46 if (current_cpu == "x64") { | 49 if (current_cpu == "x64") { |
| 47 nmf_cpu = "x86_64" | 50 nmf_cpu = "x86_64" |
| 48 } else if (current_cpu == "x86") { | 51 } else if (current_cpu == "x86") { |
| 49 nmf_cpu = "x86_32" | 52 nmf_cpu = "x86_32" |
| 50 } else { | 53 } else { |
| 51 nmf_cpu = current_cpu | 54 nmf_cpu = current_cpu |
| 52 } | 55 } |
| 53 if (is_nacl_glibc) { | 56 if (is_nacl_glibc) { |
| 54 suffix = "glibc_${nmf_cpu}" | 57 suffix = "glibc_${nmf_cpu}" |
| 55 } else { | 58 } else { |
| 56 suffix = "newlib_${nmf_cpu}" | 59 suffix = "newlib_${nmf_cpu}" |
| 57 } | 60 } |
| 58 suffixed_output_name = "${output_name}_${suffix}" | 61 suffixed_output_name = "${output_name}_${suffix}" |
| 62 if (current_cpu == "pnacl") { |
| 63 if (defined(invoker.pretranslate_pexe)) { |
| 64 pretranslate_pexe = invoker.pretranslate_pexe |
| 65 } else { |
| 66 pretranslate_pexe = is_nacl_nonsfi |
| 67 } |
| 68 if (pretranslate_pexe) { |
| 69 pexe_translate_target_name = target_name + "_translate_pexe" |
| 70 } |
| 71 } |
| 59 if (defined(invoker.generate_nmf)) { | 72 if (defined(invoker.generate_nmf)) { |
| 60 generate_nmf = invoker.generate_nmf | 73 generate_nmf = invoker.generate_nmf |
| 61 } else { | 74 } else { |
| 62 generate_nmf = true | 75 generate_nmf = true |
| 63 } | 76 } |
| 64 nexe_target_name = target_name + "_nexe" | 77 nexe_target_name = target_name + "_nexe" |
| 65 if (is_nacl_nonsfi) { | |
| 66 pexe_translate_target_name = target_name + "_translate_pexe" | |
| 67 } | |
| 68 nexe_copy_target_name = target_name + "_copy_nexe" | 78 nexe_copy_target_name = target_name + "_copy_nexe" |
| 69 if (current_cpu == "pnacl" && !is_nacl_nonsfi) { | 79 if (current_cpu == "pnacl" && !is_nacl_nonsfi) { |
| 70 if (defined(invoker.debug_pexe) && invoker.debug_pexe) { | 80 if (defined(invoker.debug_pexe) && invoker.debug_pexe) { |
| 71 pexe_copy_debug_target_name = target_name + "_copy_pexe_debug" | 81 pexe_copy_debug_target_name = target_name + "_copy_pexe_debug" |
| 72 } | 82 } |
| 73 } | 83 } |
| 74 if (generate_nmf) { | 84 if (generate_nmf) { |
| 75 nmf_target_name = target_name + "_nmf" | 85 nmf_target_name = target_name + "_nmf" |
| 76 } | 86 } |
| 77 if (defined(invoker.test_files)) { | 87 if (defined(invoker.test_files)) { |
| 78 test_files_target_name = target_name + "_test_files" | 88 test_files_target_name = target_name + "_test_files" |
| 79 } | 89 } |
| 80 final_target_name = target_name | 90 final_target_name = target_name |
| 81 | 91 |
| 92 # When the destination_dir is specified, the build artifacts end up |
| 93 # in the that directory and the manifest is the same as the target name. |
| 94 # When the destination_dir is not specified, the artifacts end up |
| 95 # in the root build directory and the manifests are suffixed to ensure |
| 96 # they do not overlap in case when we build the same test using multiple |
| 97 # different toolchains. |
| 98 if (defined(invoker.destination_dir)) { |
| 99 target_dir = |
| 100 "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}" |
| 101 if (generate_nmf) { |
| 102 nmf_name = output_name |
| 103 } |
| 104 } else { |
| 105 target_dir = root_build_dir |
| 106 if (generate_nmf) { |
| 107 if (is_nacl_nonsfi) { |
| 108 nacl_toolchain_name = "pnacl_${nacl_toolchain_variant}" |
| 109 } else { |
| 110 nacl_toolchain_name = nacl_toolchain_variant |
| 111 } |
| 112 nmf_name = "${output_name}_${nacl_toolchain_name}" |
| 113 } |
| 114 } |
| 115 |
| 82 executable(nexe_target_name) { | 116 executable(nexe_target_name) { |
| 83 visibility = [ ":*" ] | 117 visibility = [ ":*" ] |
| 84 output_name = suffixed_output_name | 118 output_name = suffixed_output_name |
| 85 sources = invoker.sources | 119 sources = invoker.sources |
| 86 forward_variables_from(invoker, | 120 forward_variables_from(invoker, |
| 87 [ | 121 [ |
| 88 "cflags", | 122 "cflags", |
| 123 "defines", |
| 124 "include_dirs", |
| 89 "ldflags", | 125 "ldflags", |
| 90 "libs", | 126 "libs", |
| 91 ]) | 127 ]) |
| 92 deps = [ | 128 deps = [ |
| 93 "//build/config/nacl:nacl_base", | 129 "//build/config/nacl:nacl_base", |
| 94 "//ppapi/native_client:ppapi_lib", | 130 "//ppapi/native_client:ppapi_lib", |
| 95 ] | 131 ] |
| 96 ldflags = [ "-pthread" ] | 132 ldflags = [ "-pthread" ] |
| 97 if (defined(invoker.deps)) { | 133 if (defined(invoker.deps)) { |
| 98 deps += invoker.deps | 134 deps += invoker.deps |
| 99 } | 135 } |
| 100 } | 136 } |
| 101 | 137 |
| 102 if (is_nacl_nonsfi) { | 138 if (current_cpu == "pnacl" && pretranslate_pexe) { |
| 103 action(pexe_translate_target_name) { | 139 action(pexe_translate_target_name) { |
| 104 visibility = [ ":$nexe_copy_target_name" ] | 140 visibility = [ ":$nexe_copy_target_name" ] |
| 105 | 141 |
| 106 # We specify the toolchain explicitly because in the Non-SFI case, we | 142 # We specify the toolchain explicitly because in the Non-SFI case, we |
| 107 # still want to use the pexe built using the newlib_pnacl toolchain. | 143 # still want to use the pexe built using the newlib_pnacl toolchain. |
| 108 tests = ":$nexe_target_name(//build/toolchain/nacl:newlib_pnacl)" | 144 tests = ":ppapi_nacl_tests_nexe(//build/toolchain/nacl:newlib_pnacl)" |
| 109 | 145 |
| 110 pexe = get_label_info(tests, "root_out_dir") + | 146 pexe = get_label_info(tests, "root_out_dir") + |
| 111 "/${suffixed_output_name}.pexe" | 147 "/${suffixed_output_name}.pexe" |
| 112 if (target_cpu == "x86" || target_cpu == "x64") { | 148 if (target_cpu == "x86" || |
| 149 (is_nacl_nonsfi && (target_cpu == "x86" || target_cpu == "x64"))) { |
| 113 nmf_cpu = "x32" | 150 nmf_cpu = "x32" |
| 114 } else { | 151 } else { |
| 115 nmf_cpu = target_cpu | 152 nmf_cpu = target_cpu |
| 116 } | 153 } |
| 117 nexe = | 154 if (is_nacl_nonsfi) { |
| 118 "${root_out_dir}/${output_name}_pnacl_newlib_${nmf_cpu}_nonsfi.nexe" | 155 suffix = "pnacl_newlib_${nmf_cpu}_nonsfi" |
| 156 } else { |
| 157 suffix = "pnacl_newlib_${nmf_cpu}" |
| 158 } |
| 159 nexe = "${root_out_dir}/${output_name}_${suffix}.nexe" |
| 119 | 160 |
| 120 script = "${nacl_toolchain_bindir}/pydir/loader.py" | 161 script = "${nacl_toolchain_bindir}/pydir/loader.py" |
| 121 sources = [ | 162 sources = [ |
| 122 pexe, | 163 pexe, |
| 123 ] | 164 ] |
| 124 outputs = [ | 165 outputs = [ |
| 125 nexe, | 166 nexe, |
| 126 ] | 167 ] |
| 127 | 168 |
| 128 if (target_cpu == "x86" || target_cpu == "x64") { | 169 if (is_nacl_nonsfi) { |
| 129 arch = "x86-32-nonsfi" | 170 if (target_cpu == "x86" || target_cpu == "x64") { |
| 130 } else if (target_cpu == "arm") { | 171 arch = "x86-32-nonsfi" |
| 131 arch = "arm-nonsfi" | 172 } else if (target_cpu == "arm") { |
| 173 arch = "arm-nonsfi" |
| 174 } |
| 175 } else { |
| 176 # TODO(phosek): remove the following once change 1360243003 is rolled |
| 177 # into Chrome and use $target_cpu directly. |
| 178 if (target_cpu == "x86") { |
| 179 arch = "i686" |
| 180 } else if (target_cpu == "x64") { |
| 181 arch = "x86-64" |
| 182 } else if (target_cpu == "arm") { |
| 183 arch = "armv7" |
| 184 } |
| 132 } | 185 } |
| 133 | 186 |
| 134 pnacl_irt_shim = "//ppapi/native_client/src/untrusted/pnacl_irt_shim:aot(/
/build/toolchain/nacl:newlib_pnacl_nonsfi)" | 187 # The pre-translated object file has to be linked with an IRT shim to |
| 188 # get a runnable nexe. This is handled by pnacl-translate, which passes |
| 189 # -l:libpnacl_irt_shim.a to native linker, and we need to ensure the |
| 190 # linker can find the correct library. |
| 191 if (is_nacl_nonsfi) { |
| 192 pnacl_irt_shim = "//ppapi/native_client/src/untrusted/pnacl_irt_shim:aot
(//build/toolchain/nacl:newlib_pnacl_nonsfi)" |
| 193 } else { |
| 194 pnacl_irt_shim = "//ppapi/native_client/src/untrusted/pnacl_irt_shim:aot
(//build/toolchain/nacl:clang_newlib_${target_cpu})" |
| 195 } |
| 135 | 196 |
| 136 args = [ | 197 args = [ |
| 137 "pnacl-translate", | 198 "pnacl-translate", |
| 138 rebase_path(pexe, root_build_dir), | 199 rebase_path(pexe, root_build_dir), |
| 139 "-o", | 200 "-o", |
| 140 rebase_path(nexe, root_build_dir), | 201 rebase_path(nexe, root_build_dir), |
| 141 "-arch", | 202 "-arch", |
| 142 arch, | 203 arch, |
| 143 "-Wl,-L" + | 204 "-Wl,-L" + |
| 144 rebase_path(get_label_info(pnacl_irt_shim, "target_out_dir")), | 205 rebase_path(get_label_info(pnacl_irt_shim, "target_out_dir")), |
| 145 ] | 206 ] |
| 146 deps = [ | 207 deps = [ |
| 147 ":$nexe_target_name(//build/toolchain/nacl:newlib_pnacl)", | 208 ":$nexe_target_name(//build/toolchain/nacl:newlib_pnacl)", |
| 148 ] | 209 ] |
| 149 data_deps = [ | 210 data_deps = [ |
| 150 pnacl_irt_shim, | 211 pnacl_irt_shim, |
| 151 ] | 212 ] |
| 152 } | 213 } |
| 153 } | 214 } |
| 154 | 215 |
| 155 copy(nexe_copy_target_name) { | 216 copy(nexe_copy_target_name) { |
| 156 visibility = [ ":$final_target_name" ] | 217 visibility = [ ":$final_target_name" ] |
| 157 if (generate_nmf) { | 218 if (generate_nmf) { |
| 158 visibility += [ ":$nmf_target_name" ] | 219 visibility += [ ":$nmf_target_name" ] |
| 159 } | 220 } |
| 160 if (current_cpu == "pnacl" && !is_nacl_nonsfi) { | 221 if (current_cpu == "pnacl") { |
| 161 if (defined(invoker.nonstable_pexe) && invoker.nonstable_pexe) { | 222 if (pretranslate_pexe) { |
| 223 sources = get_target_outputs(":${pexe_translate_target_name}") |
| 224 } else if (defined(invoker.nonstable_pexe) && invoker.nonstable_pexe) { |
| 162 sources = [ | 225 sources = [ |
| 163 "${root_out_dir}/exe.unstripped/${suffixed_output_name}.pexe", | 226 "${root_out_dir}/exe.unstripped/${suffixed_output_name}.pexe", |
| 164 ] | 227 ] |
| 165 } else { | 228 } else { |
| 166 sources = [ | 229 sources = [ |
| 167 "${root_out_dir}/${suffixed_output_name}.pexe", | 230 "${root_out_dir}/${suffixed_output_name}.pexe", |
| 168 ] | 231 ] |
| 169 } | 232 } |
| 170 } else if (is_nacl_nonsfi) { | |
| 171 sources = get_target_outputs(":${pexe_translate_target_name}") | |
| 172 } else { | 233 } else { |
| 173 sources = [ | 234 sources = [ |
| 174 "${root_out_dir}/${suffixed_output_name}.nexe", | 235 "${root_out_dir}/${suffixed_output_name}.nexe", |
| 175 ] | 236 ] |
| 176 } | 237 } |
| 177 outputs = [ | 238 outputs = [ |
| 178 "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}/{{source_f
ile_part}}", | 239 "${target_dir}/{{source_file_part}}", |
| 179 ] | 240 ] |
| 180 if (is_nacl_nonsfi) { | 241 if (current_cpu == "pnacl" && pretranslate_pexe) { |
| 181 deps = [ | 242 deps = [ |
| 182 ":$pexe_translate_target_name", | 243 ":$pexe_translate_target_name", |
| 183 ] | 244 ] |
| 184 } else { | 245 } else { |
| 185 deps = [ | 246 deps = [ |
| 186 ":$nexe_target_name", | 247 ":$nexe_target_name", |
| 187 ] | 248 ] |
| 188 } | 249 } |
| 189 } | 250 } |
| 190 | 251 |
| 191 if (current_cpu == "pnacl" && !is_nacl_nonsfi) { | 252 if (current_cpu == "pnacl" && !is_nacl_nonsfi) { |
| 192 if (defined(invoker.debug_pexe) && invoker.debug_pexe) { | 253 if (defined(invoker.debug_pexe) && invoker.debug_pexe) { |
| 193 copy(pexe_copy_debug_target_name) { | 254 copy(pexe_copy_debug_target_name) { |
| 194 visibility = [ ":$final_target_name" ] | 255 visibility = [ ":$final_target_name" ] |
| 195 sources = [ | 256 sources = [ |
| 196 "${root_out_dir}/exe.unstripped/${suffixed_output_name}.pexe", | 257 "${root_out_dir}/exe.unstripped/${suffixed_output_name}.pexe", |
| 197 ] | 258 ] |
| 198 outputs = [ | 259 outputs = [ |
| 199 "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}/{{sour
ce_name_part}}.pexe.debug", | 260 "${target_dir}/{{source_name_part}}.pexe.debug", |
| 200 ] | 261 ] |
| 201 deps = [ | 262 deps = [ |
| 202 ":$nexe_target_name", | 263 ":$nexe_target_name", |
| 203 ] | 264 ] |
| 204 } | 265 } |
| 205 } | 266 } |
| 206 } | 267 } |
| 207 | 268 |
| 208 if (generate_nmf) { | 269 if (generate_nmf) { |
| 209 if (is_nacl_nonsfi) { | 270 if (is_nacl_nonsfi) { |
| 210 generate_nonsfi_test_nmf(nmf_target_name) { | 271 generate_nonsfi_test_nmf(nmf_target_name) { |
| 211 visibility = [ ":$final_target_name" ] | 272 visibility = [ ":$final_target_name" ] |
| 212 forward_variables_from(invoker, [ "nmfflags" ]) | 273 forward_variables_from(invoker, [ "nmfflags" ]) |
| 213 nmf = "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}/${
output_name}.nmf" | 274 nmf = "${target_dir}/${nmf_name}.nmf" |
| 214 files = get_target_outputs(":$nexe_copy_target_name") | 275 files = get_target_outputs(":$nexe_copy_target_name") |
| 215 executable = files[0] | 276 executable = files[0] |
| 216 deps = [ | 277 deps = [ |
| 217 ":$nexe_copy_target_name", | 278 ":$nexe_copy_target_name", |
| 218 ] | 279 ] |
| 219 } | 280 } |
| 220 } else { | 281 } else { |
| 221 generate_nmf(nmf_target_name) { | 282 generate_nmf(nmf_target_name) { |
| 222 visibility = [ ":$final_target_name" ] | 283 visibility = [ ":$final_target_name" ] |
| 223 forward_variables_from(invoker, [ "nmfflags" ]) | 284 forward_variables_from(invoker, [ "nmfflags" ]) |
| 224 nmf = "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}/${
output_name}.nmf" | 285 nmf = "${target_dir}/${nmf_name}.nmf" |
| 225 executables = get_target_outputs(":$nexe_copy_target_name") | 286 executables = get_target_outputs(":$nexe_copy_target_name") |
| 226 if (is_nacl_glibc) { | 287 if (is_nacl_glibc) { |
| 227 lib_prefix = "${output_name}_libs" | 288 lib_prefix = "${output_name}_libs" |
| 228 stage_dependencies = | 289 stage_dependencies = target_dir |
| 229 "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}" | |
| 230 } | 290 } |
| 231 deps = [ | 291 deps = [ |
| 232 ":$nexe_copy_target_name", | 292 ":$nexe_copy_target_name", |
| 233 ] | 293 ] |
| 234 } | 294 } |
| 235 } | 295 } |
| 236 } | 296 } |
| 237 | 297 |
| 238 if (defined(invoker.test_files)) { | 298 if (defined(invoker.test_files)) { |
| 239 copy(test_files_target_name) { | 299 copy(test_files_target_name) { |
| 240 visibility = [ ":$final_target_name" ] | 300 visibility = [ ":$final_target_name" ] |
| 241 sources = invoker.test_files | 301 sources = invoker.test_files |
| 242 outputs = [ | 302 outputs = [ |
| 243 "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}/{{source
_file_part}}", | 303 "${target_dir}/{{source_file_part}}", |
| 244 ] | 304 ] |
| 245 } | 305 } |
| 246 } | 306 } |
| 247 | 307 |
| 248 group(final_target_name) { | 308 group(final_target_name) { |
| 249 data_deps = [ | 309 data_deps = [ |
| 250 ":$nexe_copy_target_name", | 310 ":$nexe_copy_target_name", |
| 251 ] | 311 ] |
| 252 if (current_cpu == "pnacl" && !is_nacl_nonsfi) { | 312 if (current_cpu == "pnacl" && !is_nacl_nonsfi) { |
| 253 if (defined(invoker.debug_pexe) && invoker.debug_pexe) { | 313 if (defined(invoker.debug_pexe) && invoker.debug_pexe) { |
| 254 data_deps += [ ":$pexe_copy_debug_target_name" ] | 314 data_deps += [ ":$pexe_copy_debug_target_name" ] |
| 255 } | 315 } |
| 256 } | 316 } |
| 257 if (generate_nmf) { | 317 if (generate_nmf) { |
| 258 data_deps += [ ":$nmf_target_name" ] | 318 data_deps += [ ":$nmf_target_name" ] |
| 259 } | 319 } |
| 260 if (defined(invoker.test_files)) { | 320 if (defined(invoker.test_files)) { |
| 261 data_deps += [ ":$test_files_target_name" ] | 321 data_deps += [ ":$test_files_target_name" ] |
| 262 } | 322 } |
| 263 } | 323 } |
| 264 } | 324 } |
| OLD | NEW |