Repository navigation
Commit d042ed6
authored
Read dependent_cmake_flags from the build's CMake cache (pytorch#22053)
### Summary
A wheel entry can declare the CMake options its file depends on, through `dependent_cmake_flags`, so that packaging skips the file when the build did not turn those options on. Those flags were read from a CMake cache resolved through the entry's own source path. For a file that CMake produces that is the build directory, which is right. For a file checked into the source tree it is the working directory, which holds no `CMakeCache.txt`, so `is_cmake_artifact_used()` took its "not a CMake folder, assume it is used" branch and every flag declared on such an entry was silently ignored.
Read the cache from the build command's `cmake_cache_dir` instead, the way `_cuda_libraries_built()` already does. The flags describe what the build turned on, so the build's cache is where to look no matter where the file itself came from.
No wheel changes today. Only two entries in `ext_modules` have a source tree path, `tools/wheel/pip_data_bin_init.py.in` and `backends/cuda/runtime/aoti_cuda_shims.lib`, and neither declares a flag. Every entry that does declare a flag resolves through `%CMAKE_CACHE_DIR%`, so it lands on the identical cache either way.
One edge moves. A `build` command with no `cmake_cache_dir` used to raise from `is_cmake_artifact_used()`. It now returns True there, and `src_path()` raises the same message immediately afterwards, so the error still surfaces with the same text.
### Test plan
Compared the result of `is_cmake_artifact_used()` before and after across all 25 wheel entries in five build shapes: a cache with the flag on, a cache with it off, a cache directory with nothing built in it, a build command with no cache directory, and a build command whose cache directory is None.
Results are identical for every entry in the three shapes a real build takes. In the two shapes where CMake never ran, the 23 entries that need the build directory now return True instead of raising, and `src_path()` raises the identical message right after, which was compared text for text.
Also ran the no cache directory shape with an unrelated `CMakeCache.txt` sitting in the working directory, to confirm the check does not read it.1 parent 3c70c37 commit d042ed6
1 file changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
844 | 844 | | |
845 | 845 | | |
846 | 846 | | |
847 | | - | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
848 | 859 | | |
849 | 860 | | |
850 | 861 | | |
| |||
0 commit comments