Skip to content

Commit

Permalink
feat: bump to libfaketime 0.9.10
Browse files Browse the repository at this point in the history
- update to libfaketime 0.9.10
- the libfaketime submodules points to the upstream
- apply a patch on build
- run GHA on macos 12, 13 and 14
  • Loading branch information
azmeuk committed Apr 30, 2024
1 parent 5472ec0 commit de827b1
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 40 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ on:

jobs:
tests:
name: ${{ matrix.python }}
runs-on: ubuntu-latest
name: ${{ matrix.os }} - python${{ matrix.python }} - ${{ matrix.tz }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- macos-14
- macos-13
- macos-12
python:
- '3.12'
- '3.11'
Expand All @@ -21,15 +26,17 @@ jobs:
- 'utc'
- 'cest'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip|${{ hashFiles('setup.py') }}|${{ hashFiles('setup.cfg') }}
- run: pip install tox
- run: git submodule update --init
- run: make -C libfaketime/vendor/libfaketime
- run: git submodule update --init --force
- run: |
git apply --directory libfaketime/vendor/libfaketime libfaketime/vendor/libfaketime.patch
make -C libfaketime/vendor/libfaketime
- run: tox -e ${{ matrix.python }}-${{ matrix.tz }}
6 changes: 1 addition & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
[submodule "vendor/libfaketime"]
path = libfaketime/vendor/libfaketime
url = https://github.com/simon-weber/libfaketime.git
url = https://github.com/wolfcw/libfaketime.git
branch = python-libfaketime
[submodule "vendor/libfaketime-pre_sierra"]
path = libfaketime/vendor/libfaketime-pre_sierra
url = https://github.com/simon-weber/libfaketime.git
branch = python-libfaketime-pre_sierra
5 changes: 0 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ include libfaketime/vendor/libfaketime/src/Makefile
include libfaketime/vendor/libfaketime/src/Makefile.OSX
include libfaketime/vendor/libfaketime/COPYING
recursive-include libfaketime/vendor/libfaketime/src *.c *.h *.map
include libfaketime/vendor/libfaketime-pre_sierra/Makefile
include libfaketime/vendor/libfaketime-pre_sierra/src/Makefile
include libfaketime/vendor/libfaketime-pre_sierra/src/Makefile.OSX
include libfaketime/vendor/libfaketime-pre_sierra/COPYING
recursive-include libfaketime/vendor/libfaketime-pre_sierra/src *.c *.h *.map
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ In some cases - especially when your tests start other processes - re-execing ca
$ python-libfaketime
export LD_PRELOAD="/home/foo/<snip>/vendor/libfaketime/src/libfaketime.so.1"
export DONT_FAKE_MONOTONIC="1"
export FAKETIME_NO_CACHE="1"
export FAKETIME_DID_REEXEC=true
```

Expand All @@ -163,6 +164,8 @@ Contributing and testing
Contributions are welcome! You should compile libfaketime before running tests:

```bash
git submodule init --update
git apply --directory libfaketime/vendor/libfaketime libfaketime/vendor/libfaketime.patch
make -C libfaketime/vendor/libfaketime
```

Expand Down
10 changes: 2 additions & 8 deletions libfaketime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import functools
import inspect
import os
import platform
import sys
import threading
import time
Expand All @@ -21,7 +20,6 @@
basestring = (str, bytes)


SIERRA_VERSION_TUPLE = (10, 12)

# When using reexec_if_needed, remove_vars=True and a test loader that purges sys.modules
# (like nose), it can be tough to run reexec_if_needed only once.
Expand All @@ -33,12 +31,6 @@
def _get_lib_path():
vendor_dir = 'libfaketime'

if sys.platform == "darwin":
version_tuple = tuple(int(x) for x in platform.mac_ver()[0].split('.'))
pre_sierra = version_tuple < SIERRA_VERSION_TUPLE
if pre_sierra:
vendor_dir = 'libfaketime-pre_sierra'

return os.path.join(
os.path.dirname(__file__),
os.path.join('vendor', vendor_dir, 'src'))
Expand Down Expand Up @@ -71,10 +63,12 @@ def _setup_ld_preload(soname):
_other_additions = {
'linux': {
'DONT_FAKE_MONOTONIC': '1',
'FAKETIME_NO_CACHE': '1',
},
'darwi': {
'DONT_FAKE_MONOTONIC': '1',
'DYLD_FORCE_FLAT_NAMESPACE': '1',
'FAKETIME_NO_CACHE': '1',
},
}

Expand Down
2 changes: 1 addition & 1 deletion libfaketime/vendor/libfaketime
Submodule libfaketime updated 70 files
+23 −0 .github/workflows/make-test.yml
+8 −1 .gitignore
+21 −0 .travis.yml
+2 −0 Makefile
+63 −0 NEWS
+263 −7 README
+40 −16 README.OSX
+27 −20 README.developers
+67 −0 README.packagers
+13 −7 TODO
+1 −1 man/Makefile
+42 −24 man/faketime.1
+0 −25 packaging/Linux/Arch/PKGBUILD-32bit.txt
+0 −30 packaging/Linux/Debian/avoid-spurious-lrt.patch
+0 −40 packaging/Linux/Debian/control
+0 −29 packaging/Linux/Debian/fix-infinite-recursion-on-real_clock_gettime.patch
+0 −3 packaging/Linux/Debian/libfaketime.install
+0 −17 packaging/Linux/Debian/rules
+0 −13 packaging/Linux/Redhat/libfaketime-fix-infinite-recursion-on-real_clock_gettime.patch
+0 −55 packaging/Linux/Redhat/libfaketime.spec.txt
+0 −53 packaging/OSX/Fink/libfaketime.info
+0 −21 packaging/OSX/Homebrew/libfaketime.rb
+0 −45 packaging/OSX/MacPorts/Portfile
+0 −12 packaging/OSX/MacPorts/patch-test-Makefile.OSX.diff
+0 −65 packaging/OSX/README
+0 −14 packaging/README
+68 −20 src/Makefile
+24 −7 src/Makefile.OSX
+58 −17 src/faketime.c
+40 −1 src/faketime_common.h
+1,838 −342 src/libfaketime.c
+1 −1 src/sunos_endian.h
+16 −4 src/time_ops.h
+52 −5 test/Makefile
+1 −1 test/Makefile.OSX
+8 −0 test/_libtest.c
+5 −0 test/_run_test.c
+7 −0 test/_use_lib_test.c
+2 −1 test/functests/common.inc
+7 −6 test/functests/test_exclude_mono.sh
+19 −2 test/functests/test_walkone.sh
+21 −0 test/randomtest.sh
+40 −0 test/repeat_random.c
+72 −0 test/snippets/README
+8 −0 test/snippets/clock_gettime.c
+1 −0 test/snippets/clock_gettime.variable
+8 −0 test/snippets/clock_gettime_heap.c
+1 −0 test/snippets/clock_gettime_heap.variable
+6 −0 test/snippets/getentropy.c
+1 −0 test/snippets/getentropy.variable
+2 −0 test/snippets/getpid.c
+1 −0 test/snippets/getpid.variable
+7 −0 test/snippets/getrandom.c
+1 −0 test/snippets/getrandom.variable
+9 −0 test/snippets/include_headers.h
+2 −0 test/snippets/syscall.c
+8 −0 test/snippets/syscall_clock_gettime.c
+1 −0 test/snippets/syscall_clock_gettime.variable
+8 −0 test/snippets/syscall_clock_gettime_heap.c
+1 −0 test/snippets/syscall_clock_gettime_heap.variable
+2 −0 test/snippets/time.c
+1 −0 test/snippets/time.variable
+19 −17 test/test.sh
+14 −8 test/test_OSX.sh
+10 −0 test/test_constructors.sh
+54 −0 test/test_variable_data.sh
+21 −0 test/timetest.c
+46 −0 test/variadic/inner.c
+70 −0 test/variadic/main.c
+21 −0 test/variadic/outer.c
1 change: 0 additions & 1 deletion libfaketime/vendor/libfaketime-pre_sierra
Submodule libfaketime-pre_sierra deleted from 83c997
38 changes: 38 additions & 0 deletions libfaketime/vendor/libfaketime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff --git a/src/Makefile b/src/Makefile
index 62e924c..6f03e26 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -110,7 +110,7 @@ PREFIX ?= /usr/local
LIBDIRNAME ?= /lib/faketime
PLATFORM ?=$(shell uname)

-CFLAGS += -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_UTIME -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"' $(FAKETIME_COMPILE_CFLAGS)
+CFLAGS += -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_PTHREAD -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"' $(FAKETIME_COMPILE_CFLAGS)
ifeq ($(PLATFORM),SunOS)
CFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
endif
diff --git a/src/libfaketime.c b/src/libfaketime.c
index e632395..09d9019 100644
--- a/src/libfaketime.c
+++ b/src/libfaketime.c
@@ -2384,10 +2384,16 @@ static void parse_ft_string(const char *user_faked_time)
user_faked_time_tm.tm_isdst = -1;
nstime_str = strptime(user_faked_time, user_faked_time_fmt, &user_faked_time_tm);

+ /* the actual format has a " %f" appended. Parse out the microseconds. */
+ char nanosecond_str[7];
+ memcpy(&nanosecond_str, user_faked_time + 20, 6);
+ nanosecond_str[6] = '\0';
+ int nanoseconds = atoi(nanosecond_str) * 1000;
+
if (NULL != nstime_str)
{
user_faked_time_timespec.tv_sec = mktime(&user_faked_time_tm);
- user_faked_time_timespec.tv_nsec = 0;
+ user_faked_time_timespec.tv_nsec = nanoseconds;

if (nstime_str[0] == '.')
{
--
2.45.0

14 changes: 1 addition & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import platform
import re
from setuptools import setup, find_packages
from setuptools.command.install import install
import subprocess
import sys


# libfaketime broke compatibility with osx before sierra.
# We keep a separate submodule for each and choose between them dynamically.
SIERRA_VERSION_TUPLE = (10, 12)

# This hack is from http://stackoverflow.com/a/7071358/1231454;
# the version is kept in a seperate file and gets parsed - this
# way, setup.py doesn't have to import the package.
Expand All @@ -35,13 +29,6 @@
elif sys.platform == "darwin":
libname = 'libfaketime.1.dylib'

version_tuple = tuple(int(x) for x in platform.mac_ver()[0].split('.'))
pre_sierra = version_tuple < SIERRA_VERSION_TUPLE
if pre_sierra:
_vendor_path = 'libfaketime/vendor/libfaketime-pre_sierra'

print("OSX version is %s-sierra: %r" % ('pre' if pre_sierra else 'post', version_tuple))

else:
raise RuntimeError("libfaketime does not support platform %s" % sys.platform)

Expand All @@ -51,6 +38,7 @@
class CustomInstall(install):
def run(self):
self.my_outputs = []
subprocess.check_call(['patch', '-p1', '<', '../libfaketime.patch'], cwd=_vendor_path, shell=True)
subprocess.check_call(['make', '-C', _vendor_path])

dest = os.path.join(self.install_purelib, os.path.dirname(faketime_lib))
Expand Down

0 comments on commit de827b1

Please sign in to comment.