blob: 23b6418983f71b4b3f9f9cf0ea2a7fe662551023 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0-only
#
# Imports ec_commands.h and ec_cmd_api.h from the cros EC repo
# and updates the copyright header for coreboot.
#
set -u
scratch_file=''
coreboot_top=''
pname=''
SPDX_ID_STRING="SPDX-License-Identifier"
cleanup()
{
if [[ -n "${scratch_file}" ]]; then
rm -f -- "${scratch_file}"
scratch_file=''
fi
}
trap cleanup EXIT
usage()
{
cat <<- __EOF
Usage: ${pname}: [top of cros EC repo]
Imports ec_commands.h and ec_cmd_api.h from the cros EC repo
and updates the copyright header for coreboot.
__EOF
}
#
# Remove the original ChromiumOS copyright so we can insert the SPDX
# license identifier. Preserve the original number of lines in the file
# so embedded #line directives are correct.
#
update_copyright()
{
local spdx="/* ${SPDX_ID_STRING}: BSD-3-Clause */"
local f=$1
# replace existing copyright with empty lines
sed -i -e '/Copyright.*Chromium/,/^$/{s/^.*$//}' "${f}"
# now add the SPDX header
sed -i -e "1s@^\$@${spdx}@" "${f}"
}
get_file()
{
local ec_path="$1"
local ec_file="$2"
local dst_path="$3"
local log
if [[ ! -f "${ec_path}/${ec_file}" ]]; then
echo "${ec_path}/${ec_file} does not exist" 2>&1
return 1
fi
scratch_file=$(mktemp)
cp "${ec_path}/${ec_file}" "${scratch_file}"
update_copyright "${scratch_file}"
cp "${scratch_file}" "${dst_path}"
rm -f "${scratch_file}"
scratch_file=''
log=$(git -C "${ec_path}" log --oneline -1 "${ec_file}")
echo "The original ${ec_file} version in the EC repo is:"
echo " ${log}"
}
main()
{
local dst_path
local ec_path
pname=$(basename "$0")
if [[ $# != 1 ]]; then
usage
exit 1
fi
ec_path="$1"
if [[ ! -d "${ec_path}" ]]; then
echo "${pname}: could not find ${ec_path}" 1>&2
exit 1
fi
coreboot_top=$(git rev-parse --show-toplevel)
if [[ ! -d "${coreboot_top}" ]]; then
echo "${pname}: could not determine coreboot top" 1>&2
exit 1
fi
dst_path="${coreboot_top}/src/ec/google/chromeec"
cat <<- __EOF
Suggested commit message:
Generated using ${pname} [EC-DIR].
__EOF
get_file "${ec_path}" include/ec_commands.h "${dst_path}/ec_commands.h"
get_file "${ec_path}" include/ec_cmd_api.h "${dst_path}/ec_cmd_api.h"
echo
}
main "$@"
|