|
18 | 18 | import subprocess
|
19 | 19 | import sys
|
20 | 20 | import textwrap
|
21 |
| -from distutils.dep_util import newer_group |
22 | 21 | from pathlib import Path
|
23 | 22 |
|
24 | 23 | from filelock import FileLock
|
@@ -71,6 +70,47 @@ def _get_files(path):
|
71 | 70 | return all_files
|
72 | 71 |
|
73 | 72 |
|
| 73 | +# copy form distutils.dep_util to avoid import distutils |
| 74 | +def newer_group(sources, target, missing="error"): |
| 75 | + """Return true if 'target' is out-of-date with respect to any file |
| 76 | + listed in 'sources'. In other words, if 'target' exists and is newer |
| 77 | + than every file in 'sources', return false; otherwise return true. |
| 78 | + 'missing' controls what we do when a source file is missing; the |
| 79 | + default ("error") is to blow up with an OSError from inside 'stat()'; |
| 80 | + if it is "ignore", we silently drop any missing source files; if it is |
| 81 | + "newer", any missing source files make us assume that 'target' is |
| 82 | + out-of-date (this is handy in "dry-run" mode: it'll make you pretend to |
| 83 | + carry out commands that wouldn't work because inputs are missing, but |
| 84 | + that doesn't matter because you're not actually going to run the |
| 85 | + commands). |
| 86 | + """ |
| 87 | + # If the target doesn't even exist, then it's definitely out-of-date. |
| 88 | + if not os.path.exists(target): |
| 89 | + return 1 |
| 90 | + |
| 91 | + # Otherwise we have to find out the hard way: if *any* source file |
| 92 | + # is more recent than 'target', then 'target' is out-of-date and |
| 93 | + # we can immediately return true. If we fall through to the end |
| 94 | + # of the loop, then 'target' is up-to-date and we return false. |
| 95 | + from stat import ST_MTIME |
| 96 | + |
| 97 | + target_mtime = os.stat(target)[ST_MTIME] |
| 98 | + for source in sources: |
| 99 | + if not os.path.exists(source): |
| 100 | + if missing == "error": # blow up when we stat() the file |
| 101 | + pass |
| 102 | + elif missing == "ignore": # missing source dropped from |
| 103 | + continue # target's dependency list |
| 104 | + elif missing == "newer": # missing source means target is |
| 105 | + return 1 # out-of-date |
| 106 | + |
| 107 | + source_mtime = os.stat(source)[ST_MTIME] |
| 108 | + if source_mtime > target_mtime: |
| 109 | + return 1 |
| 110 | + else: |
| 111 | + return 0 |
| 112 | + |
| 113 | + |
74 | 114 | class CMakeExtension(Extension):
|
75 | 115 | def __init__(self, name, source_dir=None):
|
76 | 116 | # A CMakeExtension needs a source_dir instead of a file list.
|
|
0 commit comments