Skip to content

Commit 0b2253b

Browse files
Add options to call generate-tz-header as part of the build process. (#405)
1 parent 3f3f8f7 commit 0b2253b

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

meson_options.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ option(
5858
value: false,
5959
description: 'Show additional build warnings'
6060
)
61+
option(
62+
'generate_tz_coords',
63+
type: 'boolean',
64+
value: false,
65+
description: 'Generate TZCoords header from tzdata'
66+
)
67+
option(
68+
'zone_tab',
69+
type: 'string',
70+
value: '/usr/share/zoneinfo/zone.tab',
71+
description: 'Path to tzdata zone.tab or zone1970.tab'
72+
)
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
#!/usr/bin/python3
1+
#!/usr/bin/env python3
22

33
import re
4+
from argparse import ArgumentParser
5+
from pathlib import Path
6+
7+
COORDS_RE = re.compile(r"([+-])([0-9]+)([+-])([0-9]+)")
48

59
d = {}
610

11+
parser = ArgumentParser(prog='generate-tz-header',
12+
description='Generate tz-coords.h header from timezone-data')
13+
parser.add_argument('-i', '--zone_tab', nargs='?', default='/usr/share/zoneinfo/zone.tab', type=Path)
14+
parser.add_argument('-o', '--out_file', nargs='?', default='tz-coords.h', type=Path)
15+
args = parser.parse_args()
716

8-
with open("/usr/share/zoneinfo/zone.tab", "r") as f:
17+
with open(args.zone_tab, "r") as f:
918
for line in f:
10-
if line.startswith("#"):
19+
line = line.strip()
20+
if not line or line.startswith("#"):
1121
continue
1222

13-
res = re.search(r"([A-Z]{2})\s([0-9-+]+)\s([\w/_\-]+)\s", line)
14-
code, coords, tz = res.groups()
15-
16-
res = re.search(r"([+-]{1})([0-9]+)([+-]{1})([0-9]+)", coords)
17-
lat_sign, lat_val, long_sign, long_val = res.groups()
23+
coords, tz = line.split('\t')[1:3]
24+
lat_sign, lat_val, long_sign, long_val = COORDS_RE.search(coords).groups()
1825

1926
lat_str = lat_sign + lat_val[0:2] + "." + lat_val[2:]
2027
long_str = long_sign + long_val[0:3] + "." + long_val[3:]
@@ -25,17 +32,17 @@
2532
d[tz] = [lat, long]
2633

2734
header = """
28-
// Generated from /usr/share/zoneinfo/zone.tab, used by csd-nightlight.c to calculate sunrise and sunset based on the system timezone
35+
// Generated from %s, used by csd-nightlight.c to calculate sunrise and sunset based on the system timezone
2936
3037
typedef struct
3138
{
32-
const char *timezone;
39+
const gchar *timezone;
3340
double latitude;
3441
double longitude;
3542
} TZCoords;
3643
3744
static TZCoords tz_coord_list[] = {
38-
"""
45+
""" % (args.zone_tab)
3946

4047
for zone in sorted(d.keys()):
4148
latitude, longitude = d[zone]
@@ -44,7 +51,7 @@
4451

4552
header += "};"
4653

47-
with open("tz-coords.h", "w") as f:
54+
with open(args.out_file, "w") as f:
4855
f.write(header)
4956

50-
quit()
57+
quit()

plugins/color/meson.build

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
plugin_name='color'
22

3+
if get_option('generate_tz_coords')
4+
prog_python = find_program('python3')
5+
6+
tz_coords_h = custom_target(
7+
'tz_coords_h',
8+
input: get_option('zone_tab'),
9+
output: 'tz-coords.h',
10+
command: [prog_python, '@CURRENT_SOURCE_DIR@/generate-tz-header.py', '-i', '@INPUT@', '-o', '@OUTPUT@']
11+
)
12+
else
13+
tz_coords_h = files('tz-coords.h')
14+
endif
315

416
built_sources = gnome.gdbus_codegen(
517
'cinnamon-session-dbus',
@@ -32,7 +44,7 @@ color_deps = [
3244

3345
executable(
3446
'csd-' + plugin_name,
35-
sources + built_sources,
47+
sources + built_sources + [tz_coords_h],
3648
include_directories: [include_dirs, common_inc],
3749
dependencies: color_deps,
3850
c_args: [

0 commit comments

Comments
 (0)