Skip to content

Commit d713eac

Browse files
committed
Store id128-constants.h in the repository
Instead of generating the list of message ids anew during every build, the file is generated manually and committed into the repository. Also, the list of defines is stored in id128-defines.h, also kept in the repository. Both files should only grow. This should make build easier. But it also fixes a problem with systemd, which occasionally drops message definitions. We will keep them forever, so it should be safe to rely on the presence of message definitions which systemd does not use anymore. Fixes #23.
1 parent 9e0d797 commit d713eac

File tree

8 files changed

+108
-24
lines changed

8 files changed

+108
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pip-log.txt
2323
# Unit test / coverage reports
2424
.coverage
2525
.tox
26+
.cache
2627

2728
#Translations
2829
*.mo

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
include systemd/*.h
2-
exclude systemd/id128-constants.h
32
include README.md
43
include NEWS
54
include LICENSE.txt

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PYTHON = python
22
SED = sed
33
SPHINX_BUILD = sphinx-build
44
ETAGS = etags
5-
INCLUDE_DIR = /usr/include/
5+
INCLUDE_DIR := $(shell pkg-config --variable=includedir libsystemd)
66
VERSION := $(shell $(PYTHON) setup.py --version)
77
TESTFLAGS = -v
88

@@ -15,6 +15,17 @@ builddir := $(shell $(PYTHON) -c '$(buildscript)')
1515

1616
all: build
1717

18+
.PHONY: update-constants
19+
update-constants: $(INCLUDE_DIR)/systemd/sd-messages.h
20+
cat $< systemd/id128-defines.h | \
21+
$(SED) -n -r '/#define SD_MESSAGE_[A-Z0-9_]/p' | \
22+
sort -u | \
23+
tee systemd/id128-defines.h.tmp | \
24+
$(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' | \
25+
sort -u >systemd/id128-constants.h.tmp
26+
mv systemd/id128-defines.h{.tmp,}
27+
mv systemd/id128-constants.h{.tmp,}
28+
1829
build:
1930
$(PYTHON) setup.py build
2031

@@ -28,7 +39,7 @@ clean:
2839
rm -rf build systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__
2940

3041
distclean: clean
31-
rm -rf dist MANIFEST systemd/id128-constants.h
42+
rm -rf dist MANIFEST
3243

3344
SPHINXOPTS = -D version=$(VERSION) -D release=$(VERSION)
3445
sphinx-%: build

setup.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
import sys, os
22
from distutils.core import setup, Extension
3-
from distutils.command.build_ext import build_ext
43
from subprocess import Popen, PIPE, check_output
54

6-
7-
class build_ext_generate_id128_header(build_ext):
8-
def run(self):
9-
if not self.dry_run and not os.path.exists("systemd/id128-constants.h"):
10-
constants = [line.split()[1]
11-
for line in open("/usr/include/systemd/sd-messages.h")
12-
if line.startswith('#define SD_MESSAGE_')]
13-
14-
with open("systemd/id128-constants.h", "w") as f:
15-
for c in constants:
16-
f.write('add_id(m, "{0}", {0}) JOINER\n'.format(c))
17-
18-
return build_ext.run(self)
19-
20-
215
def call(*cmd):
226
cmd = Popen(cmd,
237
stdout=PIPE, stderr=PIPE,
@@ -83,7 +67,7 @@ def lib(*names, **kw):
8367
**lib('libsystemd', 'libsystemd-login', **defines))
8468
setup (name = 'python-systemd',
8569
version = version,
86-
description = 'Native interface to the facilities of systemd',
70+
description = 'Python interface for libsystemd',
8771
author_email = '[email protected]',
8872
maintainer = 'systemd developers',
8973
maintainer_email = '[email protected]',
@@ -102,5 +86,4 @@ def lib(*names, **kw):
10286
_reader,
10387
_daemon,
10488
id128,
105-
login],
106-
cmdclass = {'build_ext': build_ext_generate_id128_header})
89+
login])

systemd/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
/id128-constants.h
21
*.py[oc]
32
*.so

systemd/id128-constants.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
add_id(m, "SD_MESSAGE_BOOTCHART", SD_MESSAGE_BOOTCHART) JOINER
2+
add_id(m, "SD_MESSAGE_CONFIG_ERROR", SD_MESSAGE_CONFIG_ERROR) JOINER
3+
add_id(m, "SD_MESSAGE_COREDUMP", SD_MESSAGE_COREDUMP) JOINER
4+
add_id(m, "SD_MESSAGE_DNSSEC_DOWNGRADE", SD_MESSAGE_DNSSEC_DOWNGRADE) JOINER
5+
add_id(m, "SD_MESSAGE_DNSSEC_FAILURE", SD_MESSAGE_DNSSEC_FAILURE) JOINER
6+
add_id(m, "SD_MESSAGE_DNSSEC_TRUST_ANCHOR_REVOKED", SD_MESSAGE_DNSSEC_TRUST_ANCHOR_REVOKED) JOINER
7+
add_id(m, "SD_MESSAGE_FORWARD_SYSLOG_MISSED", SD_MESSAGE_FORWARD_SYSLOG_MISSED) JOINER
8+
add_id(m, "SD_MESSAGE_HIBERNATE_KEY", SD_MESSAGE_HIBERNATE_KEY) JOINER
9+
add_id(m, "SD_MESSAGE_INVALID_CONFIGURATION", SD_MESSAGE_INVALID_CONFIGURATION) JOINER
10+
add_id(m, "SD_MESSAGE_JOURNAL_DROPPED", SD_MESSAGE_JOURNAL_DROPPED) JOINER
11+
add_id(m, "SD_MESSAGE_JOURNAL_MISSED", SD_MESSAGE_JOURNAL_MISSED) JOINER
12+
add_id(m, "SD_MESSAGE_JOURNAL_START", SD_MESSAGE_JOURNAL_START) JOINER
13+
add_id(m, "SD_MESSAGE_JOURNAL_STOP", SD_MESSAGE_JOURNAL_STOP) JOINER
14+
add_id(m, "SD_MESSAGE_JOURNAL_USAGE", SD_MESSAGE_JOURNAL_USAGE) JOINER
15+
add_id(m, "SD_MESSAGE_LID_CLOSED", SD_MESSAGE_LID_CLOSED) JOINER
16+
add_id(m, "SD_MESSAGE_LID_OPENED", SD_MESSAGE_LID_OPENED) JOINER
17+
add_id(m, "SD_MESSAGE_MACHINE_START", SD_MESSAGE_MACHINE_START) JOINER
18+
add_id(m, "SD_MESSAGE_MACHINE_STOP", SD_MESSAGE_MACHINE_STOP) JOINER
19+
add_id(m, "SD_MESSAGE_OVERMOUNTING", SD_MESSAGE_OVERMOUNTING) JOINER
20+
add_id(m, "SD_MESSAGE_POWER_KEY", SD_MESSAGE_POWER_KEY) JOINER
21+
add_id(m, "SD_MESSAGE_SEAT_START", SD_MESSAGE_SEAT_START) JOINER
22+
add_id(m, "SD_MESSAGE_SEAT_STOP", SD_MESSAGE_SEAT_STOP) JOINER
23+
add_id(m, "SD_MESSAGE_SESSION_START", SD_MESSAGE_SESSION_START) JOINER
24+
add_id(m, "SD_MESSAGE_SESSION_STOP", SD_MESSAGE_SESSION_STOP) JOINER
25+
add_id(m, "SD_MESSAGE_SHUTDOWN", SD_MESSAGE_SHUTDOWN) JOINER
26+
add_id(m, "SD_MESSAGE_SLEEP_START", SD_MESSAGE_SLEEP_START) JOINER
27+
add_id(m, "SD_MESSAGE_SLEEP_STOP", SD_MESSAGE_SLEEP_STOP) JOINER
28+
add_id(m, "SD_MESSAGE_SPAWN_FAILED", SD_MESSAGE_SPAWN_FAILED) JOINER
29+
add_id(m, "SD_MESSAGE_STARTUP_FINISHED", SD_MESSAGE_STARTUP_FINISHED) JOINER
30+
add_id(m, "SD_MESSAGE_SUSPEND_KEY", SD_MESSAGE_SUSPEND_KEY) JOINER
31+
add_id(m, "SD_MESSAGE_SYSTEM_DOCKED", SD_MESSAGE_SYSTEM_DOCKED) JOINER
32+
add_id(m, "SD_MESSAGE_SYSTEM_UNDOCKED", SD_MESSAGE_SYSTEM_UNDOCKED) JOINER
33+
add_id(m, "SD_MESSAGE_TIME_CHANGE", SD_MESSAGE_TIME_CHANGE) JOINER
34+
add_id(m, "SD_MESSAGE_TIMEZONE_CHANGE", SD_MESSAGE_TIMEZONE_CHANGE) JOINER
35+
add_id(m, "SD_MESSAGE_UNIT_FAILED", SD_MESSAGE_UNIT_FAILED) JOINER
36+
add_id(m, "SD_MESSAGE_UNIT_RELOADED", SD_MESSAGE_UNIT_RELOADED) JOINER
37+
add_id(m, "SD_MESSAGE_UNIT_RELOADING", SD_MESSAGE_UNIT_RELOADING) JOINER
38+
add_id(m, "SD_MESSAGE_UNIT_STARTED", SD_MESSAGE_UNIT_STARTED) JOINER
39+
add_id(m, "SD_MESSAGE_UNIT_STARTING", SD_MESSAGE_UNIT_STARTING) JOINER
40+
add_id(m, "SD_MESSAGE_UNIT_STOPPED", SD_MESSAGE_UNIT_STOPPED) JOINER
41+
add_id(m, "SD_MESSAGE_UNIT_STOPPING", SD_MESSAGE_UNIT_STOPPING) JOINER

systemd/id128-defines.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#define SD_MESSAGE_BOOTCHART SD_ID128_MAKE(9f,26,aa,56,2c,f4,40,c2,b1,6c,77,3d,04,79,b5,18)
2+
#define SD_MESSAGE_CONFIG_ERROR SD_ID128_MAKE(c7,72,d2,4e,9a,88,4c,be,b9,ea,12,62,5c,30,6c,01)
3+
#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
4+
#define SD_MESSAGE_DNSSEC_DOWNGRADE SD_ID128_MAKE(36,db,2d,fa,5a,90,45,e1,bd,4a,f5,f9,3e,1c,f0,57)
5+
#define SD_MESSAGE_DNSSEC_FAILURE SD_ID128_MAKE(16,75,d7,f1,72,17,40,98,b1,10,8b,f8,c7,dc,8f,5d)
6+
#define SD_MESSAGE_DNSSEC_TRUST_ANCHOR_REVOKED SD_ID128_MAKE(4d,44,08,cf,d0,d1,44,85,91,84,d1,e6,5d,7c,8a,65)
7+
#define SD_MESSAGE_FORWARD_SYSLOG_MISSED SD_ID128_MAKE(00,27,22,9c,a0,64,41,81,a7,6c,4e,92,45,8a,fa,2e)
8+
#define SD_MESSAGE_HIBERNATE_KEY SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,73)
9+
#define SD_MESSAGE_INVALID_CONFIGURATION SD_ID128_MAKE(c7,72,d2,4e,9a,88,4c,be,b9,ea,12,62,5c,30,6c,01)
10+
#define SD_MESSAGE_JOURNAL_DROPPED SD_ID128_MAKE(a5,96,d6,fe,7b,fa,49,94,82,8e,72,30,9e,95,d6,1e)
11+
#define SD_MESSAGE_JOURNAL_MISSED SD_ID128_MAKE(e9,bf,28,e6,e8,34,48,1b,b6,f4,8f,54,8a,d1,36,06)
12+
#define SD_MESSAGE_JOURNAL_START SD_ID128_MAKE(f7,73,79,a8,49,0b,40,8b,be,5f,69,40,50,5a,77,7b)
13+
#define SD_MESSAGE_JOURNAL_STOP SD_ID128_MAKE(d9,3f,b3,c9,c2,4d,45,1a,97,ce,a6,15,ce,59,c0,0b)
14+
#define SD_MESSAGE_JOURNAL_USAGE SD_ID128_MAKE(ec,38,7f,57,7b,84,4b,8f,a9,48,f3,3c,ad,9a,75,e6)
15+
#define SD_MESSAGE_LID_CLOSED SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,70)
16+
#define SD_MESSAGE_LID_OPENED SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,6f)
17+
#define SD_MESSAGE_MACHINE_START SD_ID128_MAKE(24,d8,d4,45,25,73,40,24,96,06,83,81,a6,31,2d,f2)
18+
#define SD_MESSAGE_MACHINE_STOP SD_ID128_MAKE(58,43,2b,d3,ba,ce,47,7c,b5,14,b5,63,81,b8,a7,58)
19+
#define SD_MESSAGE_OVERMOUNTING SD_ID128_MAKE(1d,ee,03,69,c7,fc,47,36,b7,09,9b,38,ec,b4,6e,e7)
20+
#define SD_MESSAGE_POWER_KEY SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,71)
21+
#define SD_MESSAGE_SEAT_START SD_ID128_MAKE(fc,be,fc,5d,a2,3d,42,80,93,f9,7c,82,a9,29,0f,7b)
22+
#define SD_MESSAGE_SEAT_STOP SD_ID128_MAKE(e7,85,2b,fe,46,78,4e,d0,ac,cd,e0,4b,c8,64,c2,d5)
23+
#define SD_MESSAGE_SESSION_START SD_ID128_MAKE(8d,45,62,0c,1a,43,48,db,b1,74,10,da,57,c6,0c,66)
24+
#define SD_MESSAGE_SESSION_STOP SD_ID128_MAKE(33,54,93,94,24,b4,45,6d,98,02,ca,83,33,ed,42,4a)
25+
#define SD_MESSAGE_SHUTDOWN SD_ID128_MAKE(98,26,88,66,d1,d5,4a,49,9c,4e,98,92,1d,93,bc,40)
26+
#define SD_MESSAGE_SLEEP_START SD_ID128_MAKE(6b,bd,95,ee,97,79,41,e4,97,c4,8b,e2,7c,25,41,28)
27+
#define SD_MESSAGE_SLEEP_STOP SD_ID128_MAKE(88,11,e6,df,2a,8e,40,f5,8a,94,ce,a2,6f,8e,bf,14)
28+
#define SD_MESSAGE_SPAWN_FAILED SD_ID128_MAKE(64,12,57,65,1c,1b,4e,c9,a8,62,4d,7a,40,a9,e1,e7)
29+
#define SD_MESSAGE_STARTUP_FINISHED SD_ID128_MAKE(b0,7a,24,9c,d0,24,41,4a,82,dd,00,cd,18,13,78,ff)
30+
#define SD_MESSAGE_SUSPEND_KEY SD_ID128_MAKE(b7,2e,a4,a2,88,15,45,a0,b5,0e,20,0e,55,b9,b0,72)
31+
#define SD_MESSAGE_SYSTEM_DOCKED SD_ID128_MAKE(f5,f4,16,b8,62,07,4b,28,92,7a,48,c3,ba,7d,51,ff)
32+
#define SD_MESSAGE_SYSTEM_UNDOCKED SD_ID128_MAKE(51,e1,71,bd,58,52,48,56,81,10,14,4c,51,7c,ca,53)
33+
#define SD_MESSAGE_TIME_CHANGE SD_ID128_MAKE(c7,a7,87,07,9b,35,4e,aa,a9,e7,7b,37,18,93,cd,27)
34+
#define SD_MESSAGE_TIMEZONE_CHANGE SD_ID128_MAKE(45,f8,2f,4a,ef,7a,4b,bf,94,2c,e8,61,d1,f2,09,90)
35+
#define SD_MESSAGE_UNIT_FAILED SD_ID128_MAKE(be,02,cf,68,55,d2,42,8b,a4,0d,f7,e9,d0,22,f0,3d)
36+
#define SD_MESSAGE_UNIT_RELOADED SD_ID128_MAKE(7b,05,eb,c6,68,38,42,22,ba,a8,88,11,79,cf,da,54)
37+
#define SD_MESSAGE_UNIT_RELOADING SD_ID128_MAKE(d3,4d,03,7f,ff,18,47,e6,ae,66,9a,37,0e,69,47,25)
38+
#define SD_MESSAGE_UNIT_STARTED SD_ID128_MAKE(39,f5,34,79,d3,a0,45,ac,8e,11,78,62,48,23,1f,bf)
39+
#define SD_MESSAGE_UNIT_STARTING SD_ID128_MAKE(7d,49,58,e8,42,da,4a,75,8f,6c,1c,dc,7b,36,dc,c5)
40+
#define SD_MESSAGE_UNIT_STOPPED SD_ID128_MAKE(9d,1a,aa,27,d6,01,40,bd,96,36,54,38,aa,d2,02,86)
41+
#define SD_MESSAGE_UNIT_STOPPING SD_ID128_MAKE(de,5b,42,6a,63,be,47,a7,b6,ac,3e,aa,c8,2e,2f,6f)

systemd/id128.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@
2020

2121
#include <Python.h>
2222

23-
#include "systemd/sd-messages.h"
23+
/* Our include is first, so that our defines are replaced by the ones
24+
* from the system header. If the system header has the same definitions
25+
* (or does not have them at all), this replacement is silent. If the
26+
* system header has a different definition, we get a warning. A warning
27+
* means that the system headers changed incompatibly, and we should update
28+
* our definition.
29+
*/
30+
#include "id128-defines.h"
31+
#include <systemd/sd-messages.h>
32+
2433

2534
#include "pyutil.h"
2635
#include "macro.h"

0 commit comments

Comments
 (0)