diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/.gitignore | 1 | ||||
-rwxr-xr-x | tools/check-includes.pl | 23 | ||||
-rw-r--r-- | tools/gdb-sd_dump_hashmaps.py | 94 | ||||
-rwxr-xr-x | tools/git-prune | 2 | ||||
-rwxr-xr-x | tools/git-setup | 23 | ||||
-rwxr-xr-x | tools/make-directive-index.py | 313 | ||||
-rwxr-xr-x | tools/make-man-index.py | 136 | ||||
-rw-r--r-- | tools/make-man-rules.py | 129 | ||||
-rwxr-xr-x | tools/notsd-find-includes | 52 | ||||
-rwxr-xr-x | tools/notsd-find-renames | 2 | ||||
-rwxr-xr-x | tools/notsd-fixup | 25 | ||||
-rwxr-xr-x | tools/notsd-fixup--includes | 305 | ||||
-rwxr-xr-x | tools/notsd-fixup--makefiles | 30 | ||||
-rwxr-xr-x | tools/notsd-move | 876 | ||||
-rwxr-xr-x | tools/notsd-reset | 6 | ||||
-rw-r--r-- | tools/test-header.c | 1 | ||||
-rwxr-xr-x | tools/test-header.sh | 2 | ||||
-rw-r--r-- | tools/xml_helper.py | 34 |
18 files changed, 2054 insertions, 0 deletions
diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 0000000000..4bba404d19 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1 @@ +/notsd-fixup--includes.cache diff --git a/tools/check-includes.pl b/tools/check-includes.pl new file mode 100755 index 0000000000..bf23929d47 --- /dev/null +++ b/tools/check-includes.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +# +# checkincludes: Find files included more than once in (other) files. +# Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. + +foreach $file (@ARGV) { + open(FILE, $file) or die "Cannot open $file: $!.\n"; + + my %includedfiles = (); + + while (<FILE>) { + if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { + ++$includedfiles{$1}; + } + } + foreach $filename (keys %includedfiles) { + if ($includedfiles{$filename} > 1) { + print "$file: $filename is included more than once.\n"; + } + } + + close(FILE); +} diff --git a/tools/gdb-sd_dump_hashmaps.py b/tools/gdb-sd_dump_hashmaps.py new file mode 100644 index 0000000000..9ee81fb05a --- /dev/null +++ b/tools/gdb-sd_dump_hashmaps.py @@ -0,0 +1,94 @@ +# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ +# +# This file is part of systemd. +# +# Copyright 2014 Michal Schmidt +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + +import gdb + +class sd_dump_hashmaps(gdb.Command): + "dump systemd's hashmaps" + + def __init__(self): + super(sd_dump_hashmaps, self).__init__("sd_dump_hashmaps", gdb.COMMAND_DATA, gdb.COMPLETE_NONE) + + def invoke(self, arg, from_tty): + d = gdb.parse_and_eval("hashmap_debug_list") + all_entry_sizes = gdb.parse_and_eval("all_entry_sizes") + all_direct_buckets = gdb.parse_and_eval("all_direct_buckets") + hashmap_base_t = gdb.lookup_type("HashmapBase") + uchar_t = gdb.lookup_type("unsigned char") + ulong_t = gdb.lookup_type("unsigned long") + debug_offset = gdb.parse_and_eval("(unsigned long)&((HashmapBase*)0)->debug") + + print "type, hash, indirect, entries, max_entries, buckets, creator" + while d: + h = gdb.parse_and_eval("(HashmapBase*)((char*)%d - %d)" % (int(d.cast(ulong_t)), debug_offset)) + + if h["has_indirect"]: + storage_ptr = h["indirect"]["storage"].cast(uchar_t.pointer()) + n_entries = h["indirect"]["n_entries"] + n_buckets = h["indirect"]["n_buckets"] + else: + storage_ptr = h["direct"]["storage"].cast(uchar_t.pointer()) + n_entries = h["n_direct_entries"] + n_buckets = all_direct_buckets[int(h["type"])]; + + t = ["plain", "ordered", "set"][int(h["type"])] + + print "%s, %s, %s, %d, %d, %d, %s (%s:%d)" % (t, h["hash_ops"], bool(h["has_indirect"]), n_entries, d["max_entries"], n_buckets, d["func"], d["file"], d["line"]) + + if arg != "" and n_entries > 0: + dib_raw_addr = storage_ptr + (all_entry_sizes[h["type"]] * n_buckets) + + histogram = {} + for i in xrange(0, n_buckets): + dib = int(dib_raw_addr[i]) + histogram[dib] = histogram.get(dib, 0) + 1 + + for dib in sorted(iter(histogram)): + if dib != 255: + print "%3d %8d %f%% of entries" % (dib, histogram[dib], 100.0*histogram[dib]/n_entries) + else: + print "%3d %8d %f%% of slots" % (dib, histogram[dib], 100.0*histogram[dib]/n_buckets) + print "mean DIB of entries: %f" % (sum([dib*histogram[dib] for dib in iter(histogram) if dib != 255])*1.0/n_entries) + + blocks = [] + current_len = 1 + prev = int(dib_raw_addr[0]) + for i in xrange(1, n_buckets): + dib = int(dib_raw_addr[i]) + if (dib == 255) != (prev == 255): + if prev != 255: + blocks += [[i, current_len]] + current_len = 1 + else: + current_len += 1 + + prev = dib + if prev != 255: + blocks += [[i, current_len]] + # a block may be wrapped around + if len(blocks) > 1 and blocks[0][0] == blocks[0][1] and blocks[-1][0] == n_buckets - 1: + blocks[0][1] += blocks[-1][1] + blocks = blocks[0:-1] + print "max block: %s" % max(blocks, key=lambda a: a[1]) + print "sum block lens: %d" % sum(b[1] for b in blocks) + print "mean block len: %f" % (1.0 * sum(b[1] for b in blocks) / len(blocks)) + + d = d["debug_list_next"] + +sd_dump_hashmaps() diff --git a/tools/git-prune b/tools/git-prune new file mode 100755 index 0000000000..d5a36dd4ee --- /dev/null +++ b/tools/git-prune @@ -0,0 +1,2 @@ +#!/bin/sh +git tag|grep '^elogind/v[0-9]*$'|xargs -n1 git tag -d diff --git a/tools/git-setup b/tools/git-setup new file mode 100755 index 0000000000..f40a7724d9 --- /dev/null +++ b/tools/git-setup @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +cd "$(dirname -- "$0")" +cd "$(git rev-parse --show-toplevel)" + +if [ -f .git/hooks/pre-commit.sample ] && [ ! -f .git/hooks/pre-commit ]; then + # This part is allowed to fail + cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \ + chmod +x .git/hooks/pre-commit && \ + echo "Activated pre-commit hook." || : +fi + +declare -A fetch +git config -f .gitconfig --get-regexp '.*' | while read -r key val; do + if [[ $key = *.fetch ]]; then + if [[ -z "${fetch[$key]}" ]]; then + git config --local --unset-all "$key" + fetch[$key]='true' + fi + git config --local --add "$key" "$val" + else + git config --local "$key" "$val" + fi +done diff --git a/tools/make-directive-index.py b/tools/make-directive-index.py new file mode 100755 index 0000000000..256ff3dc5d --- /dev/null +++ b/tools/make-directive-index.py @@ -0,0 +1,313 @@ +# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ +# +# This file is part of systemd. +# +# Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + +import sys +import collections +import re +from xml_helper import * +from copy import deepcopy + +TEMPLATE = '''\ +<refentry id="systemd.directives" conditional="HAVE_PYTHON"> + + <refentryinfo> + <title>systemd.directives</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Zbigniew</firstname> + <surname>Jędrzejewski-Szmek</surname> + <email>zbyszek@in.waw.pl</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>systemd.directives</refentrytitle> + <manvolnum>7</manvolnum> + </refmeta> + + <refnamediv> + <refname>systemd.directives</refname> + <refpurpose>Index of configuration directives</refpurpose> + </refnamediv> + + <refsect1> + <title>Unit directives</title> + + <para>Directives for configuring units, used in unit + files.</para> + + <variablelist id='unit-directives' /> + </refsect1> + + <refsect1> + <title>Options on the kernel command line</title> + + <para>Kernel boot options for configuring the behaviour of the + systemd process.</para> + + <variablelist id='kernel-commandline-options' /> + </refsect1> + + <refsect1> + <title>Environment variables</title> + + <para>Environment variables understood by the systemd + manager and other programs.</para> + + <variablelist id='environment-variables' /> + </refsect1> + + <refsect1> + <title>UDEV directives</title> + + <para>Directives for configuring systemd units through the + udev database.</para> + + <variablelist id='udev-directives' /> + </refsect1> + + <refsect1> + <title>Network directives</title> + + <para>Directives for configuring network links through the + net-setup-link udev builtin and networks through + systemd-networkd.</para> + + <variablelist id='network-directives' /> + </refsect1> + + <refsect1> + <title>Journal fields</title> + + <para>Fields in the journal events with a well known meaning.</para> + + <variablelist id='journal-directives' /> + </refsect1> + + <refsect1> + <title>PAM configuration directives</title> + + <para>Directives for configuring PAM behaviour.</para> + + <variablelist id='pam-directives' /> + </refsect1> + + <refsect1> + <title><filename>/etc/crypttab</filename> and + <filename>/etc/fstab</filename> options</title> + + <para>Options which influence mounted filesystems and + encrypted volumes.</para> + + <variablelist id='fstab-options' /> + </refsect1> + + <refsect1> + <title>System manager directives</title> + + <para>Directives for configuring the behaviour of the + systemd process.</para> + + <variablelist id='systemd-directives' /> + </refsect1> + + <refsect1> + <title>command line options</title> + + <para>Command-line options accepted by programs in the + systemd suite.</para> + + <variablelist id='options' /> + </refsect1> + + <refsect1> + <title>Constants</title> + + <para>Various constant used and/or defined by systemd.</para> + + <variablelist id='constants' /> + </refsect1> + + <refsect1> + <title>Miscellaneous options and directives</title> + + <para>Other configuration elements which don't fit in + any of the above groups.</para> + + <variablelist id='miscellaneous' /> + </refsect1> + + <refsect1> + <title>Files and directories</title> + + <para>Paths and file names referred to in the + documentation.</para> + + <variablelist id='filenames' /> + </refsect1> + + <refsect1> + <title>Colophon</title> + <para id='colophon' /> + </refsect1> +</refentry> +''' + +COLOPHON = '''\ +This index contains {count} entries in {sections} sections, +referring to {pages} individual manual pages. +''' + +def _extract_directives(directive_groups, formatting, page): + t = xml_parse(page) + section = t.find('./refmeta/manvolnum').text + pagename = t.find('./refmeta/refentrytitle').text + + storopt = directive_groups['options'] + for variablelist in t.iterfind('.//variablelist'): + klass = variablelist.attrib.get('class') + storvar = directive_groups[klass or 'miscellaneous'] + # <option>s go in OPTIONS, unless class is specified + for xpath, stor in (('./varlistentry/term/varname', storvar), + ('./varlistentry/term/option', + storvar if klass else storopt)): + for name in variablelist.iterfind(xpath): + text = re.sub(r'([= ]).*', r'\1', name.text).rstrip() + stor[text].append((pagename, section)) + if text not in formatting: + # use element as formatted display + if name.text[-1] in '= ': + name.clear() + else: + name.tail = '' + name.text = text + formatting[text] = name + + storfile = directive_groups['filenames'] + for xpath, absolute_only in (('.//refsynopsisdiv//filename', False), + ('.//refsynopsisdiv//command', False), + ('.//filename', True)): + for name in t.iterfind(xpath): + if absolute_only and not (name.text and name.text.startswith('/')): + continue + if name.attrib.get('noindex'): + continue + name.tail = '' + if name.text: + if name.text.endswith('*'): + name.text = name.text[:-1] + if not name.text.startswith('.'): + text = name.text.partition(' ')[0] + if text != name.text: + name.clear() + name.text = text + if text.endswith('/'): + text = text[:-1] + storfile[text].append((pagename, section)) + if text not in formatting: + # use element as formatted display + formatting[text] = name + else: + text = ' '.join(name.itertext()) + storfile[text].append((pagename, section)) + formatting[text] = name + + storfile = directive_groups['constants'] + for name in t.iterfind('.//constant'): + if name.attrib.get('noindex'): + continue + name.tail = '' + if name.text.startswith('('): # a cast, strip it + name.text = name.text.partition(' ')[2] + storfile[name.text].append((pagename, section)) + formatting[name.text] = name + +def _make_section(template, name, directives, formatting): + varlist = template.find(".//*[@id='{}']".format(name)) + for varname, manpages in sorted(directives.items()): + entry = tree.SubElement(varlist, 'varlistentry') + term = tree.SubElement(entry, 'term') + display = deepcopy(formatting[varname]) + term.append(display) + + para = tree.SubElement(tree.SubElement(entry, 'listitem'), 'para') + + b = None + for manpage, manvolume in sorted(set(manpages)): + if b is not None: + b.tail = ', ' + b = tree.SubElement(para, 'citerefentry') + c = tree.SubElement(b, 'refentrytitle') + c.text = manpage + c.attrib['target'] = varname + d = tree.SubElement(b, 'manvolnum') + d.text = manvolume + entry.tail = '\n\n' + +def _make_colophon(template, groups): + count = 0 + pages = set() + for group in groups: + count += len(group) + for pagelist in group.values(): + pages |= set(pagelist) + + para = template.find(".//para[@id='colophon']") + para.text = COLOPHON.format(count=count, + sections=len(groups), + pages=len(pages)) + +def _make_page(template, directive_groups, formatting): + """Create an XML tree from directive_groups. + + directive_groups = { + 'class': {'variable': [('manpage', 'manvolume'), ...], + 'variable2': ...}, + ... + } + """ + for name, directives in directive_groups.items(): + _make_section(template, name, directives, formatting) + + _make_colophon(template, directive_groups.values()) + + return template + +def make_page(*xml_files): + "Extract directives from xml_files and return XML index tree." + template = tree.fromstring(TEMPLATE) + names = [vl.get('id') for vl in template.iterfind('.//variablelist')] + directive_groups = {name:collections.defaultdict(list) + for name in names} + formatting = {} + for page in xml_files: + try: + _extract_directives(directive_groups, formatting, page) + except Exception: + raise ValueError("failed to process " + page) + + return _make_page(template, directive_groups, formatting) + +if __name__ == '__main__': + with open(sys.argv[1], 'wb') as f: + f.write(xml_print(make_page(*sys.argv[2:]))) diff --git a/tools/make-man-index.py b/tools/make-man-index.py new file mode 100755 index 0000000000..74a47b821a --- /dev/null +++ b/tools/make-man-index.py @@ -0,0 +1,136 @@ +# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ +# +# This file is part of systemd. +# +# Copyright 2012 Lennart Poettering +# Copyright 2013 Zbigniew Jędrzejewski-Szmek +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + +import collections +import sys +import re +from xml_helper import * + +MDASH = ' — ' if sys.version_info.major >= 3 else ' -- ' + +TEMPLATE = '''\ +<refentry id="systemd.index" conditional="HAVE_PYTHON"> + + <refentryinfo> + <title>systemd.index</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>systemd.index</refentrytitle> + <manvolnum>7</manvolnum> + </refmeta> + + <refnamediv> + <refname>systemd.index</refname> + <refpurpose>List all manpages from the systemd project</refpurpose> + </refnamediv> +</refentry> +''' + +SUMMARY = '''\ + <refsect1> + <title>See Also</title> + <para> + <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry> + </para> + + <para id='counts' /> + </refsect1> +''' + +COUNTS = '\ +This index contains {count} entries, referring to {pages} individual manual pages.' + + +def check_id(page, t): + id = t.getroot().get('id') + if not re.search('/' + id + '[.]', page): + raise ValueError("id='{}' is not the same as page name '{}'".format(id, page)) + +def make_index(pages): + index = collections.defaultdict(list) + for p in pages: + t = xml_parse(p) + check_id(p, t) + section = t.find('./refmeta/manvolnum').text + refname = t.find('./refnamediv/refname').text + purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split()) + for f in t.findall('./refnamediv/refname'): + infos = (f.text, section, purpose, refname) + index[f.text[0].upper()].append(infos) + return index + +def add_letter(template, letter, pages): + refsect1 = tree.SubElement(template, 'refsect1') + title = tree.SubElement(refsect1, 'title') + title.text = letter + para = tree.SubElement(refsect1, 'para') + for info in sorted(pages, key=lambda info: str.lower(info[0])): + refname, section, purpose, realname = info + + b = tree.SubElement(para, 'citerefentry') + c = tree.SubElement(b, 'refentrytitle') + c.text = refname + d = tree.SubElement(b, 'manvolnum') + d.text = section + + b.tail = MDASH + purpose # + ' (' + p + ')' + + tree.SubElement(para, 'sbr') + +def add_summary(template, indexpages): + count = 0 + pages = set() + for group in indexpages: + count += len(group) + for info in group: + refname, section, purpose, realname = info + pages.add((realname, section)) + + refsect1 = tree.fromstring(SUMMARY) + template.append(refsect1) + + para = template.find(".//para[@id='counts']") + para.text = COUNTS.format(count=count, pages=len(pages)) + +def make_page(*xml_files): + template = tree.fromstring(TEMPLATE) + index = make_index(xml_files) + + for letter in sorted(index): + add_letter(template, letter, index[letter]) + + add_summary(template, index.values()) + + return template + +if __name__ == '__main__': + with open(sys.argv[1], 'wb') as f: + f.write(xml_print(make_page(*sys.argv[2:]))) diff --git a/tools/make-man-rules.py b/tools/make-man-rules.py new file mode 100644 index 0000000000..0b73ab04f7 --- /dev/null +++ b/tools/make-man-rules.py @@ -0,0 +1,129 @@ +# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ +# +# This file is part of systemd. +# +# Copyright 2013 Zbigniew Jędrzejewski-Szmek +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + +from __future__ import print_function +import collections +import sys +import os.path +from xml_helper import * + +SECTION = '''\ +sdman.MANPAGES += \\ + {manpages} +sdman.MANPAGES_ALIAS += \\ + {aliases} +{rules} +{htmlrules} +''' + +CONDITIONAL = '''\ +ifneq ($({conditional}),) +''' \ ++ SECTION + \ +'''\ +endif +''' + +HEADER = '''\ +# Do not edit. Generated by make-man-rules.py. +# To regenerate: +# 1. Create, update, or remove source .xml files in man/ +# 2. Run 'make update-man-list' +# 3. Run 'make man' to generate manpages +# +# To make a man page conditional on a configure switch add +# attribute conditional="ENABLE_WHAT" or conditional="WITH_WHAT" +# to <refentry> element. +''' + +HTML_ALIAS_RULE = '''\ +{}.html: {}.html + $(sdman.html-alias) +''' + +FOOTER = '''\ + +# Really, do not edit this file. + +EXTRA_DIST += \\ + {dist_files} +''' + +def man(page, number): + return 'man/{}.{}'.format(page, number) + +def xml(file): + return 'man/{}'.format(os.path.basename(file)) + +def add_rules(rules, name): + xml = xml_parse(name) + # print('parsing {}'.format(name), file=sys.stderr) + if xml.getroot().tag != 'refentry': + return + conditional = xml.getroot().get('conditional') or '' + rulegroup = rules[conditional] + refmeta = xml.find('./refmeta') + title = refmeta.find('./refentrytitle').text + number = refmeta.find('./manvolnum').text + refnames = xml.findall('./refnamediv/refname') + target = man(refnames[0].text, number) + if title != refnames[0].text: + raise ValueError('refmeta and refnamediv disagree: ' + name) + for refname in refnames: + assert all(refname not in group + for group in rules.values()), "duplicate page name" + alias = man(refname.text, number) + rulegroup[alias] = target + # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr) + +def create_rules(xml_files): + " {conditional => {alias-name => source-name}} " + rules = collections.defaultdict(dict) + for name in xml_files: + try: + add_rules(rules, name) + except Exception: + print("Failed to process", name, file=sys.stderr) + raise + return rules + +def mjoin(files): + return ' \\\n\t'.join(sorted(files) or '#') + +def make_makefile(rules, dist_files): + return HEADER + '\n'.join( + (CONDITIONAL if conditional else SECTION).format( + manpages=mjoin(set(rulegroup.values())), + aliases=mjoin(k for k,v in rulegroup.items() if k != v), + rules='\n'.join('{}: {}'.format(k,v) + for k,v in sorted(rulegroup.items()) + if k != v), + htmlrules='\n'.join(HTML_ALIAS_RULE.format(k[:-2],v[:-2]) + for k,v in sorted(rulegroup.items()) + if k != v), + conditional=conditional) + for conditional,rulegroup in sorted(rules.items()) + ) + FOOTER.format(dist_files=mjoin(sorted(dist_files))) + +if __name__ == '__main__': + rules = create_rules(sys.argv[1:]) + dist_files = (xml(file) for file in sys.argv[1:] + if not file.endswith(".directives.xml") and + not file.endswith(".index.xml")) + print(make_makefile(rules, dist_files), end='') diff --git a/tools/notsd-find-includes b/tools/notsd-find-includes new file mode 100755 index 0000000000..494398b082 --- /dev/null +++ b/tools/notsd-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/notsd-find-renames b/tools/notsd-find-renames new file mode 100755 index 0000000000..fe90e325f6 --- /dev/null +++ b/tools/notsd-find-renames @@ -0,0 +1,2 @@ +#!/bin/sh +git diff --find-renames -l1000 --stat=300,290 "${1:-notsystemd/postmove}" "${2:-notsystemd/master}" |sed -n '/=>/s/\s*|.*//p'
\ No newline at end of file diff --git a/tools/notsd-fixup b/tools/notsd-fixup new file mode 100755 index 0000000000..71b3bf4dfa --- /dev/null +++ b/tools/notsd-fixup @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Copyright (C) 2015-2016 Luke Shumaker + +main() { + set -e + set -o pipefail + export LC_COLLATE=C + + # We wrap the programs called by xargs with `sh` because xargs only exits early + # if the status is 255, but we want to exit early for all non-zero statuses. + # We use xargs instead of `find -exec` because `-exec` won't do much of + # anything useful with the exit status. + + # Makefiles + find "$@" -type f -name Makefile -print0 | + xargs -r0 sh -c "$0--makefiles \"\$@\" || exit 255" -- + + # C includes + rm -rf -- "$0"--includes.cache + find "$@" \( -name '*.h' -o -name '*.c' -o -name '*.gperf' -o -name '*.gperf.m4' \) -type f -print0 | + xargs -r0 sh -c "$0--includes \"\$@\" || exit 255" -- + rm -rf -- "$0"--includes.cache +} + +main "$@" diff --git a/tools/notsd-fixup--includes b/tools/notsd-fixup--includes new file mode 100755 index 0000000000..a636c78be6 --- /dev/null +++ b/tools/notsd-fixup--includes @@ -0,0 +1,305 @@ +#!/usr/bin/env python3 + +# If you are thinking "this file looks gross!", it is. It +# started out as a set of Bash one-liners. Which got turned +# into a script. Which grew somewhat organically. Not huge, +# but given that it started as some one liners, that's not a +# very pretty several hunderd lines. Then got fairly litterally +# translated into this, for speed. So yes, it is gross. +# Rewrites welcome; just don't introduce any behavioral changes +# (easy since `tools/notsd-move` runs it on the entire repo and +# puts the results in git history). + +import atexit +import filecmp +import json +import os +import re +import shlex +import subprocess +import sys + +################################################################ +# Everything else in this program is just fluff and bookkeeping +# around around calling classify(). + +# Return a tuple of (class/group, path); which is a class that +# the header path belongs to, and a normalized path for it. +# +# There are a fixed number of classes that it may put a header +# in; in order of most-public to most-private: +# +# system +# linux +# public +# protected +# private +def classify(expensive, current_file, path): + if re.fullmatch('.*/include(-staging)?/.*/.*', current_file): + lib = os.path.basename(os.path.dirname(current_file)) + if path.startswith(lib+'/'): + path = re.sub('^'+lib+'/', path) + if path.startswith('linux/'): + return 'linux', path + elif expensive.exists(os.path.join(os.path.dirname(current_file), path)): + return 'private', path + elif not path.startswith('systemd/') and path != 'libudev.h' and expensive.cpp(path): + return 'system', path + else: + if path.endswith('-to-name.h') or path.endswith('-from-name.h'): + base = re.fullmatch('(.*)-(to|from)-name\.h', os.path.basename(path)).group(1) + d={ + 'dns_type' : 'src/grp-resolve/systemd-resolved', + 'keyboard-keys' : 'src/grp-udev/libudev-core', + 'af' : 'src/libsystemd-basic/src', + 'arphrd' : 'src/libsystemd-basic/src', + 'cap' : 'src/libsystemd-basic/src', + 'errno' : 'src/libsystemd-basic/src', + 'audit_type' : 'src/libsystemd/src/sd-journal', + } + file = os.path.join(d[base], os.path.basename(path)) + if current_file.startswith(d[base]): + return 'private', os.path.basename(file) + elif '/include/' in file: + return 'protected', re.sub('.*/include/', '', file) + else: + return 'protected', os.path.basename(file) + elif path in [ 'asm/sgidefs.h', 'dbus/dbus.h', 'efi.h', 'efilib.h', 'gio/gio.h', 'glib.h', 'libmount.h' ]: + return 'system', path + elif os.path.basename(path) == 'util.h': + if '/systemd-boot/' in current_file: + return 'private', 'util.h' + else: + return 'protected', 'systemd-basic/util.h' + else: + find = expensive.find(os.path.basename(path)) + if len(find) == 1: + file = find[0] + if '/src/' in file: + if os.path.dirname(current_file) == os.path.dirname(file): + return 'private', os.path.basename(file) + else: + return 'protected', re.sub('.*/src/', '', file) + elif ('/libsystemd/include/' in file) or ('/libudev/include/' in file): + return 'public', re.sub('.*/include/', '', file) + elif '/include/' in file: + return 'protected', re.sub('.*/include/', '', file) + elif '/include-staging/' in file: + return 'protected', re.sub('.*/include-staging/', '', file) + else: + if os.path.dirname(current_file) == os.path.dirname(file): + return 'private', os.path.basename(file) + else: + return 'protected', os.path.basename(file) + else: + sys.exit('Cannot figure out: {0}'.format(path)) + +################################################################ +# Cache expensive things + +class Cache: + def __init__(self, filename): + self.cache = { + 'find': None, + 'cpp': {} + } + self.dirty = True + + if os.path.isfile(filename): + with open(filename) as file: + self.cache = json.load(file) + self.dirty = False + + def save(self, filename): + if self.dirty: + with open(filename, 'w') as file: + json.dump(self.cache, file) + + def real_cpp(path): + # `cpp -include "$path" <<<'' &>/dev/null` + print(' -> cpp({0})'.format(path), file=sys.stderr) + with subprocess.Popen(['cpp', '-include', path], + stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) as proc: + proc.stdin.close() + return proc.wait() == 0 + + def real_find(): + # This can probably be done with os.walk or something, + # but since it is only called once, it isn't a good + # place to start optimizing. + # + # `find src -name '*.h' \( -type l -printf 'l %p\n' -o -type f -printf 'f %p\n' \)` + print(' -> find()', file=sys.stderr) + ret = {} + with subprocess.Popen(['find', 'src', '-name', '*.h', '(', '-type', 'l', '-printf', 'l %p\n', '-o', '-type', 'f', '-printf', 'f %p\n', ')'], + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, universal_newlines=True, + stderr=subprocess.DEVNULL) as proc: + for line in proc.stdout: + t, p = line.rstrip('\n').split(' ', 1) + ret[p]=t + return ret + + def cpp(self, path): + # `cpp -include "$path" <<<'' &>/dev/null` + if path not in self.cache['cpp']: + self.cache['cpp'][path] = Cache.real_cpp(path) + self.dirty = True + return self.cache['cpp'][path] + + def exists(self, path): + # `test -f "$path"` + if not self.cache['find']: + self.cache['find'] = Cache.real_find() + self.dirty = True + return path in self.cache['find'] + + def find(self, name): + # `find src -type f -name "$name"` + if not self.cache['find']: + self.cache['find'] = Cache.real_find() + self.dirty = True + return [p for p in self.cache['find'].keys() if self.cache['find'][p]=='f' and os.path.basename(p) == name] + +################################################################ +# Data structure for storing a chunk of `#include` lines. + +class IncludeSection: + def __init__(self): + self.trailing_nl = '' + self.system = [] + self.linux = [] + self.public = [] + self.protected = [] + self.typedef = [] + self.typedef_last = True + self.private = [] + def print(self, file=sys.stdout): + b='' + if len(self.system) > 0: + for line in sorted(set(self.system)): + print(line, file=file) + b='\n' + if len(self.linux) > 0: + print(b, end='', file=file) + for line in self.linux: + print(line, file=file) + b='\n' + if len(self.public) > 0: + print(b, end='', file=file) + for line in sorted(set(self.public)): + print(line, file=file) + b='\n' + if len(self.protected) > 0: + print(b, end='', file=file) + for line in sorted(set(self.protected)): + print(line, file=file) + b='\n' + if len(self.typedef) > 0 and not self.typedef_last: + print(b, end='', file=file) + for line in sorted(set(self.typedef)): + print(line, file=file) + b='\n' + if len(self.private) > 0: + print(b, end='', file=file) + for line in sorted(set(self.private)): + print(line, file=file) + b='\n' + if len(self.typedef) > 0 and self.typedef_last: + print(b, end='', file=file) + for line in self.typedef: + print(line, file=file) + print(self.trailing_nl, end='', file=file) + def add(self, group, path, extra): + if group == 'system': + self.system.append('#include <{0}>{1}'.format(path, extra)) + elif group == 'linux': + self.linux.append('#include <{0}>{1}'.format(path, extra)) + elif group == 'public': + self.public.append('#include <{0}>{1}'.format(path, extra)) + elif group == 'protected': + self.protected.append('#include "{0}"{1}'.format(path, extra)) + elif group == 'private': + if len(self.typedef) > 0: + self.typedef_last = False + self.private.append('#include "{0}"{1}'.format(path, extra)) + else: + sys.exit('panic: unrecognized line class: {0}'.format(group)) + +################################################################ +# The main program loop + +class Parser: + def __init__(self, cache, ifilename, ofilename): + self.cache = cache + self.ifilename = os.path.normpath(ifilename) + self.ofilename = ofilename + + self.includes = None + self.phase = self.phase0 + + def phase0(self, line, ofile): + self.phase = self.phase0 + + if re.fullmatch('#include.*|typedef .*;', line): + self.includes = IncludeSection() + self.phase1(line, ofile) + else: + print(line, file=ofile) + + def phase1(self, line, ofile): + self.phase = self.phase1 + + if line == '': + self.includes.trailing_nl += '\n' + elif line.startswith('#include'): + self.includes.trailing_nl = '' + match = re.fullmatch('^#include [<"]([^">]*)[">](.*)', line) + if match: + group, path = classify(self.cache, self.ifilename, match.group(1)) + self.includes.add(group, path, match.group(2)) + else: + sys.exit('panic: malformed #include line') + elif re.fullmatch('typedef .*;', line): + self.includes.trailing_nl = '' + self.includes.typedef.append(line) + else: + self.includes.print(file=ofile) + self.includes = None + self.phase0(line, ofile) + + def run(self): + print(' => {0} {1}'.format( + shlex.quote(__file__), + shlex.quote(self.ifilename), + ), file=sys.stderr) + with open(self.ofilename, 'w') as ofile: + with open(self.ifilename) as ifile: + for line in ifile: + self.phase(line.rstrip('\n'), ofile) + if self.includes: + self.includes.print(file=ofile) + +def main(argv): + cache = Cache(__file__+'.cache') + tmpfilename = '' + def cleanup(): + if tmpfilename != '': + try: + os.unlink(tmpfilename) + except FileNotFoundError: + pass + atexit.register(cleanup) + for filename in argv[1:]: + tmpfilename = os.path.join(os.path.dirname(filename), '.tmp.'+os.path.basename(filename)+'.tmp') + Parser(cache, filename, tmpfilename).run() + if not filecmp.cmp(filename, tmpfilename): + os.rename(tmpfilename, filename) + cleanup() + tmpfilename = '' + cache.save(__file__+'.cache') + +if __name__ == '__main__': + main(sys.argv) diff --git a/tools/notsd-fixup--makefiles b/tools/notsd-fixup--makefiles new file mode 100755 index 0000000000..f89e4b075b --- /dev/null +++ b/tools/notsd-fixup--makefiles @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +doit() { + local filename=$1 + { + <"$filename" sed -r \ + -e "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="$(dirname -- "$filename")" config.mk)|" \ + -e '/^nested\.subdirs/d' \ + -e '/^include \$\(topsrcdir\)\/build-aux\/Makefile\.tail\.mk$/d' + echo + find "$(dirname "$filename")" -mindepth 2 -maxdepth 2 -name Makefile -print0 | + xargs -r0 dirname -z -- | + xargs -r0 basename -a -z | + xargs -r0 printf 'nested.subdirs += %s\n' | sort + echo + echo 'include $(topsrcdir)/build-aux/Makefile.tail.mk' + } | cat -s | build-aux/write-ifchanged "$filename" +} + +main() { + set -e + set -o pipefail + local filename + for filename in "$@"; do + >&2 printf ' => %q %q\n' "$0" "$filename" + doit "$filename" + done +} + +main "$@" diff --git a/tools/notsd-move b/tools/notsd-move new file mode 100755 index 0000000000..ad638a2e63 --- /dev/null +++ b/tools/notsd-move @@ -0,0 +1,876 @@ +#!/usr/bin/env bash + +in_array() ( + set +x + local needle=$1; shift + local item + for item in "$@"; do + [[ $item = $needle ]] && return 0 # Found + done + return 1 # Not Found +) + +split_lib() ( + shopt -s nullglob + local d=$1 + local t + + if t=("$d"/test-*) && [[ ${#t[@]} -gt 0 ]]; then + mkdir "$d/test" + mv -t "$d/test" -- "${t[@]}" + fi + + if t=("$d"/*.c) && [[ ${#t[@]} -gt 0 ]]; then + mkdir "$d/src" + mv -t "$d/src" -- "${t[@]}" + fi + + if t=("$d"/*.h) && [[ ${#t[@]} -gt 0 ]]; then + local h=${d##*/lib} + mkdir "$d/include" + mkdir "$d/include/$h" + mv -t "$d/include/$h" -- "${t[@]}" + else + return 1 + fi +) + +grp() { + local grp=$1 + shift + if [[ -d "${grp}.d" ]]; then + mv -T "${grp}.d" "$grp" + else + mkdir "$grp" + fi + mv "$@" -t "$grp" +} + +move_files() ( + # first focus on getting directories to the right names. + mv -T src/{,systemd-}debug-generator + mv -T src/{,systemd-}fstab-generator + mv -T src/{,systemd-}getty-generator + mv -T src/{,systemd-}gpt-auto-generator + mv -T src/{,systemd-}rc-local-generator + mv -T src/{,systemd-}system-update-generator + mv -T src/{,systemd-}sysv-generator + + mv -T src/{,systemd-}ac-power + mv -T src/{,systemd-}analyze + mv -T src/{,systemd-}ask-password + mv -T src/{,systemd-}backlight + mv -T src/{,systemd-}binfmt + mv -T src/{,systemd-}cgls + mv -T src/{,systemd-}cgroups-agent + mv -T src/{,systemd-}cgtop + mv -T src/{,systemd-}cryptsetup + mv -T src/{,systemd-}delta + mv -T src/{,systemd-}detect-virt + mv -T src/{,systemd-}escape + mv -T src/{,systemd-}firstboot + mv -T src/{,systemd-}fsck + mv -T src/{,systemd-}hibernate-resume + mv -T src/{,systemd-}hwdb + mv -T src/{,systemd-}initctl + mv -T src/{,systemd-}machine-id-setup + mv -T src/{,systemd-}modules-load + mv -T src/{,systemd-}mount + mv -T src/{,systemd-}notify + mv -T src/{,systemd-}nspawn + mv -T src/{,systemd-}path + mv -T src/{,systemd-}quotacheck + mv -T src/{,systemd-}random-seed + mv -T src/{,systemd-}remount-fs + mv -T src/{,systemd-}reply-password + mv -T src/{,systemd-}rfkill + mv -T src/{,systemd-}run + mv -T src/{,systemd-}sleep + mv -T src/{,systemd-}stdio-bridge + mv -T src/{,systemd-}sysctl + mv -T src/{,systemd-}sysusers + mv -T src/{,systemd-}tmpfiles + mv -T src/{,systemd-}tty-ask-password-agent + mv -T src/{,systemd-}update-done + mv -T src/{,systemd-}update-utmp + mv -T src/{,systemd-}user-sessions + mv -T src/vconsole src/systemd-vconsole-setup + mv -T src/socket-proxy src/systemd-socket-proxyd + mv -T src/timesync src/systemd-timesyncd + mv -T src/activate src/systemd-socket-activate + + mv src/udev/*_id -t src + mv src/udev/mtd_probe -t src + mv src/udev/collect -t src + + mv -T src/boot/efi src/systemd-boot + mv -T src/boot src/bootctl + + mkdir src/libsystemd/src + mv -t src/libsystemd/src src/libsystemd/sd-* + mkdir src/libsystemd/include + mv -T src/systemd src/libsystemd/include/systemd + + mkdir src/busctl + mv src/libsystemd/src/sd-bus/busctl* -t src/busctl + + mkdir src/systemd + mv -t src/systemd \ + src/core/main* \ + src/core/*systemd* \ + src/core/system.conf \ + src/core/user.conf + mkdir src/systemd-shutdown + mv -t src/systemd-shutdown \ + src/core/shutdown* \ + src/core/umount* + mv -T src/{,lib}core + + mv -T src/{,libsystemd-}basic + mv -T src/{,libsystemd-}shared + + mv -T src/lib{systemd-shared,core}/linux + + mkdir src/libsystemd-firewall + mv -T src/libsystemd-{shared,firewall}/firewall-util.c + mv -T src/libsystemd-{shared,firewall}/firewall-util.h + + mkdir src/libsystemd-gcrypt + mv -T src/libsystemd-{shared,gcrypt}/gcrypt-util.c + mv -T src/libsystemd-{shared,gcrypt}/gcrypt-util.h + + mkdir src/libsystemd-blkid + mv -T src/libsystemd-{basic,blkid}/blkid-util.h + + mkdir src/libsystemd-microhttpd + mv -t src/libsystemd-microhttpd \ + src/journal-remote/microhttpd* + + split_lib src/libcore + split_lib src/libsystemd-basic + split_lib src/libsystemd-shared + split_lib src/libsystemd-network + split_lib src/libsystemd-firewall + split_lib src/libsystemd-gcrypt + split_lib src/libsystemd-blkid + split_lib src/libsystemd-microhttpd + + mv -t src/libcore/src \ + src/libcore/linux \ + src/libcore/include/core/dbus*.h + mv -T src/libcore/{src,include/core}/dbus-manager.h + mv -T src/libcore/{include/core,src}/audit-fd.h + mv -T src/libcore/{include/core,src}/load-dropin.h + mv -T src/libcore/{include/core,src}/locale-setup.h + mv -T src/libcore/{include/core,src}/selinux-access.h + mv -T src/libcore/{include/core,src}/transaction.h + mv -T src/libcore/{include/core,src}/unit-printf.h + mv -T src/libcore/{,src}/load-fragment-gperf.gperf.m4 + + mv src/libsystemd-shared/{test,include/systemd-shared}/test-tables.h + rmdir src/libsystemd-shared/test + + mkdir src/systemd-hibernate-resume-generator + mv -t src/systemd-hibernate-resume-generator \ + src/systemd-hibernate-resume/*generator* + + # src/resolve => src/{libbasic-dns,resolve,resolved} + mkdir src/libbasic-dns + mv -t src/libbasic-dns \ + src/resolve/dns-type.{c,h} \ + src/resolve/resolved-dns-{answer,dnssec,packet,question,rr}.{c,h} \ + src/resolve/test-* + mkdir src/systemd-resolve + mv -t src/systemd-resolve \ + src/resolve/resolve-tool.c + mkdir src/systemd-resolved + mv -t src/systemd-resolved \ + src/resolve/.gitignore \ + src/resolve/* + rmdir src/resolve + split_lib src/libbasic-dns + + # src/import => src/{libimport,systemd-{export,importd,import}} + mkdir src/libimport + mv -t src/libimport \ + src/import/import-common.{c,h} \ + src/import/import-compress.{c,h} \ + src/import/qcow2-util.{c,h} \ + src/import/test-qcow2.c + mkdir src/systemd-export + mv -t src/systemd-export \ + src/import/export* + mkdir src/systemd-importd + mv -t src/systemd-importd \ + src/import/.gitignore \ + src/import/importd.c \ + src/import/org.* + mkdir src/systemd-import + mv -t src/systemd-import \ + src/import/import* + mkdir src/systemd-pull + mv -t src/systemd-pull \ + src/import/pull* \ + src/import/curl-util* + rmdir src/import + + # src/journal => src/... + mkdir src/libjournal-core + mv -t src/libjournal-core \ + src/journal/.gitignore \ + src/journal/journald-* \ + src/journal/test-* + mkdir src/systemd-cat + mv -t src/systemd-cat \ + src/journal/cat.c + mkdir src/journalctl + mv -t src/journalctl \ + src/journal/journal-qrcode.{c,h} \ + src/journal/journalctl.c + mkdir src/systemd-journald + mv -t src/systemd-journald \ + src/journal/journald.* + mkdir src/libsystemd/src/sd-journal + mv -t src/libsystemd/src/sd-journal \ + src/journal/audit-type.c \ + src/journal/audit-type.h \ + src/journal/catalog.c \ + src/journal/catalog.h \ + src/journal/compress.c \ + src/journal/compress.h \ + src/journal/fsprg.c \ + src/journal/fsprg.h \ + src/journal/journal-authenticate.c \ + src/journal/journal-authenticate.h \ + src/journal/journal-def.h \ + src/journal/journal-file.c \ + src/journal/journal-file.h \ + src/journal/journal-internal.h \ + src/journal/journal-send.c \ + src/journal/journal-vacuum.c \ + src/journal/journal-vacuum.h \ + src/journal/journal-verify.c \ + src/journal/journal-verify.h \ + src/journal/lookup3.c \ + src/journal/lookup3.h \ + src/journal/mmap-cache.c \ + src/journal/mmap-cache.h \ + src/journal/sd-journal.c + rmdir src/journal + split_lib src/libjournal-core + mv -T src/libjournal-core/{,src/}journald-gperf.gperf + + # src/network => src/... + mkdir src/systemd-networkd-wait-online + mv -t src/systemd-networkd-wait-online \ + src/network/networkd-wait-online* + mkdir src/libnetworkd-core + mv -t src/libnetworkd-core \ + src/network/.gitignore \ + src/network/networkd-* + mkdir src/networkctl + mv -t src/networkctl \ + src/network/networkctl.c + mkdir src/systemd-networkd + mv -t src/systemd-networkd \ + src/network/networkd* \ + src/network/org.* + mkdir src/grp-network.d + mv -t src/grp-network.d \ + src/network/test-* + rmdir src/network + + # src/machine => src/{machinectl,systemd-machined,libmachine-core} + mkdir src/machinectl src/systemd-machined src/libmachine-core + mv -T src/{machine,machinectl}/machinectl.c + mv -T src/{machine,systemd-machined}/machined.c + mv -t src/systemd-machined \ + src/machine/.gitignore \ + src/machine/org.* + mv -t src/libmachine-core \ + src/machine/* + rmdir src/machine + split_lib src/libmachine-core + + # src/coredump => src/{coredumpctl,systemd-coredump} + mkdir src/coredumpctl + mv -t src/coredumpctl \ + src/coredump/coredumpctl* + mkdir src/systemd-coredump + mv -t src/systemd-coredump \ + src/coredump/* + rmdir src/coredump + + # src/hostname => src/{hostnamectl,systemd-hostnamed} + mkdir src/hostnamectl + mv -t src/hostnamectl \ + src/hostname/hostnamectl* + mkdir src/systemd-hostnamed + mv -t src/systemd-hostnamed \ + src/hostname/.gitignore \ + src/hostname/* + rmdir src/hostname + + # src/journal-remote => src/... + mkdir src/systemd-journal-gatewayd + mv -t src/systemd-journal-gatewayd \ + src/journal-remote/journal-gateway* + mkdir src/systemd-journal-remote + mv -t src/systemd-journal-remote \ + src/journal-remote/journal-remote* + mkdir src/systemd-journal-upload + mv -t src/systemd-journal-upload \ + src/journal-remote/journal-upload* + mkdir src/grp-remote.d + mv -t src/grp-remote.d \ + src/journal-remote/.gitignore \ + src/journal-remote/browse.html \ + src/journal-remote/log-generator.py + rmdir src/journal-remote + + # src/locale => src/... + mkdir src/localectl + mv -t src/localectl \ + src/locale/localectl* + mkdir src/systemd-localed + mv -t src/systemd-localed \ + src/locale/.gitignore \ + src/locale/* + rmdir src/locale + + # src/login => src/... + mkdir src/grp-login.d + mv -t src/grp-login.d \ + src/login/.gitignore \ + src/login/test-* + mkdir src/loginctl + mv -t src/loginctl \ + src/login/loginctl* \ + src/login/sysfs-show* + mkdir src/pam_systemd + mv -t src/pam_systemd \ + src/login/pam* + mkdir src/systemd-inhibit + mv -t src/systemd-inhibit \ + src/login/inhibit* + mkdir src/systemd-logind + mv -t src/systemd-logind \ + src/login/logind* \ + src/login/*.rules \ + src/login/*.rules.in \ + src/login/org.* + mv -T src/login/systemd-user.m4 src/systemd-logind/systemd-user.pam.m4 + rmdir src/login + + # src/timedate => src/... + mkdir src/timedatectl + mv -t src/timedatectl \ + src/timedate/timedatectl* + mkdir src/systemd-timedated + mv -t src/systemd-timedated \ + src/timedate/.gitignore \ + src/timedate/timedated* \ + src/timedate/org.* + rmdir src/timedate + + # src/udev => src/... + mv -T src/udev/udev.h src/libudev/udev.h + mkdir src/udevadm + mv -t src/udevadm \ + src/udev/udevadm* + mkdir src/libudev-core + mv -t src/libudev-core \ + src/udev/net \ + src/udev/udev-* + mkdir src/systemd-udevd + mv -t src/systemd-udevd \ + src/udev/udev.conf* \ + src/udev/udevd* + mkdir src/grp-udev.d + mv -t src/grp-udev.d \ + src/udev/.gitignore \ + src/udev/udev.* + rm src/udev/.vimrc + rmdir src/udev + + # .conf is such a useless suffix + for ext in sysctl sysusers tmpfiles; do + for file in $ext.d/*.conf*; do + mv -T "$file" "${file/.conf/.$ext}" + done + done + for ext in xorg; do + for file in $ext/*.sh*; do + mv -T "$file" "${file/.sh/.$ext}" + done + done + + # less obvious manpage groups + mv -T man/{glib-event-glue,sd_event_get_fd-glib-example}.c + mv -T man/systemd-{halt.service,shutdown}.xml + mv -T man/systemd-{suspend.service,sleep}.xml + mv -t src/libsystemd \ + man/libsystemd* \ + man/sd* + mv -t src/libudev \ + man/udev_* + mkdir src/manpages + mv -t src/manpages \ + man/daemon.xml \ + man/file-hierarchy.xml \ + man/hostname.xml \ + man/locale.conf.xml \ + man/localtime.xml \ + man/machine-id.xml \ + man/machine-info.xml \ + man/os-release.xml + mv -t src/systemctl \ + man/halt.xml \ + man/runlevel.xml \ + man/shutdown.xml \ + man/telinit.xml \ + man/systemd.preset.xml + mv -t src/systemd \ + man/systemd-system.conf.xml + mkdir src/grp-system.d + mv -t src/grp-system.d \ + man/bootup.xml \ + man/kernel-command-line.xml + mv -t src/systemd-udevd \ + man/udev.conf.xml + mv -t src/grp-udev.d \ + man/udev.xml + mv -t src/systemd-cryptsetup \ + man/*crypt* + mv -t src/systemd-machine-id-setup \ + man/systemd-machine-id* + mv -t src/systemd-path src/libsystemd/include/systemd/sd-path* + mv -t src/systemd-path src/libsystemd/src/sd-path/* + rmdir src/libsystemd/src/sd-path + mv -t src/systemd-resolved \ + man/dnssec-trust-anchors* + mv -t src/systemd-tty-ask-password-agent \ + man/systemd-ask-password-console* + + # less obvious unit groups + # suffix these with '*' in case they gain or lose the .in suffix. + for thing in hibernate hybrid-sleep suspend; do + mv -t src/systemd-sleep \ + units/"$thing".target* \ + units/systemd-"$thing".service* + done + for thing in halt kexec poweroff reboot; do + mv -t src/systemd-shutdown \ + units/"$thing".target* \ + units/systemd-"$thing".service* + done + mv -t src/systemd-binfmt \ + units/*binfmt* + mv -t src/systemd-modules-load \ + units/kmod* + mv -t src/systemd-quotacheck \ + units/quota* + mv -t src/systemd-journald \ + units/*journald* + mv -t src/systemd-cryptsetup \ + units/cryptsetup* + mv -t src/systemd-logind \ + units/user.slice* + mv -t src/systemd-machined \ + units/machine.slice* + + # muck + mv -t src/libsystemd-basic/src src/libsystemd-basic/.gitignore + mv -T {test,src/systemd-boot}/test-efi-create-disk.sh + mv -t src/systemd-tmpfiles units/systemd-tmpfiles* + mv -t src/systemd-tmpfiles \ + tmpfiles.d/tmp.* \ + tmpfiles.d/var.* \ + tmpfiles.d/etc.* \ + tmpfiles.d/home.* \ + tmpfiles.d/*nologin* \ + tmpfiles.d/legacy.* \ + tmpfiles.d/x11.* + mv -t src/systemd-sysusers \ + sysusers.d/.gitignore \ + sysusers.d/basic* + mkdir src/libudev/src + mv -t src/libudev/src src/libudev/*.{c,h} + mkdir src/libudev/include + mv -T src/libudev/{src,include}/libudev.h + mv -T src/{systemd-networkd,libnetworkd-core}/networkd.h + mv -T src/{systemd-resolved,libbasic-dns/include/basic-dns}/resolved-def.h + mv -t src/cdrom_id rules/*cdrom* + mv -t src/mtd_probe rules/*mtd* + mv -t src/v4l_id rules/*v4l* + mv -t src/libsystemd-network/include/systemd-network \ + src/libsystemd/include/systemd/sd-dhcp* \ + src/libsystemd/include/systemd/sd-ipv4* \ + src/libsystemd/include/systemd/sd-lldp* \ + src/libsystemd/include/systemd/sd-ndisc* + mkdir src/libsystemd/include-staging{,/systemd-staging} + mv -t src/libsystemd/include-staging/systemd-staging \ + src/libsystemd/include/systemd/sd-{device,hwdb,netlink,network,resolve}.h + + mkdir src/grp-journal.d + mv -t src/grp-journal.d tmpfiles.d/journal-nocow.* + mv -t src/grp-remote.d tmpfiles.d/systemd-remote.* + mv -t src/systemd tmpfiles.d/systemd-tmpfs.tmpfiles* + mv -t src/systemd xorg/??-systemd-user.*; rmdir xorg + mv -t src/systemd-vconsole-setup man/vconsole.conf.xml + mv -t src/systemd-coredump \ + sysctl.d/*coredump* + mv -t src/systemd-sysctl \ + sysctl.d/??-default.* + + mv -t src/systemd-sysv-generator \ + docs/sysvinit/.gitignore \ + docs/sysvinit/* + rmdir docs/sysvinit + mv -t src/grp-journal.d \ + docs/var-log/.gitignore \ + docs/var-log/* + rmdir docs/var-log + rm docs/.gitignore + rmdir docs + + # auto-distribute the stuff + for d in man units sysusers.d tmpfiles.d; do + pushd $d >/dev/null + for file in *; do + base=${file%%.*} + base=${base%%@*} + if [[ -d ../src/"${base}" ]]; then + mv "$file" -t ../src/"${base}" + elif [[ -d ../src/"${base#systemd-}" ]]; then + mv "$file" -t ../src/"${base#systemd-}" + elif [[ -d ../src/systemd-"${base}" ]]; then + mv "$file" -t ../src/systemd-"${base}" + fi + done + popd >/dev/null + done + rmdir sysusers.d #tmpfiles.d + + pushd shell-completion/bash >/dev/null + mv -T systemctl.in ../../src/systemctl/systemctl.completion.bash.in + cat .gitignore >> ../../src/systemctl/.gitignore + rm .gitignore + for file in *; do + if [[ -d ../../src/"$file" ]]; then + mv -T "$file" "../../src/$file/$file.completion.bash" + fi + done + popd >/dev/null + rmdir shell-completion/bash + + pushd shell-completion/zsh >/dev/null + mv -T _systemctl.in ../../src/systemctl/systemctl.completion.zsh.in + cat .gitignore >> ../../src/systemctl/.gitignore + rm .gitignore + for file in _*; do + if [[ -d ../../src/"${file#_}" ]]; then + mv -T "$file" "../../src/${file#_}/${file#_}.completion.zsh" + fi + done + popd >/dev/null + mv -T shell-completion/zsh src/zsh-completion + rmdir shell-completion + + # do this *after* auto-splitting, because of + # systemd-journal-{gatewayd,remote,upload}. + mv -t src/journalctl \ + units/*journal* + # fix a false positive + mv -t units \ + src/systemd-shutdown/shutdown.target + + # categorize + grp src/grp-boot \ + src/bootctl \ + src/kernel-install \ + src/systemd-boot + grp src/grp-coredump \ + src/coredumpctl \ + src/systemd-coredump + grp src/grp-hostname \ + src/hostnamectl \ + src/systemd-hostnamed + grp src/grp-initprogs \ + src/systemd-backlight \ + src/systemd-binfmt \ + src/systemd-detect-virt \ + src/systemd-firstboot \ + src/systemd-fsck \ + src/systemd-modules-load \ + src/systemd-quotacheck \ + src/systemd-random-seed \ + src/systemd-rfkill \ + src/systemd-sysctl \ + src/systemd-sysusers \ + src/systemd-tmpfiles \ + src/systemd-update-done \ + src/systemd-update-utmp \ + src/systemd-user-sessions \ + src/systemd-vconsole-setup + grp src/grp-initprogs/grp-sleep \ + src/systemd-hibernate-resume \ + src/systemd-hibernate-resume-generator \ + src/systemd-sleep + grp src/grp-remote \ + src/libsystemd-microhttpd \ + src/systemd-journal-gatewayd \ + src/systemd-journal-remote \ + src/systemd-journal-upload + grp src/grp-journal \ + catalog \ + src/grp-remote \ + src/journalctl \ + src/libjournal-core \ + src/systemd-cat \ + src/systemd-journald + grp src/grp-locale \ + src/localectl \ + src/systemd-localed + grp src/grp-login \ + src/loginctl \ + src/pam_systemd \ + src/systemd-inhibit \ + src/systemd-logind + grp src/grp-machine \ + src/libmachine-core \ + src/machinectl \ + src/nss-mymachines \ + src/systemd-machined + grp src/grp-machine/grp-import \ + src/libimport \ + src/systemd-export \ + src/systemd-import \ + src/systemd-importd \ + src/systemd-pull + grp src/grp-network \ + network \ + src/libnetworkd-core \ + src/networkctl \ + src/systemd-networkd \ + src/systemd-networkd-wait-online + grp src/grp-resolve \ + src/libbasic-dns \ + src/nss-resolve \ + src/systemd-resolve \ + src/systemd-resolved + grp src/grp-system \ + src/libcore \ + src/systemctl \ + src/systemd \ + src/systemd-cgroups-agent \ + src/systemd-shutdown + grp src/grp-system/grp-utils \ + src/systemd-analyze \ + src/systemd-delta \ + src/systemd-fstab-generator \ + src/systemd-run \ + src/systemd-sysv-generator + grp src/grp-timedate \ + src/systemd-timedated \ + src/timedatectl + grp src/grp-udev \ + rules \ + hwdb \ + src/libudev-core \ + src/*_id \ + src/collect \ + src/mtd_probe \ + src/systemd-hwdb \ + src/systemd-udevd \ + src/udevadm + grp src/grp-utils \ + src/systemd-ac-power \ + src/systemd-escape \ + src/systemd-notify \ + src/systemd-path \ + src/systemd-socket-activate + + mv -t src/grp-udev \ + src/grp-udev/rules/* + cat src/grp-udev/rules/.gitignore >> src/grp-udev/.gitignore + rm src/grp-udev/rules/.gitignore + rmdir src/grp-udev/rules + + mv -t src/grp-journal/systemd-journald \ + src/grp-journal/catalog/.gitignore \ + src/grp-journal/catalog/* + rmdir src/grp-journal/catalog + + mv -t src/systemd-timesyncd system-preset/??-timesyncd.preset + mv -t src/grp-journal/grp-remote system-preset/??-journal-remote.preset + for file in system-preset/??-*.preset; do + base="${file##*/??-}" + base="${base%.preset}" + base="${base%d}" + mv -t src/grp-"$base" "$file" + done + rmdir system-preset + + mv -t src/libsystemd/src/sd-bus \ + src/libsystemd-shared/src/bus-util.c \ + src/libsystemd-shared/include/systemd-shared/bus-util.h + + ln -srT src/libsystemd/include/systemd/_sd-common.h src/libsystemd-network/include/systemd-network/_sd-common.h + ln -srT src/libsystemd/include/systemd/_sd-common.h src/grp-utils/systemd-path/_sd-common.h + ln -srT src/grp-login/systemd-logind/logind-acl.h src/grp-udev/libudev-core/logind-acl.h + ln -srT src/grp-login/systemd-logind/logind-acl.c src/grp-udev/libudev-core/logind-acl.c + ln -srT src/libsystemd/src/sd-login/sd-login.c src/grp-udev/libudev-core/sd-login.c +) + +breakup_makefile() ( + mkdir -p build-aux/Makefile.{once,each}.{head,tail} + + touch .tmp.move.all + files=(.tmp.move.all) + file=/dev/null + IFS='' + declare -i i=0 + trap 'printf "Makefile.am:%d:%s\n" $i "$line"' EXIT + while read -r line; do + i+=1 + if [[ $line = '#@'* ]]; then + file="${line#'#@'}" + file="${file%% *}" + if [[ $file = auto/* ]]; then + IFS=/ + read -r auto dir makefile <<<"$file" + IFS='' + [[ $auto = auto ]] + [[ $makefile = Makefile ]] + d="$(find src -type d -name "$dir")" + [[ -n "$d" ]] + [[ "$(wc -l <<<"$d")" = 1 ]] + file="$d/Makefile" + fi + if [[ "$file" != all ]] && ! in_array "$file" "${files[@]}"; then + cat .tmp.move.all > "$file" + files+=("$file") + fi + elif [[ $file = all ]]; then + printf '%s\n' "$line" | tee -a "${files[@]}" >/dev/null + else + printf '%s\n' "$line" >> "$file" + fi + done < <(fixup_makefile <Makefile.am) + trap -- EXIT + rm .tmp.move.all + + sed -ri \ + -e '/^[^# ]*:/ { s|\S+/|$(outdir)/|g }' \ + src/libsystemd-basic/src/Makefile \ + src/libsystemd/src/Makefile \ + src/libsystemd/src/sd-journal/Makefile \ + src/grp-udev/libudev-core/Makefile + + ln -sT ../subdir.mk src/libsystemd/src/sd-network/Makefile + ln -sT ../subdir.mk src/libsystemd/src/sd-event/Makefile + ln -sT ../subdir.mk src/libsystemd/src/sd-login/Makefile + ln -sT ../subdir.mk src/libsystemd/src/sd-resolve/Makefile + ln -sT ../subdir.mk src/libsystemd/src/sd-daemon/Makefile + ln -sT ../subdir.mk src/libsystemd/src/sd-netlink/Makefile + ln -sT ../subdir.mk src/libsystemd/src/sd-id128/Makefile + ln -sT ../subdir.mk src/libsystemd/src/sd-device/Makefile +) + +fixup_makefile() { + sed -r \ + -e '#### Specific complete strings #####' \ + -e 's|\$\(CPP\) \$\(CFLAGS\) \$\(AM_CPPFLAGS\) \$\(CPPFLAGS\)|$(CPP) $(sd.ALL_CPPFLAGS)|g' \ + -e '/^ \$\(AM_V_at\)\$\(MKDIR_P\) \$\(dir \$@\)/d' \ + \ + -e '#### General cases #################' \ + -e '/^[^# ]*:/ { s|^(\s*)\S+/|\1$(outdir)/| }' \ + -e 's|^if (.*)|ifneq ($(\1),)|' \ + -e '/^\s*\$\(AM_(C|CPP|LD)FLAGS\b/d' \ + -e 's|--version-script=.*/([^/]+)\.sym|--version-script=$(srcdir)/\1.sym|g' \ + -e 's|\$\((lib\S+)_la_LIBADD\)|\1.la|g' \ + \ + -e '#### Rename helpers ################' \ + -e 's|libbasic_la|libsystemd_basic_la|g' \ + -e 's|libbasic|libsystemd-basic|g' \ + -e 's|libsystemd-basic-dns|libbasic-dns|g' \ + \ + -e 's|libshared_la|libsystemd_shared_la|g' \ + -e 's|libshared|libsystemd-shared|g' \ + \ + -e 's|libfirewall_la|libsystemd_firewall_la|g' \ + -e 's|libfirewall|libsystemd-firewall|g' +} + +breakup_zshcompletion() ( + sed_expr=' + 1 { + i #compdef %s + d + } + /^case/,/^esac/ { + /^ %s)/,/^ ;;/ { + s/^ //p + } + d + } + ' + + cd shell-completion/zsh + read -r _ cmds < _systemd + for cmd in $cmds; do + printf -v cmd_sed_expr "$sed_expr" $cmd $cmd + sed -e "$cmd_sed_expr" < _systemd > _$cmd + done + rm _systemd +) + +run() ( + local tmp + tmp="$(mktemp --tmpdir)" + trap 'rm -f -- "$tmp"' EXIT + "$0" "$@" |& tail -n20 > "$tmp" || { r=$?; cat "$tmp"; return $r; } + return 0 +) + +move() ( + find . \( -name Makefile -o -name '*.mk' \) -delete + find src -type d -empty -exec rmdir -p --ignore-fail-on-non-empty -- {} + + + >&2 echo ' => breakup_zshcompletion' + run breakup_zshcompletion + >&2 echo ' => move_files' + run move_files + >&2 echo ' => breakup_makefile' + run breakup_makefile + >&2 echo ' => ./tools/notsd-fixup' + ./tools/notsd-fixup +) + +main() { + 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 tmp/postmove + + move + + git add . + git commit -m './tools/notsd-move' + git merge --no-edit -s ours notsystemd/postmove + git checkout notsystemd/postmove + git merge tmp/postmove + git branch -d tmp/postmove +} + +set -e +set -o pipefail +if [[ $# -gt 0 ]]; then + set -x; +else + set -- main +fi +"$@" diff --git a/tools/notsd-reset b/tools/notsd-reset new file mode 100755 index 0000000000..d7141587fa --- /dev/null +++ b/tools/notsd-reset @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e +git checkout notsystemd/premove +git branch -D tmp/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..d63177bde0 --- /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")" "$(dirname -- "$0")"/test-header.c diff --git a/tools/xml_helper.py b/tools/xml_helper.py new file mode 100644 index 0000000000..e87126f2f7 --- /dev/null +++ b/tools/xml_helper.py @@ -0,0 +1,34 @@ +# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ +# +# This file is part of systemd. +# +# Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + +from lxml import etree as tree + +class CustomResolver(tree.Resolver): + def resolve(self, url, id, context): + if 'custom-entities.ent' in url: + return self.resolve_filename('man/custom-entities.ent', context) + +_parser = tree.XMLParser() +_parser.resolvers.add(CustomResolver()) +def xml_parse(page): + doc = tree.parse(page, _parser) + doc.xinclude() + return doc +def xml_print(xml): + return tree.tostring(xml, pretty_print=True, encoding='utf-8') |