Skip to content

Commit

Permalink
[tz] Add source database to package as default
Browse files Browse the repository at this point in the history
* This replaces the iana binary tzdb with the source tzdb as the
  default. This is because this is what's supported most comprehensively
  by the date package. This still retains the option to build the binary
  database if required.

Closes #21670
  • Loading branch information
samuel-emrys committed Dec 7, 2023
1 parent 7ca6977 commit 69914f8
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 23 deletions.
76 changes: 58 additions & 18 deletions recipes/tz/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class TzConan(ConanFile):
description = "The Time Zone Database contains data that represent the history of local time for many representative locations around the globe."
topics = ("tz", "tzdb", "time", "zone", "date")
settings = "os", "build_type", "arch", "compiler"
options = {"with_binary_db": [True, False]}
default_options = {"with_binary_db": False}

@property
def _settings_build(self):
Expand All @@ -29,13 +31,16 @@ def layout(self):

def package_id(self):
del self.info.settings.compiler
if not self.info.options.with_binary_db:
self.info.clear()

def build_requirements(self):
self.tool_requires("mawk/1.3.4-20230404")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
if self.options.with_binary_db:
self.tool_requires("mawk/1.3.4-20230404")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
Expand All @@ -50,24 +55,59 @@ def _patch_sources(self):
replace_in_file(self, os.path.join(self.source_folder, "Makefile"), "AWK= awk", f"AWK={awk_path}")

def build(self):
self._patch_sources()
autotools = Autotools(self)
autotools.make(args=["-C", self.source_folder.replace("\\", "/")])
if self.options.with_binary_db:
self._patch_sources()
autotools = Autotools(self)
autotools.make(args=["-C", self.source_folder.replace("\\", "/")])

def package(self):
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
autotools = Autotools(self)
destdir = self.package_folder.replace('\\', '/')
autotools.install(args=["-C", self.source_folder.replace("\\", "/"), f"DESTDIR={destdir}"])
rmdir(self, os.path.join(self.package_folder, "usr", "share", "man"))
# INFO: The library does not have a public API, it's used to build the zic and zdump tools
rmdir(self, os.path.join(self.package_folder, "usr", "lib"))
if self.options.with_binary_db:
autotools = Autotools(self)
destdir = self.package_folder.replace('\\', '/')
autotools.install(args=["-C", self.source_folder.replace("\\", "/"), f"DESTDIR={destdir}"])
rmdir(self, os.path.join(self.package_folder, "usr", "share", "man"))
# INFO: The library does not have a public API, it's used to build the zic and zdump tools
rmdir(self, os.path.join(self.package_folder, "usr", "lib"))
else:
tzdata = [
"africa",
"antarctica",
"asia",
"australasia",
"backward",
"backzone",
"calendars",
"checklinks.awk",
"checktab.awk",
"etcetera",
"europe",
"factory",
"iso3166.tab",
"leap-seconds.list",
"leapseconds",
"leapseconds.awk",
"NEWS",
"northamerica",
"southamerica",
"version",
"ziguard.awk",
"zishrink.awk",
"zone.tab",
"zone1970.tab",
]
for data in tzdata:
copy(self, data, dst=os.path.join(self.package_folder, "res", "tzdata"), src=self.source_folder)

def package_info(self):
self.cpp_info.libdirs = []
self.cpp_info.includedirs = []
self.cpp_info.frameworkdirs = []
self.cpp_info.resdirs = [os.path.join("usr", "share")]
self.cpp_info.bindirs = [os.path.join("usr", "bin"), os.path.join("usr", "sbin")]
self.buildenv_info.define("TZDATA", os.path.join(self.package_folder, "usr", "share", "zoneinfo"))
self.runenv_info.define("TZDATA", os.path.join(self.package_folder, "usr", "share", "zoneinfo"))
self.cpp_info.resdirs = ["res"]
self.buildenv_info.define("TZDATA", os.path.join(self.package_folder, "res", "tzdata"))
self.runenv_info.define("TZDATA", os.path.join(self.package_folder, "res", "tzdata"))
if self.options.with_binary_db:
self.cpp_info.resdirs = [os.path.join("usr", "share")]
self.cpp_info.bindirs = [os.path.join("usr", "bin"), os.path.join("usr", "sbin")]
self.buildenv_info.define("TZDATA", os.path.join(self.package_folder, "usr", "share", "zoneinfo"))
self.runenv_info.define("TZDATA", os.path.join(self.package_folder, "usr", "share", "zoneinfo"))
22 changes: 17 additions & 5 deletions recipes/tz/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.layout import basic_layout
from conan.errors import ConanException
import os

Expand All @@ -14,14 +15,19 @@ class TzTestConan(ConanFile):
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
self.tool_requires(self.tested_reference_str)
if self._settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

def generate(self):
# INFO: zdump does not consume TZDATA, need to pass absolute path of the zoneinfo directory
self.tzdata = self.dependencies.build['tz'].buildenv_info.vars(self).get('TZDATA')
self.tzdata = self.dependencies['tz'].runenv_info.vars(self).get('TZDATA')
with open("tzdata.info", "w") as fd:
fd.write(self.tzdata)

Expand All @@ -30,6 +36,12 @@ def build(self):

def test(self):
if can_run(self):
with open("tzdata.info", "r") as fd:
self.tzdata = fd.read()
self.run(f"zdump {os.path.join(self.tzdata, 'America', 'Los_Angeles')}")
if self.dependencies['tz'].options.with_binary_db:
self.output.info("Test that binary tzdb is readable")
with open("tzdata.info", "r") as fd:
self.tzdata = fd.read()
self.run(f"zdump {os.path.join(self.tzdata, 'America', 'Los_Angeles')}", env="conanrun")
else:
self.output.info("Test that source tzdb is readable")
cmd = "python -c 'import os; tzdata = os.environ[\"TZDATA\"]; f=open(os.path.join(tzdata, \"factory\"), \"r\"); s = f.read(); f.close(); print(s)'"
self.run(cmd, env="conanrun")

0 comments on commit 69914f8

Please sign in to comment.