Commit 62ed81a0 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

getdeps: update the python wheel builder to support dependencies

Summary:
Correctly emit dependency information when one Python package depends on
another.

Reviewed By: wez

Differential Revision: D17669620

fbshipit-source-id: f51c7851470fe50dc0c17263c94c4d858d6e0921
parent 4474c86b
...@@ -62,6 +62,8 @@ install( ...@@ -62,6 +62,8 @@ install(
CMAKE_CONFIG_FILE = """ CMAKE_CONFIG_FILE = """
@PACKAGE_INIT@ @PACKAGE_INIT@
include(CMakeFindDependencyMacro)
set_and_check({upper_name}_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_DIR@") set_and_check({upper_name}_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_DIR@")
if (NOT TARGET {namespace}::{lib_name}) if (NOT TARGET {namespace}::{lib_name})
...@@ -70,6 +72,8 @@ endif() ...@@ -70,6 +72,8 @@ endif()
set({upper_name}_LIBRARIES {namespace}::{lib_name}) set({upper_name}_LIBRARIES {namespace}::{lib_name})
{find_dependency_lines}
if (NOT {manifest_name}_FIND_QUIETLY) if (NOT {manifest_name}_FIND_QUIETLY)
message(STATUS "Found {manifest_name}: ${{PACKAGE_PREFIX_DIR}}") message(STATUS "Found {manifest_name}: ${{PACKAGE_PREFIX_DIR}}")
endif() endif()
...@@ -120,6 +124,14 @@ class PythonWheelBuilder(BuilderBase): ...@@ -120,6 +124,14 @@ class PythonWheelBuilder(BuilderBase):
if not version.startswith("1."): if not version.startswith("1."):
raise Exception("unsupported wheel version %s" % (version,)) raise Exception("unsupported wheel version %s" % (version,))
# Add a find_dependency() call for each of our dependencies.
# The dependencies are also listed in the wheel METADATA file, but it is simpler
# to pull this directly from the getdeps manifest.
dep_list = sorted(
self.manifest.get_section_as_dict("dependencies", self.ctx).keys()
)
find_dependency_lines = ["find_dependency({})".format(dep) for dep in dep_list]
getdeps_cmake_dir = os.path.join( getdeps_cmake_dir = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "CMake" os.path.dirname(os.path.dirname(__file__)), "CMake"
) )
...@@ -131,6 +143,7 @@ class PythonWheelBuilder(BuilderBase): ...@@ -131,6 +143,7 @@ class PythonWheelBuilder(BuilderBase):
"manifest_name": self.manifest.name, "manifest_name": self.manifest.name,
"namespace": self.manifest.name, "namespace": self.manifest.name,
"upper_name": self.manifest.name.upper().replace("-", "_"), "upper_name": self.manifest.name.upper().replace("-", "_"),
"find_dependency_lines": "\n".join(find_dependency_lines),
} }
# Find sources from the root directory # Find sources from the root directory
...@@ -153,7 +166,7 @@ class PythonWheelBuilder(BuilderBase): ...@@ -153,7 +166,7 @@ class PythonWheelBuilder(BuilderBase):
) )
# Emit CMake files # Emit CMake files
self._write_cmakelists(path_mapping) self._write_cmakelists(path_mapping, dep_list)
self._write_cmake_config_template() self._write_cmake_config_template()
# Run the build # Run the build
...@@ -175,12 +188,14 @@ class PythonWheelBuilder(BuilderBase): ...@@ -175,12 +188,14 @@ class PythonWheelBuilder(BuilderBase):
) )
cmake_builder.build(install_dirs=install_dirs, reconfigure=reconfigure) cmake_builder.build(install_dirs=install_dirs, reconfigure=reconfigure)
def _write_cmakelists(self, path_mapping): def _write_cmakelists(self, path_mapping, dependencies):
# type: (List[str]) -> None # type: (List[str]) -> None
cmake_path = os.path.join(self.build_dir, "CMakeLists.txt") cmake_path = os.path.join(self.build_dir, "CMakeLists.txt")
with open(cmake_path, "w") as f: with open(cmake_path, "w") as f:
f.write(CMAKE_HEADER.format(**self.template_format_dict)) f.write(CMAKE_HEADER.format(**self.template_format_dict))
for dep in dependencies:
f.write("find_package({0} REQUIRED)\n".format(dep))
f.write( f.write(
"add_fb_python_library({lib_name}\n".format(**self.template_format_dict) "add_fb_python_library({lib_name}\n".format(**self.template_format_dict)
...@@ -192,6 +207,10 @@ class PythonWheelBuilder(BuilderBase): ...@@ -192,6 +207,10 @@ class PythonWheelBuilder(BuilderBase):
' "%s=%s"\n' ' "%s=%s"\n'
% (_to_cmake_path(src_path), _to_cmake_path(install_path)) % (_to_cmake_path(src_path), _to_cmake_path(install_path))
) )
if dependencies:
f.write(" DEPENDS\n")
for dep in dependencies:
f.write(' "{0}::{0}"\n'.format(dep))
f.write(")\n") f.write(")\n")
f.write(CMAKE_FOOTER.format(**self.template_format_dict)) f.write(CMAKE_FOOTER.format(**self.template_format_dict))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment