Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump to libfaketime 0.9.10 #75

Merged
merged 3 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 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,18 @@ 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: git submodule update --init --force
- run: env FAKETIME_COMPILE_CFLAGS="-UFAKE_STAT -UFAKE_UTIME -UFAKE_SLEEP" make -C libfaketime/vendor/libfaketime
if: runner.os == 'Linux'
- run: make -C libfaketime/vendor/libfaketime
- run: tox -e ${{ matrix.python }}-${{ matrix.tz }}
if: runner.os == 'macOS'
- run: tox -e ${{ matrix.python }}-${{ matrix.tz }} --recreate
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
7 changes: 6 additions & 1 deletion 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,7 +164,11 @@ Contributing and testing
Contributions are welcome! You should compile libfaketime before running tests:

```bash
make -C libfaketime/vendor/libfaketime
git submodule init --update
# For Linux:
env FAKETIME_COMPILE_CFLAGS="-UFAKE_STAT -UFAKE_UTIME -UFAKE_SLEEP" make -C libfaketime/vendor/libfaketime
# For macOS
env make -C libfaketime/vendor/libfaketime
```

Then you can install requirements with ``pip install -r requirements.txt`` and use ``pytest`` and ``tox`` to run the tests.
Expand Down
24 changes: 13 additions & 11 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,24 +20,17 @@
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.
# This env var is set by reexec to ensure we don't reload more than once.

_DID_REEXEC_VAR = 'FAKETIME_DID_REEXEC'

_FAKETIME_FMT = '%Y-%m-%d %T.%f'

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 Expand Up @@ -168,7 +162,7 @@ def _should_patch_uuid(self):
return None

def _format_datetime(self, _datetime):
return _datetime.strftime('%Y-%m-%d %T %f')
return _datetime.strftime(_FAKETIME_FMT)

def tick(self, delta=datetime.timedelta(seconds=1)):
self.time_to_freeze += delta
Expand All @@ -179,11 +173,13 @@ def __enter__(self):
begin_callback(self)
self._prev_spec = os.environ.get('FAKETIME')
self._prev_tz = os.environ.get('TZ')
self._prev_fmt = os.environ.get('FAKETIME_FMT')

os.environ['TZ'] = self.timezone_str

time.tzset()
os.environ['FAKETIME'] = self._format_datetime(self.time_to_freeze)
os.environ['FAKETIME_FMT'] = _FAKETIME_FMT

func_name = self._should_patch_uuid()
if func_name:
Expand All @@ -208,7 +204,13 @@ def __exit__(self, *exc):
os.environ['FAKETIME'] = self._prev_spec
else:
del os.environ['FAKETIME']
end_callback(self)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, looks like this was a bug before, yeah? it should have been one level out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I suppose, else that would imply that the end callback is only called if there was not a previous FAKETIME environment var defined, and I am not sure how it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do a fix for this in a separate PR if you prefer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it's been fixed. I just wanted to double check it.


if self._prev_fmt is not None:
os.environ['FAKETIME_FMT'] = self._prev_spec
else:
del os.environ['FAKETIME_FMT']

end_callback(self)

return False

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
18 changes: 4 additions & 14 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,7 +38,10 @@
class CustomInstall(install):
def run(self):
self.my_outputs = []
subprocess.check_call(['make', '-C', _vendor_path])
if sys.platform in ("linux", "linux2"):
subprocess.check_call(['env', 'FAKETIME_COMPILE_CFLAGS=-UFAKE_STAT -UFAKE_UTIME -UFAKE_SLEEP', 'make', '-C', _vendor_path])
elif sys.platform == "darwin":
subprocess.check_call(['make', '-C', _vendor_path])

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