Skip to content
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

sdformat15: support multiple python versions #2836

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions Formula/gz-math8.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
class GzMath8 < Formula
desc "Math API for robotic applications"
homepage "https://gazebosim.org"
url "https://osrf-distributions.s3.amazonaws.com/gz-math/releases/gz-math-8.0.0.tar.bz2"
sha256 "dfc15a78aa52f5e200da991e92ebcbd0bd6f9529326dbe3a1a365ad6d7da9669"
url "https://github.com/gazebosim/gz-math.git", branch: "scpeters/build_python_bindings_separately"
version "8.0.0~pre1"
license "Apache-2.0"

head "https://github.com/gazebosim/gz-math.git", branch: "gz-math8"

bottle do
root_url "https://osrf-distributions.s3.amazonaws.com/bottles-simulation"
sha256 cellar: :any, sonoma: "d8579d9bf3c0daf39405ef8b7d5695988e5cadd12af596a887b12f7c1ca3e426"
sha256 cellar: :any, ventura: "abd335fc1d7e07926aa272efdf4158bf369f4b47b7f86312a71653e39373c177"
end

depends_on "cmake" => :build
depends_on "doxygen" => :build
depends_on "pybind11" => :build
depends_on "[email protected]" => [:build, :test]
depends_on "[email protected]" => [:build, :test]
depends_on "pkg-config" => :test
depends_on "eigen"
depends_on "gz-cmake4"
depends_on "gz-utils3"
depends_on "[email protected]"
depends_on "ruby"

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", "../src/python_pybind11", *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
Expand Down Expand Up @@ -78,6 +86,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 gz.math8"
pythons.each do |python|
system python.opt_libexec/"bin/python", "-c", "import gz.math8"
end
end
end
44 changes: 27 additions & 17 deletions Formula/sdformat15.rb
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
Expand Down Expand Up @@ -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
Loading