-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdformat15: support multiple python versions
Build bindings for both [email protected] and [email protected]. Signed-off-by: Steve Peters <[email protected]>
- Loading branch information
Showing
1 changed file
with
27 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,58 @@ | ||
class Sdformat15 < Formula | ||
desc "Simulation Description Format" | ||
homepage "http://sdformat.org" | ||
url "https://osrf-distributions.s3.amazonaws.com/sdformat/releases/sdformat-15.0.0.tar.bz2" | ||
sha256 "c6c65ac60c502143afc2e4e258d66b92d12c4ab37cf91b5852a50eab4d0f3b1f" | ||
url "https://github.com/gazebosim/sdformat.git", branch: "scpeters/build_python_bindings_separately" | ||
version "15.0.0~pre1" | ||
license "Apache-2.0" | ||
|
||
head "https://github.com/gazebosim/sdformat.git", branch: "sdf15" | ||
|
||
bottle do | ||
root_url "https://osrf-distributions.s3.amazonaws.com/bottles-simulation" | ||
sha256 sonoma: "30f1dd8393161bebe0bb8f3bd3e5cc90462e09e3d04294ea1ed0b6928df19159" | ||
sha256 ventura: "212c79cc2989ba711db1a1cbef8dc86b3ed804c61b1278443767a3e475f33473" | ||
end | ||
|
||
depends_on "cmake" => [:build, :test] | ||
depends_on "pkg-config" => [:build, :test] | ||
depends_on "pybind11" => :build | ||
depends_on "[email protected]" => [:build, :test] | ||
depends_on "[email protected]" => [:build, :test] | ||
|
||
depends_on "doxygen" | ||
depends_on "gz-cmake4" | ||
depends_on "gz-math8" | ||
depends_on "gz-tools2" | ||
depends_on "gz-utils3" | ||
depends_on macos: :mojave # c++17 | ||
depends_on "[email protected]" | ||
depends_on "tinyxml2" | ||
depends_on "urdfdom" | ||
|
||
def python_cmake_arg | ||
"-DPython3_EXECUTABLE=#{which("python3")}" | ||
def pythons | ||
deps.map(&:to_formula) | ||
.select { |f| f.name.match?(/^python@3\.\d+$/) } | ||
end | ||
|
||
def python_cmake_arg(python = "[email protected]".to_formula) | ||
"-DPython3_EXECUTABLE=#{python.opt_libexec}/bin/python" | ||
end | ||
|
||
def install | ||
cmake_args = std_cmake_args | ||
cmake_args << "-DBUILD_TESTING=Off" | ||
cmake_args << "-DCMAKE_INSTALL_RPATH=#{rpath}" | ||
cmake_args << python_cmake_arg | ||
|
||
# Use a build folder | ||
# first build without python bindings | ||
mkdir "build" do | ||
system "cmake", "..", *cmake_args | ||
system "cmake", "..", *cmake_args, "-DSKIP_PYBIND11=ON" | ||
system "make", "install" | ||
end | ||
|
||
(lib/"python3.12/site-packages").install Dir[lib/"python/*"] | ||
rmdir prefix/"lib/python" | ||
# now build only the python bindings | ||
pythons.each do |python| | ||
# remove @ from formula name | ||
python_name = python.name.tr("@", "") | ||
mkdir "build_#{python_name}" do | ||
system "cmake", "../python", *cmake_args, python_cmake_arg(python) | ||
system "make", "install" | ||
(lib/"#{python_name}/site-packages").install Dir[lib/"python/*"] | ||
rmdir prefix/"lib/python" | ||
end | ||
end | ||
end | ||
|
||
test do | ||
|
@@ -90,6 +98,8 @@ def install | |
cmd_not_grep_xcode = "! grep -rnI 'Applications[/]Xcode' #{prefix}" | ||
system cmd_not_grep_xcode | ||
# check python import | ||
system Formula["[email protected]"].opt_bin/"python3.12", "-c", "import sdformat15" | ||
pythons.each do |python| | ||
system python.opt_libexec/"bin/python", "-c", "import sdformat15" | ||
end | ||
end | ||
end |