1# Copyright 2022 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Tests for pw_watch.build_recipe""" 15 16from pathlib import Path 17import shlex 18import unittest 19 20from parameterized import parameterized # type: ignore 21 22from pw_build.build_recipe import BuildCommand 23 24 25# pylint: disable=line-too-long 26class TestBuildRecipe(unittest.TestCase): 27 """Tests for creating BuildRecipes.""" 28 29 maxDiff = None 30 31 @parameterized.expand( 32 [ 33 ( 34 'build command using make', 35 BuildCommand( 36 build_dir=Path('outmake'), 37 build_system_command='make', 38 build_system_extra_args=['-k'], 39 targets=['maketarget1', 'maketarget2'], 40 ), 41 # result 42 ['make', '-k', '-C', 'outmake', 'maketarget1', 'maketarget2'], 43 ), 44 ( 45 'build command using bazel', 46 BuildCommand( 47 build_dir=Path('outbazel'), 48 build_system_command='bazel', 49 build_system_extra_args=['build'], 50 targets=['//pw_analog/...', '//pw_assert/...'], 51 ), 52 # result 53 [ 54 'bazel', 55 'build', 56 '--symlink_prefix', 57 str(Path('outbazel') / 'bazel-'), 58 '//pw_analog/...', 59 '//pw_assert/...', 60 ], 61 ), 62 ( 63 'test command using bazel', 64 BuildCommand( 65 build_dir=Path('outbazel'), 66 build_system_command='bazel', 67 build_system_extra_args=['test'], 68 targets=['//...:all'], 69 ), 70 # result 71 [ 72 'bazel', 73 'test', 74 '--symlink_prefix', 75 str(Path('outbazel') / 'bazel-'), 76 '//...:all', 77 ], 78 ), 79 ( 80 'clean command using bazel', 81 BuildCommand( 82 build_dir=Path('outbazel'), 83 build_system_command='bazel', 84 build_system_extra_args=['clean'], 85 targets=['//...:all'], 86 ), 87 # result 88 [ 89 'bazel', 90 'clean', 91 '--symlink_prefix', 92 str(Path('outbazel') / 'bazel-'), 93 ], 94 ), 95 ( 96 'cmake shell command', 97 BuildCommand( 98 build_dir=Path('outcmake'), 99 command=shlex.split('cmake -G Ninja -S ./ -B outcmake'), 100 ), 101 # result 102 ['cmake', '-G', 'Ninja', '-S', './', '-B', 'outcmake'], 103 ), 104 ( 105 'gn shell command', 106 BuildCommand( 107 build_dir=Path('out'), 108 command=shlex.split('gn gen out --export-compile-commands'), 109 ), 110 # result 111 ['gn', 'gen', 'out', '--export-compile-commands'], 112 ), 113 ( 114 'python shell command', 115 BuildCommand( 116 build_dir=Path('outpytest'), 117 command=shlex.split( 118 'python pw_build/py/build_recipe_test.py' 119 ), 120 ), 121 # result 122 ['python', 'pw_build/py/build_recipe_test.py'], 123 ), 124 ( 125 'gn shell command with a list', 126 BuildCommand( 127 build_dir=Path('out'), 128 command=['gn', 'gen', 'out', '--export-compile-commands'], 129 ), 130 # result 131 ['gn', 'gen', 'out', '--export-compile-commands'], 132 ), 133 ] 134 ) 135 def test_build_command_get_args( 136 self, 137 _test_name, 138 build_command, 139 expected_args, 140 ) -> None: 141 """Test BuildCommand get_args.""" 142 self.assertEqual(expected_args, build_command.get_args()) 143 144 145if __name__ == '__main__': 146 unittest.main() 147