Jack Neus | fdbed82 | 2019-07-08 15:10:41 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | # Move to this script's directory. |
| 7 | cd "$(dirname "$0")" |
| 8 | |
| 9 | # List of files to generate mocks from. |
| 10 | # Mocked files are placed in a subdirectory mock/ in the mocked file's |
| 11 | # directory. |
| 12 | # For example, if you mocked a/b/c.go, it would be placed in a/b/mock/c.go. |
| 13 | # If the mock/ subdirectory does not exist, it will be created. |
| 14 | mocks=( |
Jack Neus | fdbed82 | 2019-07-08 15:10:41 -0600 | [diff] [blame] | 15 | ) |
| 16 | |
| 17 | license="// Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 18 | // Use of this source code is governed by a BSD-style license that can be |
| 19 | // found in the LICENSE file.\n" |
| 20 | |
| 21 | for i in "${mocks[@]}"; do |
| 22 | # Try to create mock/ subdirectory in case it doesn't exist. |
| 23 | mkdir "$(dirname $i)/mock" 2>/dev/null |
| 24 | # Generate mock file |
| 25 | dest="$(dirname $i)/mock/$(basename $i)" |
| 26 | echo "generating $dest" |
| 27 | mockgen -source "$i" > "$dest" |
| 28 | # Prepend license to mocked file |
| 29 | echo -e "$license$(cat $dest)" > "$dest" |
| 30 | done |