Check if an objects needs to be rebuild based on its dependencies Parameters ---------- obj : str object file Returns ------- bool
(obj, cc_args, extra_postargs, pp_opts)
| 37 | |
| 38 | |
| 39 | def _needs_build(obj, cc_args, extra_postargs, pp_opts): |
| 40 | """ |
| 41 | Check if an objects needs to be rebuild based on its dependencies |
| 42 | |
| 43 | Parameters |
| 44 | ---------- |
| 45 | obj : str |
| 46 | object file |
| 47 | |
| 48 | Returns |
| 49 | ------- |
| 50 | bool |
| 51 | """ |
| 52 | # defined in unixcompiler.py |
| 53 | dep_file = obj + '.d' |
| 54 | if not os.path.exists(dep_file): |
| 55 | return True |
| 56 | |
| 57 | # dep_file is a makefile containing 'object: dependencies' |
| 58 | # formatted like posix shell (spaces escaped, \ line continuations) |
| 59 | # the last line contains the compiler commandline arguments as some |
| 60 | # projects may compile an extension multiple times with different |
| 61 | # arguments |
| 62 | with open(dep_file) as f: |
| 63 | lines = f.readlines() |
| 64 | |
| 65 | cmdline =_commandline_dep_string(cc_args, extra_postargs, pp_opts) |
| 66 | last_cmdline = lines[-1] |
| 67 | if last_cmdline != cmdline: |
| 68 | return True |
| 69 | |
| 70 | contents = ''.join(lines[:-1]) |
| 71 | deps = [x for x in shlex.split(contents, posix=True) |
| 72 | if x != "\n" and not x.endswith(":")] |
| 73 | |
| 74 | try: |
| 75 | t_obj = os.stat(obj).st_mtime |
| 76 | |
| 77 | # check if any of the dependencies is newer than the object |
| 78 | # the dependencies includes the source used to create the object |
| 79 | for f in deps: |
| 80 | if os.stat(f).st_mtime > t_obj: |
| 81 | return True |
| 82 | except OSError: |
| 83 | # no object counts as newer (shouldn't happen if dep_file exists) |
| 84 | return True |
| 85 | |
| 86 | return False |
| 87 | |
| 88 | |
| 89 | def replace_method(klass, method_name, func): |
no test coverage detected