1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2020 The Chromium Authors 2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file. 4*8975f5c5SAndroid Build Coastguard Worker 5*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/android/rules.gni") 6*8975f5c5SAndroid Build Coastguard Worker 7*8975f5c5SAndroid Build Coastguard Workerdeclare_args() { 8*8975f5c5SAndroid Build Coastguard Worker # Used by tests to enable generating build files for GN targets which should 9*8975f5c5SAndroid Build Coastguard Worker # not compile. 10*8975f5c5SAndroid Build Coastguard Worker enable_android_nocompile_tests = false 11*8975f5c5SAndroid Build Coastguard Worker} 12*8975f5c5SAndroid Build Coastguard Worker 13*8975f5c5SAndroid Build Coastguard Worker# Defines a test suite which checks that the 'test targets' fail to compile. The 14*8975f5c5SAndroid Build Coastguard Worker# test suite runs 'gn gen' with a custom output directory and attempts to compile 15*8975f5c5SAndroid Build Coastguard Worker# each test target. 16*8975f5c5SAndroid Build Coastguard Worker# 17*8975f5c5SAndroid Build Coastguard Worker# All of the tests should be defined in the same dedicated BUILD.gn file in order 18*8975f5c5SAndroid Build Coastguard Worker# to minimize the number of targets that are processed by 'gn gen'. 19*8975f5c5SAndroid Build Coastguard Worker# 20*8975f5c5SAndroid Build Coastguard Worker# Variables 21*8975f5c5SAndroid Build Coastguard Worker# tests: List of test configurations. A test configuration has the following 22*8975f5c5SAndroid Build Coastguard Worker# keys: 23*8975f5c5SAndroid Build Coastguard Worker# 'target': The GN target which should not compile when 24*8975f5c5SAndroid Build Coastguard Worker# enable_android_nocompile_tests=true The target should compile when 25*8975f5c5SAndroid Build Coastguard Worker# enable_android_nocompile_tests=false. 26*8975f5c5SAndroid Build Coastguard Worker# 'expected_compile_output_regex': Error message regex to search for when compile fails. 27*8975f5c5SAndroid Build Coastguard Worker# 'nocompile_sources': Source files which do not compile. This ensures that 28*8975f5c5SAndroid Build Coastguard Worker# the test suite is re-run when one of these files change (as the test 29*8975f5c5SAndroid Build Coastguard Worker# targets might not depend of the files when 30*8975f5c5SAndroid Build Coastguard Worker# enable_android_nocompile_tests=false). 31*8975f5c5SAndroid Build Coastguard Workertemplate("android_nocompile_test_suite") { 32*8975f5c5SAndroid Build Coastguard Worker assert(!enable_android_nocompile_tests) 33*8975f5c5SAndroid Build Coastguard Worker 34*8975f5c5SAndroid Build Coastguard Worker action(target_name) { 35*8975f5c5SAndroid Build Coastguard Worker testonly = true 36*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/nocompile_test.py" 37*8975f5c5SAndroid Build Coastguard Worker pool = "//build/config/android:nocompile_pool" 38*8975f5c5SAndroid Build Coastguard Worker 39*8975f5c5SAndroid Build Coastguard Worker _tests = invoker.tests 40*8975f5c5SAndroid Build Coastguard Worker _test0 = _tests[0] 41*8975f5c5SAndroid Build Coastguard Worker _test0_dir = get_label_info(_test0["target"], "dir") 42*8975f5c5SAndroid Build Coastguard Worker _test0_target_out_dir = get_label_info(_test0["target"], "target_out_dir") 43*8975f5c5SAndroid Build Coastguard Worker foreach(_test_config, _tests) { 44*8975f5c5SAndroid Build Coastguard Worker assert( 45*8975f5c5SAndroid Build Coastguard Worker _test0_dir == get_label_info(_test_config["target"], "dir"), 46*8975f5c5SAndroid Build Coastguard Worker "To avoid running 'gn gen' for each test, all tests in an android_nocompile_test_suite() should be declared in same BUILD.gn file") 47*8975f5c5SAndroid Build Coastguard Worker } 48*8975f5c5SAndroid Build Coastguard Worker 49*8975f5c5SAndroid Build Coastguard Worker deps = [] 50*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 51*8975f5c5SAndroid Build Coastguard Worker deps += invoker.deps 52*8975f5c5SAndroid Build Coastguard Worker } 53*8975f5c5SAndroid Build Coastguard Worker 54*8975f5c5SAndroid Build Coastguard Worker sources = [] 55*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.sources)) { 56*8975f5c5SAndroid Build Coastguard Worker sources += invoker.sources 57*8975f5c5SAndroid Build Coastguard Worker } 58*8975f5c5SAndroid Build Coastguard Worker 59*8975f5c5SAndroid Build Coastguard Worker # Depend on compile_java Python scripts so that the action is re-run whenever the script is 60*8975f5c5SAndroid Build Coastguard Worker # modified. 61*8975f5c5SAndroid Build Coastguard Worker _pydeps = [ "//build/android/gyp/compile_java.pydeps" ] 62*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.pydeps)) { 63*8975f5c5SAndroid Build Coastguard Worker _pydeps += invoker.pydeps 64*8975f5c5SAndroid Build Coastguard Worker } 65*8975f5c5SAndroid Build Coastguard Worker 66*8975f5c5SAndroid Build Coastguard Worker inputs = [] 67*8975f5c5SAndroid Build Coastguard Worker foreach(_pydeps_file, _pydeps) { 68*8975f5c5SAndroid Build Coastguard Worker _pydeps_file_lines = [] 69*8975f5c5SAndroid Build Coastguard Worker _pydeps_file_lines = read_file(_pydeps_file, "list lines") 70*8975f5c5SAndroid Build Coastguard Worker _pydeps_entries = [] 71*8975f5c5SAndroid Build Coastguard Worker _pydeps_entries = filter_exclude(_pydeps_file_lines, [ "#*" ]) 72*8975f5c5SAndroid Build Coastguard Worker _pydeps_file_dir = get_path_info(_pydeps_file, "dir") 73*8975f5c5SAndroid Build Coastguard Worker inputs += rebase_path(_pydeps_entries, ".", _pydeps_file_dir) 74*8975f5c5SAndroid Build Coastguard Worker } 75*8975f5c5SAndroid Build Coastguard Worker 76*8975f5c5SAndroid Build Coastguard Worker _json_test_configs = [] 77*8975f5c5SAndroid Build Coastguard Worker foreach(_test_config, _tests) { 78*8975f5c5SAndroid Build Coastguard Worker _test = _test_config["target"] 79*8975f5c5SAndroid Build Coastguard Worker deps += [ _test ] 80*8975f5c5SAndroid Build Coastguard Worker sources += _test_config["nocompile_sources"] 81*8975f5c5SAndroid Build Coastguard Worker _dep_dir = get_label_info(_test, "dir") 82*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_test, "name") 83*8975f5c5SAndroid Build Coastguard Worker _json_test_configs += [ 84*8975f5c5SAndroid Build Coastguard Worker { 85*8975f5c5SAndroid Build Coastguard Worker target = "${_dep_dir}:${_dep_name}" 86*8975f5c5SAndroid Build Coastguard Worker expect_regex = _test_config["expected_compile_output_regex"] 87*8975f5c5SAndroid Build Coastguard Worker }, 88*8975f5c5SAndroid Build Coastguard Worker ] 89*8975f5c5SAndroid Build Coastguard Worker } 90*8975f5c5SAndroid Build Coastguard Worker 91*8975f5c5SAndroid Build Coastguard Worker _config_path = "$target_gen_dir/${target_name}.nocompile_config" 92*8975f5c5SAndroid Build Coastguard Worker write_file(_config_path, _json_test_configs, "json") 93*8975f5c5SAndroid Build Coastguard Worker 94*8975f5c5SAndroid Build Coastguard Worker # Compute output directory for no-compile tests based on the directory containing test 95*8975f5c5SAndroid Build Coastguard Worker # targets instead of based on the test suite target name. This avoids calling 'gn gen' for each 96*8975f5c5SAndroid Build Coastguard Worker # android_nocompile_test_suite() for test suites whose tests are declared in the same BUILD.gn 97*8975f5c5SAndroid Build Coastguard Worker # file. 98*8975f5c5SAndroid Build Coastguard Worker _out_dir = "${_test0_target_out_dir}/nocompile_out" 99*8975f5c5SAndroid Build Coastguard Worker 100*8975f5c5SAndroid Build Coastguard Worker _stamp_path = "${target_gen_dir}/${target_name}.stamp" 101*8975f5c5SAndroid Build Coastguard Worker args = [ 102*8975f5c5SAndroid Build Coastguard Worker "--gn-args-path", 103*8975f5c5SAndroid Build Coastguard Worker "args.gn", 104*8975f5c5SAndroid Build Coastguard Worker "--out-dir", 105*8975f5c5SAndroid Build Coastguard Worker rebase_path(_out_dir, root_build_dir), 106*8975f5c5SAndroid Build Coastguard Worker "--test-configs-path", 107*8975f5c5SAndroid Build Coastguard Worker rebase_path(_config_path, root_build_dir), 108*8975f5c5SAndroid Build Coastguard Worker "--stamp", 109*8975f5c5SAndroid Build Coastguard Worker rebase_path(_stamp_path, root_build_dir), 110*8975f5c5SAndroid Build Coastguard Worker ] 111*8975f5c5SAndroid Build Coastguard Worker inputs += [ _config_path ] 112*8975f5c5SAndroid Build Coastguard Worker outputs = [ _stamp_path ] 113*8975f5c5SAndroid Build Coastguard Worker } 114*8975f5c5SAndroid Build Coastguard Worker} 115