Skip to content

Commit

Permalink
refactor: directly pass libfaketime CFLAGS
Browse files Browse the repository at this point in the history
instead of changing the Makefile C flags in the patch
  • Loading branch information
azmeuk committed Apr 30, 2024
1 parent f0d018d commit 799e8a4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
key: pip|${{ hashFiles('setup.py') }}|${{ hashFiles('setup.cfg') }}
- run: pip install tox
- 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 }}
- run: git apply --directory libfaketime/vendor/libfaketime libfaketime/vendor/nanosecond.patch
- 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
if: runner.os == 'macOS'
- run: tox -e ${{ matrix.python }}-${{ matrix.tz }} --recreate
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ 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
git apply --directory libfaketime/vendor/libfaketime libfaketime/vendor/nanosecond.patch
# 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
25 changes: 25 additions & 0 deletions libfaketime/vendor/nanosecond.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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

7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
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])
subprocess.check_call(['patch', '-p1', '<', '../nanosecond.patch'], cwd=_vendor_path, shell=True)
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

0 comments on commit 799e8a4

Please sign in to comment.