blob: 287dec8907adf8ce4337aac6704ad7bf1cc8e33f [file] [log] [blame]
Jack Neusfdbed822019-07-08 15:10:41 -06001#!/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.
7cd "$(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.
14mocks=(
Jack Neusfdbed822019-07-08 15:10:41 -060015)
16
17license="// 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
21for 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"
30done