diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-08-07 21:03:44 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-08-07 21:03:44 -0400 |
commit | 2abe0f2d527c7b3f6b97bd6519bf0e35a266ea68 (patch) | |
tree | 02eb54ce46d51f11defb2c6481cd23ee006d39c0 /tools | |
parent | 09010ac6999db43e39cde92200fc4a10858f5c51 (diff) |
stuff
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/find_includes | 52 | ||||
-rwxr-xr-x | tools/fixup.sh | 9 | ||||
-rwxr-xr-x | tools/fixup_includes | 215 | ||||
-rwxr-xr-x | tools/move.sh | 382 | ||||
-rwxr-xr-x | tools/reset.sh | 6 | ||||
-rw-r--r-- | tools/test-header.c | 1 | ||||
-rwxr-xr-x | tools/test-header.sh | 2 |
7 files changed, 667 insertions, 0 deletions
diff --git a/tools/find_includes b/tools/find_includes new file mode 100755 index 0000000000..6dfb406fa3 --- /dev/null +++ b/tools/find_includes @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +phase=phase0 + +phase0() { + phase=phase0 + local line="$1" + case "$line" in + '#include'*|'typedef '*';') + phase1 "$line" + ;; + *) + ;; + esac +} + +phase1() { + phase=phase1 + local line="$1" + case "$line" in + '') + ;; + '#include'*) + ;; + 'typedef '*';') + ;; + *) + phase2 "$line" + ;; + esac +} + +phase2() { + phase=phase2 + local line="$1" + printf '%s\n' "$line" + cat +} + +main() { + current_file="$1" + set -o pipefail + { + IFS='' + while read -r line; do + "$phase" "$line" + IFS='' + done + } < "$current_file" | grep '^#include' | ifne printf '%s\n' "$current_file" +} + +main "$@" diff --git a/tools/fixup.sh b/tools/fixup.sh new file mode 100755 index 0000000000..651feb6cf8 --- /dev/null +++ b/tools/fixup.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +for lib in basic shared systemd-network systemd; do + pushd src/lib${lib}/include/${lib} + find . -type f -exec sed -ri -e "s|$lib/||" -- {} + + popd +done + +find src \( -name '*.h' -o -name '*.c' \) -type f -exec ./fixup_includes {} \; diff --git a/tools/fixup_includes b/tools/fixup_includes new file mode 100755 index 0000000000..957733cdc0 --- /dev/null +++ b/tools/fixup_includes @@ -0,0 +1,215 @@ +#!/usr/bin/env bash + +panic() { + >&2 echo panic + exit 2 +} + +out() { + printf '%q ' "$@" +} + +# system +# linux +# public +# protected +# private +classify() { + local path=$1 + if [[ "$path" = linux/* ]]; then + out linux "$path" + elif [[ -f "${current_file%/*}/${path}" ]]; then + out private "$path" + elif [[ "$path" != systemd/* ]] && + [[ "$path" != libudev.h ]] && + cpp -include "$path" <<<'' &>/dev/null; + then + out system "$path" + else + case "$path" in + asm/sgidefs.h|dbus/dbus.h|efi.h|efilib.h|gio/gio.h|glib.h|libmount.h) + out system "$path" + ;; + util.h|*/util.h) + if [[ "$current_file" = */systemd-boot/* ]]; then + out private util.h + else + out protected basic/util.h + fi + ;; + *) + file=$(find src -type f -name "${path##*/}") + if [[ -f "$file" ]]; then + case "$file" in + */src/*) + if [[ "${current_file%/*}" = "${file%/*}" ]]; then + out private "${file##*/}" + else + out protected "${file##*/src/}" + fi + ;; + */libsystemd/include/*|*/libudev/include/*) + out public "${file##*/include/}" + ;; + */include/*) + out protected "${file##*/include/}" + ;; + *) + if [[ "${current_file%/*}" = "${file%/*}" ]]; then + out private "${file##*/}" + else + out protected "${file##*/}" + fi + ;; + esac + else + >&2 printf 'Cannot figure out: %q\n' "$path" + exit 2 + fi + ;; + esac + fi +} + +phase=phase0 +hook=: + +phase0() { + phase=phase0 + hook=: + local line="$1" + case "$line" in + '#include'*|'typedef '*';') + phase1 "$line" + ;; + *) + printf '%s\n' "$line" + ;; + esac +} + +phase1_tail= +system=() +linux=() +public=() +protected=() +typedef=(); typedef_last=true +private=() +phase1_flush() { + local b=: + if [[ ${#system[@]} -gt 0 ]]; then + printf '%s\n' "${system[@]}" | sort -u + b=echo + fi + if [[ ${#linux[@]} -gt 0 ]]; then + $b + printf '%s\n' "${linux[@]}" + b=echo + fi + if [[ ${#public[@]} -gt 0 ]]; then + $b + printf '%s\n' "${public[@]}" | sort -u + b=echo + fi + if [[ ${#protected[@]} -gt 0 ]]; then + $b + printf '%s\n' "${protected[@]}" | sort -u + b=echo + fi + if [[ ${#typedef[@]} -gt 0 ]] && ! $typedef_last; then + $b + printf '%s\n' "${typedef[@]}" | sort -u + b=echo + fi + if [[ ${#private[@]} -gt 0 ]]; then + $b + printf '%s\n' "${private[@]}" | sort -u + b=echo + fi + if [[ ${#typedef[@]} -gt 0 ]] && $typedef_last; then + $b + printf '%s\n' "${typedef[@]}" + fi + printf '%s' "$phase1_tail" +} +phase1() { + phase=phase1 + hook=phase1_flush + local line="$1" + case "$line" in + '') + phase1_tail+=$'\n' + ;; + '#include'*) + phase1_tail='' + local re='^#include [<"]([^">]*)[">](.*)' + if [[ "$line" =~ $re ]]; then + IFS=' ' + local buf + buf="$(classify "${BASH_REMATCH[1]}")" || panic + read -r class path <<<"$buf" + case "$class" in + system) + printf -v line '#include <%s>%s' "$path" "${BASH_REMATCH[2]}" + system+=("$line") + ;; + linux) + printf -v line '#include <%s>%s' "$path" "${BASH_REMATCH[2]}" + linux+=("$line") + ;; + public) + printf -v line '#include <%s>%s' "$path" "${BASH_REMATCH[2]}" + public+=("$line") + ;; + protected) + printf -v line '#include "%s"%s' "$path" "${BASH_REMATCH[2]}" + protected+=("$line") + ;; + private) + if [[ ${#typedef[@]} -gt 0 ]]; then + typedef_last=false + fi + printf -v line '#include "%s"%s' "$path" "${BASH_REMATCH[2]}" + private+=("$line") + ;; + esac + else + panic + fi + ;; + 'typedef '*';') + phase1_tail='' + typedef+=("$line") + ;; + *) + phase1_flush + phase2 "$line" + ;; + esac +} + +phase2() { + phase=phase2 + hook=: + local line="$1" + printf '%s\n' "$line" + cat +} + +main() { + current_file="$1" + printf ' => %s\n' "$current_file" + set -o pipefail + trap 'rm -f -- "$current_file.tmp"' EXIT + { + IFS='' + while read -r line; do + "$phase" "$line" + IFS='' + done + "$hook" + } < "$current_file" > "$current_file.tmp" + mv -Tf "$current_file.tmp" "$current_file" +} + +main "$@" diff --git a/tools/move.sh b/tools/move.sh new file mode 100755 index 0000000000..4b55c869ec --- /dev/null +++ b/tools/move.sh @@ -0,0 +1,382 @@ +#!/usr/bin/env bash + +in_array() { + local needle=$1; shift + local item + for item in "$@"; do + [[ $item = $needle ]] && return 0 # Found + done + return 1 # Not Found +} + +move_files() ( + for d in libsystemd libudev; do + mkdir src/$d-new + mv -T src/$d src/$d-new/src + mv -T src/$d-new src/$d + done + + for d in basic core shared; do + mv -T src/{,lib}$d + done + + mkdir src/libbasic/src + mv src/libbasic/*.c src/libbasic/src/ + mkdir src/libbasic/include + mkdir src/libbasic/include/basic + mv src/libbasic/.gitignore src/libbasic/*.h src/libbasic/include/basic/ + + mv -T src/lib{shared,core}/linux + + mkdir src/libfirewall + mv -T src/lib{shared,firewall}/firewall-util.c + mv -T src/lib{shared,firewall}/firewall-util.h + + mkdir src/libshared/src + mv src/libshared/*.c src/libshared/src/ + mkdir src/libshared/include + mkdir src/libshared/include/shared + mv src/libshared/*.h src/libshared/include/shared/ + + mkdir src/libsystemd-network/test + mv src/libsystemd-network/test-* src/libsystemd-network/test + mkdir src/libsystemd-network/src + mv src/libsystemd-network/*.c src/libsystemd-network/src/ + mkdir src/libsystemd-network/include + mkdir src/libsystemd-network/include/systemd-network + mv src/libsystemd-network/*.h src/libsystemd-network/include/systemd-network/ + + pfix=( + dbus1-generator + debug-generator + fstab-generator + getty-generator + gpt-auto-generator + rc-local-generator + system-update-generator + sysv-generator + + ac-power + activate + analyze + ask-password + backlight + binfmt + cgls + cgroups-agent + cgtop + coredump + cryptsetup + delta + detect-virt + escape + firstboot + fsck + hibernate-resume + hwdb + initctl + machine-id-setup + modules-load + notify + nspawn + path + quotacheck + random-seed + remount-fs + reply-password + rfkill + run + sleep + socket-proxy + stdio-bridge + sysctl + sysusers + timesync + tmpfiles + tty-ask-password-agent + update-done + update-utmp + user-sessions + ) + for d in "${pfix[@]}"; do + mv -T src/{,systemd-}$d + done + mv -T src/vconsole src/systemd-vconsole-setup + + dmon=( + systemd-socket-proxy + systemd-timesync + ) + for d in "${dmon[@]}"; do + mv -T "src/$d"{,d} + done + + mv -T {shell-completion/bash/,src/kernel-install/bash-completion_}kernel-install + mv -T {shell-completion/zsh/_,src/kernel-install/zsh-completion_}kernel-install + mv -T {man,src/kernel-install}/kernel-install.xml + + mkdir src/libsystemd/include + mv -T src/{,libsystemd/include}/systemd + + mkdir src/grp-machine + mv -T src/machine src/grp-machine/libmachine-core + mkdir src/grp-machine/systemd-machined + mv -T src/grp-machine/{libmachine-core,systemd-machined}/machined.c + mkdir src/grp-machine/machinectl + mv -T src/grp-machine/{libmachine-core,machinectl}/machinectl.c + mv -T src/{,grp-machine}/nss-mymachines + + mkdir src/grp-resolve + mv -T src/{resolve,grp-resolve/systemd-resolved} + mv -T src/{,grp-resolve}/nss-resolve + + mkdir src/grp-system + mv -T src/{,grp-system}/systemctl + + mkdir src/grp-system/systemd + mv -T src/{libcore,grp-system/systemd}/main.c + mv -T src/{libcore,grp-system/systemd}/macros.systemd.in + mv -T src/{libcore,grp-system/systemd}/org.freedesktop.systemd1.conf + mv -T src/{libcore,grp-system/systemd}/org.freedesktop.systemd1.policy.in.in + mv -T src/{libcore,grp-system/systemd}/org.freedesktop.systemd1.service + mv -T src/{libcore,grp-system/systemd}/system.conf + mv -T src/{libcore,grp-system/systemd}/systemd.pc.in + mv -T src/{libcore,grp-system/systemd}/triggers.systemd.in + mv -T src/{libcore,grp-system/systemd}/user.conf + + mkdir src/libudev/include + mv -T src/libudev/{src,include}/libudev.h + + mv -T src/libsystemd/{src,}/libsystemd.pc.in + mv -T src/libsystemd/{src,}/libsystemd.sym + mv -T src/libsystemd/{src,}/.gitignore + + mkdir src/systemd-shutdown + + mkdir src/grp-coredump + mv -T src/{,grp-coredump}/systemd-coredump + mkdir src/grp-coredump/coredumpctl + mv -T src/grp-coredump/{systemd-coredump,coredumpctl}/coredumpctl.c + + mkdir src/grp-boot + mv -T src/boot/efi src/grp-boot/systemd-boot + mv -T src/boot src/grp-boot/bootctl + mv -T {test,src/grp-boot/systemd-boot}/test-efi-create-disk.sh + + mkdir build-aux + mkdir build-aux/Makefile.{once,each}.{head,tail} + touch build-aux/Makefile.{once,each}.{head,tail}/.gitignore + + mkdir src/libsystemd/src/sd-journal + + libsystemd_journal_files=( + audit-type.c + audit-type.h + catalog.c + catalog.h + compress.c + compress.h + fsprg.c + fsprg.h + journal-authenticate.c + journal-authenticate.h + journal-def.h + journal-file.c + journal-file.h + journal-internal.h + journal-send.c + journal-vacuum.c + journal-vacuum.h + journal-verify.c + journal-verify.h + lookup3.c + lookup3.h + mmap-cache.c + mmap-cache.h + sd-journal.c + ) + for file in "${libsystemd_journal_files[@]}"; do + mv -T src/{journal,libsystemd/src/sd-journal}/$file + done + + mkdir src/busctl + mv src/libsystemd/src/sd-bus/busctl* src/busctl + + mv -T src/{udev,libudev/src}/udev.h + + mkdir src/grp-timedate + mv -T src/timedate src/grp-timedate/systemd-timedated + mkdir src/grp-timedate/timedatectl + mv -T src/grp-timedate/{systemd-timedated,timedatectl}/timedatectl.c + + mv -T src/{journal,grp-journal} + mv -T {,src/grp-journal/}catalog + mkdir src/grp-journal/{systemd-journald,journalctl,libjournal-core} + mv -T src/grp-journal/{,systemd-journald}/journald.c + mv -T src/grp-journal/{,journalctl}/journalctl.c + mv src/grp-journal/*.* src/grp-journal/libjournal-core/ + + mv -T src/{,grp-}journal-remote + local suffix + for suffix in gatewayd remote upload; do + mkdir src/grp-journal-remote/systemd-journal-$suffix + mv src/grp-journal-remote/journal-$suffix* src/grp-journal-remote/systemd-journal-$suffix/ + done + + mv -T src/{,grp-}hostname + mv -T src/{,grp-}locale + mv -T src/{,grp-}udev + + mv -T src/{,grp-}import + mkdir src/grp-import/systemd-importd + mv src/grp-import/{,systemd-importd}/importd.c + mkdir src/grp-import/systemd-pull + mv src/grp-import/pull* src/grp-import/systemd-pull + mkdir src/grp-import/systemd-import + mv src/grp-import/import* src/grp-import/systemd-import + mkdir src/grp-import/systemd-export + mv src/grp-import/export* src/grp-import/systemd-export + + mv -T src/{,grp-}network + mkdir src/grp-network/systemd-networkd + mv src/grp-network/{,systemd-networkd}/networkd.c + mkdir src/grp-network/systemd-networkd-wait-online + mv src/grp-network/networkd-wait-online* src/grp-network/systemd-networkd-wait-online + mkdir src/grp-network/networkctl + mv src/grp-network/{,networkctl}/networkctl.c + mkdir src/grp-network/libnetworkd-core + mv src/grp-network/networkd* src/grp-network/libnetworkd-core + + mv -T src/{,grp-}login + mkdir src/grp-login/systemd-logind + mv -T src/grp-login/{,systemd-logind}/logind.c + mv -T src/grp-login/{,systemd-logind}/logind.h + mkdir src/grp-login/liblogind-core + mv src/grp-login/logind-* src/grp-login/liblogind-core + mkdir src/grp-login/loginctl + mv -T src/grp-login/{,loginctl}/loginctl.c + mv -T src/grp-login/{,loginctl}/sysfs-show.h + mv -T src/grp-login/{,loginctl}/sysfs-show.c + mkdir src/grp-login/systemd-inhibit + mv -T src/grp-login/{,systemd-inhibit}/inhibit.c + mkdir src/grp-login/pam_systemd + mv -T src/grp-login/{,pam_systemd}/pam_systemd.c + mv -T src/grp-login/{,pam_systemd}/pam_systemd.sym + + mkdir src/grp-udev/d-udevadm + mv src/grp-udev/udevadm* src/grp-udev/d-udevadm/ + mkdir src/grp-udev/systemd-udevd + mv -T src/grp-udev/{,systemd-udevd}/udevd.c + mkdir src/grp-udev/libudev-core + mv src/grp-udev/udev* src/grp-udev/libudev-core/ + mv -T src/grp-udev/{,libudev-core}/net + mv -T src/grp-udev/{d-,}udevadm + + mv -T src/{libcore,systemd-shutdown}/shutdown.c + mv -T src/{libcore,systemd-shutdown}/umount.c + mv -T src/{libcore,systemd-shutdown}/umount.h + + mkdir src/grp-helperunits + helperunits=( + backlight + binfmt + detect-virt + quotacheck + random-seed + rfkill + sleep + vconsole-setup + user-sessions + ) + for hu in "${helperunits[@]}"; do + mv -T src/systemd-"$hu" src/grp-helperunits/systemd-"$hu" + done +) + +breakup_makefile() ( + find . \( -name Makefile -o -name '*.mk' \) -delete + + touch .tmp.move.all + files=(.tmp.move.all) + file=/dev/null + IFS='' + while read -r line; do + if [[ $line = '#@'* ]]; then + file="${line#'#@'}" + file="${file%% *}" + elif [[ $file = all ]]; then + printf '%s\n' "$line" | tee -a "${files[@]}" >/dev/null + else + if ! in_array "$file" "${files[@]}"; then + cat .tmp.move.all > "$file" + files+=("$file") + fi + printf '%s\n' "$line" >> "$file" + fi + done < <(fixup_makefile <Makefile.am) + rm .tmp.move.all +) + +fixup_includes() ( + find src \( -name '*.h' -o -name '*.c' \) \ + -exec grep '#include ["<]sd-' -l -- {} + | + xargs -d $'\n' sed -ri \ + -e 's|#include "(sd-[^"]*)"|#include <systemd/\1>|' \ + -e 's|#include <(sd-[^>]*)>|#include <systemd/\1>|' +) + +fixup_makefile() { + sed -r \ + -e '/^[^# ]*:/ { s|^(\s*)\S+/|\1$(outdir)/| }' \ + -e 's|^if (.*)|ifneq ($(\1),)|' \ + -e 's|--version-script=.*/([^/]+)\.sym|--version-script=$(srcdir)/\1.sym|g' +} + +fixup_makefiles() ( + sed -ri \ + -e '/^ \$\(AM_V_at\)\$\(MKDIR_P\) \$\(dir \$@\)/d' \ + -e 's/ \$\(CFLAGS\) / /g' \ + -e 's/ \$\(CPPFLAGS\) / /g' \ + -e 's/ \$\(AM_CPPFLAGS\) / $(ALL_CPPFLAGS) /g' \ + -e '/^[^# ]*:/ { s|\S+/|$(outdir)/|g }' \ + src/libbasic/include/basic/Makefile \ + src/libsystemd/src/Makefile \ + src/libsystemd/src/sd-journal/Makefile \ + src/grp-udev/libudev-core/Makefile + find -type f -name Makefile|while read -r filename; do + sed -r -i "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="${filename%/*}" config.mk)|" "$filename" + done +) + +move() ( + >&2 echo ' => move_files' + move_files + >&2 echo ' => breakup_makefile' + breakup_makefile + >&2 echo ' => fixup_includes' + fixup_includes + >&2 echo ' => fixup_makefiles' + fixup_makefiles +) + +main() { + set -e + + if [[ -n "$(git status -s)" ]] || [[ -n "$(git clean -xdn)" ]]; then + echo 'There are changes in the current directory.' >&2 + exit 1 + fi + + git checkout -b postmove + + move + + git add . + git commit -m './move.sh' + git merge -s ours lukeshu/postmove + git checkout lukeshu/postmove + git merge postmove + git branch -d postmove +} + +main "$@" diff --git a/tools/reset.sh b/tools/reset.sh new file mode 100755 index 0000000000..66b629c217 --- /dev/null +++ b/tools/reset.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e +git checkout lukeshu/premove +git branch -D postmove || true +git checkout . +git clean -xdf diff --git a/tools/test-header.c b/tools/test-header.c new file mode 100644 index 0000000000..76e8197013 --- /dev/null +++ b/tools/test-header.c @@ -0,0 +1 @@ +int main() { return 0; } diff --git a/tools/test-header.sh b/tools/test-header.sh new file mode 100755 index 0000000000..b11285af7d --- /dev/null +++ b/tools/test-header.sh @@ -0,0 +1,2 @@ +#!/bin/bash +gcc -c -o /dev/null -I/usr/include/efi -I/usr/include/efi/x86_64 -I/usr/include/libmount $(find src -type d |sed 's|^|-I&|') -include ./config.h -include "$(realpath -- "$1")" test-header.c |