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

gz-transport14: support multiple python versions #2855

Merged
merged 6 commits into from
Nov 9, 2024
Merged
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
49 changes: 39 additions & 10 deletions Formula/gz-transport14.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ class GzTransport14 < Formula
url "https://osrf-distributions.s3.amazonaws.com/gz-transport/releases/gz-transport-14.0.0.tar.bz2"
sha256 "88cbcef69f16ea5124ff41766cc59c0277bfc3ae57c405f3fbae1dbee874a1c0"
license "Apache-2.0"
revision 1
revision 2

head "https://github.com/gazebosim/gz-transport.git", branch: "gz-transport14"

bottle do
root_url "https://osrf-distributions.s3.amazonaws.com/bottles-simulation"
sha256 sonoma: "75690bd5d5f2a5d291ade581f3ebcd65dd26d6b56864e0ffc2b46730fe669786"
sha256 ventura: "c49af19223e326ab340c666daa9643c18e0ec3c50db37c2c8d7cab695ca8862d"
end

depends_on "doxygen" => [:build, :optional]
depends_on "pybind11" => :build
depends_on "[email protected]" => [:build, :test]
depends_on "[email protected]" => [:build, :test]

depends_on "abseil"
depends_on "cmake"
Expand All @@ -23,13 +31,24 @@ class GzTransport14 < Formula
depends_on "ossp-uuid"
depends_on "pkg-config"
depends_on "protobuf"
depends_on "[email protected]"
depends_on "sqlite"
depends_on "tinyxml2"
depends_on "zeromq"

def python_cmake_arg
"-DPython3_EXECUTABLE=#{which("python3")}"
patch do
# Support building python bindings against external gz-transport library
# Remove this patch with the next release
url "https://github.com/gazebosim/gz-transport/commit/250e95f0757af410adfaab213b3077c0a501252e.patch?full_index=1"
sha256 "b7184cc5a1e505ff31a43eacb5b5aa6ac217a07b4eec81e1585f14db6806abb0"
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
Expand All @@ -40,16 +59,24 @@ def install
cmake_args = std_cmake_args
cmake_args << "-DBUILD_TESTING=OFF"
cmake_args << "-DCMAKE_INSTALL_RPATH=#{rpaths.join(";")}"
cmake_args << python_cmake_arg

# Use 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 +117,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 gz.transport14"
pythons.each do |python|
system python.opt_libexec/"bin/python", "-c", "import gz.transport14"
end
end
end