summaryrefslogtreecommitdiff
path: root/usr/src/cmd/acpi/acpica-update
blob: 5015084f52f1ab8ff79a7cdbac0b37646a30fb06 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/ksh -e
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# Copyright (c) 2018, Joyent, Inc.
#

export PATH=/usr/bin:/usr/sbin:$PATH

# Comment this when you are ready to run it for real.
dry_run=--dry-run

# This uses rsync.  Trailing slashes are signficant.
function sync {		# srcdir dstdir [excludepatterns]
	set -e
	typeset src=$1
	typeset dst=$2
	typeset -a exclude
	typeset patch=acpica-resync.patch

	shift 2
	for arg in "$@"; do
		exclude+=( --exclude "$arg" )
	done

	echo ""
	echo "sync $src"
	echo "  to: $dst"
	if (( $# > 0 )); then
		echo "  excluding: $@"
	fi

	add_files "$dst"

	rsync $dry_run --out-format '%i %n' -r \
	    --checksum --delete --exclude "$patch" "${exclude[@]}" \
	    "$src" "$dst"

	if [[ -f $dst/$patch ]]; then
		typeset ws_patch
		ws_patch=$(ws_path "${dst%%/}/$patch")
		if grep '^@@ ' "$ws_patch" >/dev/null 2>&1; then
			if [[ -z $dry_run ]]; then
				echo "Applying patch in $ws_patch"
				if patch -f -p1 < "$ws_patch"; then
					patches["$ws_patch"]="Patch Applied"
				else
					patches["$ws_patch"]="Patch FAILED"
				fi
			else
				echo "Patch in $ws_patch"
				if [[ -n $diffstat ]]; then
					diffstat < $ws_patch
				fi
				patches["$ws_patch"]="Has Patch"
			fi
		else
			echo "Important resync info in $ws_patch:"
			cat "$ws_patch"
			patches["$ws_patch"]="MUST READ"
		fi
	fi
}

function copy {		# srcfile dst{file|dir}
	typeset src=$1
	typeset dst=$2

	if [[ -d "$dst" ]]; then
		add_files "$dst"
	else
		add_files "$(dirname "$dst")"
	fi

	if diff "$src" "$dst" >/dev/null 2>&1; then
		echo ""
		echo "copy $src"
		echo "  to: $dst"
		if [[ -z $dry_run ]]; then
			cp "$src" "$dst" || return $?
		fi
	fi
	return 0
}

function add_files {	# dir
	typeset dir=$(ws_path "$1")
	typeset file

	if [[ -n ${alldirs["$dir"]} ]]; then
		return
	fi
	alldirs["$dir"]=added

	find "$dir" -type f | while read file; do
		skip_file "$file" && continue
		[[ -n ${allfiles["$file"]} ]] && continue
		set -- $(md5sum "$file")
		allfiles["$file"]="md5:$1"
	done
}

function compare_files {
	typeset dir
	typeset file
	typeset ufile
	typeset header="\nThe following file changes happened:"

	for dir in ${!alldirs[@]}; do
		find "$dir" -type f | while read file; do
			skip_file "$file" && continue
			if [[ -z ${allfiles["$file"]} ]]; then
				allfiles["$file"]=new
				continue
			fi
			set -- $(md5sum "$file")
			if [[ ${allfiles["$file"]} == "md5:$1" ]]; then
				allfiles["$file"]=same
				continue
			fi
			allfiles["$file"]=modified
		done
	done
	for ufile in "${!allfiles[@]}"; do
		echo "$ufile"
	done | sort | while read file; do
		typeset val=${allfiles["$file"]}

		[[ $val == same ]] && continue
		[[ $val == md5:* ]] && val=removed

		if [[ -n $header ]]; then
			print "$header"
			header=
		fi
		printf "  %-12s %s\n" "$val" "$file"
	done
}

function skip_file {	# filename
	typeset file=$1

	# Remember reserved meaning of return codes
	[[ $file == *.o ]] && return 0
	[[ $file == *.rej ]] && return 0
	[[ $file == *.orig ]] && return 0
	[[ $(file "$file") == *ELF* ]] && return 0

	return 1
}

# Translate absolute path into one relative to $ws_top
function ws_path {	# path
	typeset path=$1

	if [[ $path != /* ]]; then
		print -u2 "ws_path: bad absolute path: '%s'"
		exit 1
	fi

	# Strip excessive leading and all trailing slashes
	path=${path%%/}
	path=/${path##/}

	echo "${path#$ws_top/}"
}

#
# First argument is the acpica source directory
#
if [[ $1 != /* || ! -d $1 ]]; then
	print -u2 "Usage: $0 <acpica-git-directory>"
	exit 1
fi
ac_top=$1

ac_source=$ac_top/source
ac_include=$ac_source/include
ac_components=$ac_source/components

ws_top=${CODEMGR_WS:-$(git rev-parse --show-toplevel)}
ws_common=$ws_top/usr/src/common/acpica
ws_include=$ws_top/usr/src/uts/intel/sys/acpi
ws_cmd=$ws_top/usr/src/cmd/acpi

cd "$ws_top"

typeset -A patches
typeset -A alldirs
typeset -A allfiles
diffstat=$(type -p diffstat 2>/dev/null)

#
# Sync acpica/source/comonents/<comp> to illumos/usr/src/common/acpica/<comp>
#
for dir in disassembler dispatcher events executer hardware \
    namespace parser resources tables utilities; do
	sync "$ac_components/$dir/" "$ws_common/$dir/"
done

#
# Sync acpica/source/include to illumos/usr/src/uts/intel/sys/acpi
#
sync "$ac_include/" "$ws_include/" acsolaris.h acpi_pci.h acpi_enum.h

#
# Sync some acpica/source/tools/<tool> to usr/src/cmd/acpi/<tool>
# acpidump requires some special treatment because of OS-specific files.
#
sync "$ac_source/tools/acpidump/" "$ws_cmd/acpidump/" \
    Makefile osillumostbl.c osunixdir.c
copy "$ac_source/os_specific/service_layers/osunixdir.c" "$ws_cmd/acpidump/"
sync "$ac_source/tools/acpixtract/" "$ws_cmd/acpixtract/" \
    Makefile

#
# Sync iasl from acpica/source/compiler to usr/src/cmd/acpi/iasl
#
sync "$ac_source/compiler/" "$ws_cmd/iasl/" \
    Makefile

#
# Sync common user space code from acpica/source/common to
# usr/src/cmd/acpi/comon
#
sync "$ac_source/common/" "$ws_cmd/common/" osl.c osunixxf.c
copy "$ac_source/os_specific/service_layers/osunixxf.c" "$ws_cmd/common/"

if [[ -n $dry_run ]]; then
	echo ""
	echo "NOTICE: That was a dry run: nothing was changed."
fi

if (( ${#patches[@]} != 0 )); then
	echo ""
	echo "NOTICE: You reviewed all the $patch files, right?"
	for file in "${!patches[@]}"; do
		printf "   %-12s %s\n" "${patches["$file"]}" "$file"
	done
fi

compare_files

exit 0