-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
implement the depfile command-line option for the "cython" tool #4916
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
Conversation
This looks pretty clean to me so far; the one code block moved into |
6c8137d
to
defbddb
Compare
Tests pass locally. |
Cython/Build/Dependencies.py
Outdated
def write_depfile_for(self, source, c_file): | ||
dependencies = self.all_dependencies(source) | ||
src_base_dir, _ = os.path.split(source) | ||
cwd = os.getcwd() | ||
if not src_base_dir.endswith(os.sep): | ||
src_base_dir += os.sep | ||
# paths below the base_dir are relative, otherwise absolute | ||
paths = [] | ||
for fname in dependencies: | ||
if fname.startswith(src_base_dir): | ||
paths.append(os.path.relpath(fname, cwd)) | ||
else: | ||
paths.append(os.path.abspath(fname)) | ||
|
||
depline = os.path.relpath(c_file, cwd) + ": \\\n " | ||
depline += " \\\n ".join(paths) + "\n" | ||
|
||
with open(c_file+'.dep', 'w') as outfile: | ||
outfile.write(depline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excluding the call to self.all_dependencies()
, I think this can be moved to Utils.py
where most of the file related utilities live. It's generally a good idea to separate calculation (i.e. figuring out the dependencies) from representation (i.e. writing them down into a dependency file).
defbddb
to
5de9e30
Compare
We would like to use it in the frontend for the cython tool as well. Pull it out of the main loop and make it a utility function.
The paths for files in the source tree are relative instead of absolute. This is not inherently a problem, but they are relative to the containing directory of the source code file but the program that parses these files (make, ninja) computes filenames relative to its working directory, not relative to the source file. Likewise, the final output file had its entire path component trimmed, leaving just a bare filename. Make this actually work by computing all relative paths relative to the current working directory of the cython process itself. When invoked by a build system, this will be the same directory the build system expects files to be based on.
This acts the same as the option for the cythonize tool.
4046697
to
c631e7d
Compare
Thanks! Is there interest in backporting this to 0.29.x? |
Backporting to 0.29.x would need some minor manual tweaks: #4576 |
Alright, I tried a backport. |
Tested with the cythoner from SciPy after editing in the -M argument and updating lots of meson generators to expect a depfile.
/cc @rgommers @ev-br
I do not like the delayed import of
Build.Dependencies.DependencyTree
but it is needed to avoid a circular import, if anyone has suggestions to fix this I'm all ears. (I think this would require more refactoring than I'm comfortable with, but TBH the code is massively confusing in layout to me.)This is missing tests but I have no time left today for that (I'll finish this up on Sunday), so, posting for discussion.