Skip to content

Conversation

eli-schwartz
Copy link
Contributor

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.

@rgommers
Copy link
Contributor

This looks pretty clean to me so far; the one code block moved into write_depfile_for is a straightforward refactor, and the rest seems about as minimal as it gets for adding a new command-line option.

@eli-schwartz eli-schwartz force-pushed the depfile-singletranspile branch from 6c8137d to defbddb Compare July 25, 2022 04:01
@eli-schwartz eli-schwartz marked this pull request as ready for review July 25, 2022 04:01
@eli-schwartz
Copy link
Contributor Author

Tests pass locally.

Comment on lines 724 to 742
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)
Copy link
Contributor

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).

@eli-schwartz eli-schwartz force-pushed the depfile-singletranspile branch from defbddb to 5de9e30 Compare July 27, 2022 22:54
eli-schwartz and others added 4 commits July 28, 2022 16:05
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.
@eli-schwartz eli-schwartz force-pushed the depfile-singletranspile branch from 4046697 to c631e7d Compare July 28, 2022 20:10
@scoder scoder added this to the 3.0 milestone Jul 29, 2022
@scoder scoder merged commit 820b444 into cython:master Jul 29, 2022
@eli-schwartz eli-schwartz deleted the depfile-singletranspile branch July 29, 2022 18:04
@eli-schwartz
Copy link
Contributor Author

Thanks!

Is there interest in backporting this to 0.29.x?

@ev-br
Copy link
Contributor

ev-br commented Jul 30, 2022

Backporting to 0.29.x would need some minor manual tweaks: #4576
(optparse/argparse at least)

@eli-schwartz
Copy link
Contributor Author

Alright, I tried a backport.

@scoder scoder added the feature label Aug 5, 2022
scoder pushed a commit that referenced this pull request Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants