#!/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 " 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/ to illumos/usr/src/common/acpica/ # 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/ to usr/src/cmd/acpi/ # 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