Skip to content

Commit

Permalink
sdformat14: support multiple python versions (#2849)
Browse files Browse the repository at this point in the history
* add patches
* revision bump
* update  bottle.

Signed-off-by: Steve Peters <[email protected]>
Co-authored-by: OSRF Build Bot <[email protected]>
  • Loading branch information
scpeters and osrfbuild authored Nov 7, 2024
1 parent ff1f58a commit f68f104
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions Formula/sdformat14.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,76 @@ class Sdformat14 < Formula
url "https://osrf-distributions.s3.amazonaws.com/sdformat/releases/sdformat-14.5.0.tar.bz2"
sha256 "4b0a99a51378a73e0e3bc209c244eff127ded55a3724d614b8cf051e7d905273"
license "Apache-2.0"
revision 1
revision 2

head "https://github.com/gazebosim/sdformat.git", branch: "main"

bottle do
root_url "https://osrf-distributions.s3.amazonaws.com/bottles-simulation"
sha256 sonoma: "a86f783aae1361e4646bbfe3c9704efdfbf3a432175d1110787c26b26a848b4f"
sha256 ventura: "356dd92e2367af5ddebce7d1708ac7c8982e80855d2dd5ef4cdea35f9386129c"
sha256 monterey: "6c4252571144290e9561d79393699940e5a1363a4cd4ee83d9607fd5b5c5c270"
sha256 sonoma: "3c4e3786e5fbd1017b300fcebf8c092f84216a052f27c9e0228ecd81281384d0"
sha256 ventura: "cc4c31cf4369892f763f39d995d287c88731aeb1416d13e2acfc0e0e197445d8"
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-cmake3"
depends_on "gz-math7"
depends_on "gz-tools2"
depends_on "gz-utils2"
depends_on macos: :mojave # c++17
depends_on "[email protected]"
depends_on "tinyxml2"
depends_on "urdfdom"

def python_cmake_arg
"-DPython3_EXECUTABLE=#{which("python3")}"
patch do
# Support building python bindings against external sdformat library part 1
# Remove this patch with the next release
url "https://github.com/gazebosim/sdformat/commit/dcd3cd61402a2278db3ac021442a6e7458fa79b9.patch?full_index=1"
sha256 "2f92c942ccb4e474d086e57cf7089e5aac3b26217a2b2304c7aadc5c34a354f5"
end

patch do
# Support building python bindings against external sdformat library part 2
# Remove this patch with the next release
url "https://github.com/gazebosim/sdformat/commit/91d9029b867a35349b3be85dbe9333feeb2b503c.patch?full_index=1"
sha256 "6ee0532d398b67de5004c321bdbe9a6d0f7d232c9cabfaf4a8468f2e967d7b77"
end

def pythons
deps.map(&:to_formula)
.select { |f| f.name.match?(/^python@3\.\d+$/) }
end

def python_cmake_arg(python = Formula["[email protected]"])
"-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 @@ -92,6 +119,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_libexec/"bin/python", "-c", "import sdformat14"
pythons.each do |python|
system python.opt_libexec/"bin/python", "-c", "import sdformat14"
end
end
end

0 comments on commit f68f104

Please sign in to comment.