-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add support for cached generators #301
Changes from 10 commits
409875a
03e348e
0915477
e29d16c
fde1a64
19f83c1
772c992
1f01fb7
1bd7155
081f7fb
b486cb0
8a1cdb3
12041ca
3397ee9
5bb1d1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ docs/_build | |
# IDE junk | ||
.idea/* | ||
*.swp | ||
.vscode/* | ||
|
||
# build output (testing) | ||
skbuild/_cmake_test_compile/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import os.path | ||
import sys | ||
import argparse | ||
import json | ||
|
||
from contextlib import contextmanager | ||
from distutils.errors import (DistutilsArgError, | ||
|
@@ -23,6 +24,11 @@ | |
except ImportError: | ||
from io import StringIO | ||
|
||
try: | ||
from shutil import which | ||
except ImportError: | ||
from distutils.spawn import find_executable as which | ||
|
||
from setuptools import setup as upstream_setup | ||
from setuptools.dist import Distribution as upstream_Distribution | ||
|
||
|
@@ -31,7 +37,7 @@ | |
install, install_lib, install_scripts, | ||
bdist, bdist_wheel, egg_info, | ||
sdist, generate_source_manifest, test) | ||
from .constants import CMAKE_INSTALL_DIR | ||
from .constants import CMAKE_INSTALL_DIR, CMAKE_ARGUMENTS_FILE | ||
from .exceptions import SKBuildError, SKBuildGeneratorNotFoundError | ||
from .utils import (mkdir_p, PythonModuleFinder, to_platform_path, to_unix_path) | ||
|
||
|
@@ -290,6 +296,27 @@ def _should_run_cmake(commands, cmake_with_sdist): | |
return False | ||
|
||
|
||
def _save_cmake_args(args): | ||
"""Save the CMake arguments to disk""" | ||
# We use JSON here because readability is more important than performance | ||
try: | ||
os.makedirs(os.path.dirname(CMAKE_ARGUMENTS_FILE)) | ||
except OSError: | ||
pass | ||
|
||
with open(CMAKE_ARGUMENTS_FILE, 'w+') as fp: | ||
json.dump(args, fp) | ||
|
||
|
||
def _load_cmake_args(): | ||
"""Load and return the CMake arguments from disk""" | ||
try: | ||
with open(CMAKE_ARGUMENTS_FILE) as fp: | ||
return json.load(fp) | ||
except (OSError, IOError, ValueError): | ||
return None | ||
|
||
|
||
# pylint:disable=too-many-locals, too-many-branches | ||
def setup(*args, **kw): # noqa: C901 | ||
"""This function wraps setup() so that we can run cmake, make, | ||
|
@@ -437,17 +464,27 @@ def setup(*args, **kw): # noqa: C901 | |
# weight and when CMake is given multiple times a argument, only the last | ||
# one is considered, let's prepend the one provided in the setup call. | ||
cmake_args = skbuild_kw['cmake_args'] + cmake_args | ||
|
||
# Used to confirm that the cmake executable is the same | ||
cmake_cmd = [which('cmake')] + cmake_args | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think we should ask cmake what is its version. After doing |
||
|
||
# Languages are used to determine a working generator | ||
cmake_languages = skbuild_kw['cmake_languages'] | ||
|
||
try: | ||
cmkr = cmaker.CMaker() | ||
if not skip_cmake: | ||
env = cmkr.configure(cmake_args, | ||
cmake_source_dir=cmake_source_dir, | ||
cmake_install_dir=skbuild_kw['cmake_install_dir'], | ||
languages=cmake_languages) | ||
# skip the configure step for a cached build | ||
env = cmkr.get_cached_env() | ||
if env is None or cmake_cmd != _load_cmake_args(): | ||
env = cmkr.configure( | ||
cmake_args, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One last thing would be to serialize the I suggest to add a function |
||
cmake_source_dir=cmake_source_dir, | ||
cmake_install_dir=skbuild_kw['cmake_install_dir'], | ||
languages=cmake_languages | ||
) | ||
_save_cmake_args(cmake_cmd) | ||
|
||
cmkr.make(make_args, env=env) | ||
except SKBuildGeneratorNotFoundError as ex: | ||
sys.exit(ex) | ||
|
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.
Instead, you could relocate the
which
function currently present in the test helpers.See
scikit-build/tests/__init__.py
Lines 272 to 292 in d5fa09f