|
| 1 | +# Copyright 2020 The Bazel Authors. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Tests for module cache related command line flags under various configs.""" |
| 16 | + |
| 17 | +load( |
| 18 | + "@build_bazel_rules_swift//test/rules:action_command_line_test.bzl", |
| 19 | + "make_action_command_line_test_rule", |
| 20 | +) |
| 21 | + |
| 22 | +use_global_module_cache_action_command_line_test = make_action_command_line_test_rule( |
| 23 | + config_settings = { |
| 24 | + "//command_line_option:features": [ |
| 25 | + "swift.use_global_module_cache", |
| 26 | + ], |
| 27 | + }, |
| 28 | +) |
| 29 | + |
| 30 | +use_tmpdir_for_module_cache_action_command_line_test = make_action_command_line_test_rule( |
| 31 | + config_settings = { |
| 32 | + "//command_line_option:features": [ |
| 33 | + "swift.use_tmpdir_for_module_cache", |
| 34 | + ], |
| 35 | + }, |
| 36 | +) |
| 37 | + |
| 38 | +def module_cache_settings_test_suite(name = "module_cache_settings"): |
| 39 | + """Test suite for module cache options. |
| 40 | +
|
| 41 | + Args: |
| 42 | + name: The name prefix for all the nested tests |
| 43 | + """ |
| 44 | + |
| 45 | + # Verify that a global module cache path is passed to swiftc. |
| 46 | + use_global_module_cache_action_command_line_test( |
| 47 | + name = "{}_global_module_cache_build".format(name), |
| 48 | + expected_argv = [ |
| 49 | + "-module-cache-path", |
| 50 | + # Starlark doesn't have support for regular expression yet, so we |
| 51 | + # can't verify the whole argument here. |
| 52 | + "/bin/_swift_module_cache", |
| 53 | + ], |
| 54 | + not_expected_argv = [ |
| 55 | + "-Xwrapped-swift=-ephemeral-module-cache", |
| 56 | + ], |
| 57 | + mnemonic = "SwiftCompile", |
| 58 | + tags = [name], |
| 59 | + target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple", |
| 60 | + ) |
| 61 | + |
| 62 | + # Verify that a pre-defined shared module cache path in `/private/tmp` is |
| 63 | + # passed to swiftc. |
| 64 | + use_tmpdir_for_module_cache_action_command_line_test( |
| 65 | + name = "{}_tmpdir_module_cache_build".format(name), |
| 66 | + expected_argv = [ |
| 67 | + "-module-cache-path", |
| 68 | + "/private/tmp/__build_bazel_rules_swift_module_cache", |
| 69 | + ], |
| 70 | + not_expected_argv = [ |
| 71 | + "-Xwrapped-swift=-ephemeral-module-cache", |
| 72 | + ], |
| 73 | + mnemonic = "SwiftCompile", |
| 74 | + tags = [name], |
| 75 | + target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple", |
| 76 | + ) |
| 77 | + |
| 78 | + native.test_suite( |
| 79 | + name = name, |
| 80 | + tags = [name], |
| 81 | + ) |
0 commit comments