Skip to content

Commit

Permalink
gz-msgs10: support multiple python versions (#2843)
Browse files Browse the repository at this point in the history
* Symlink generated python files to versioned python folders.
* 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 1, 2024
1 parent 7fc0eaa commit 59d0189
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions Formula/gz-msgs10.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ class GzMsgs10 < Formula
url "https://osrf-distributions.s3.amazonaws.com/gz-msgs/releases/gz-msgs-10.3.0.tar.bz2"
sha256 "501e475f5602448428a11d16e3d11972a87d5212bd1655d9154e74aa80bd8454"
license "Apache-2.0"
revision 9
revision 10

head "https://github.com/gazebosim/gz-msgs.git", branch: "gz-msgs10"

bottle do
root_url "https://osrf-distributions.s3.amazonaws.com/bottles-simulation"
sha256 sonoma: "09a74f0522f615809badfbfdd4c31809da04605c41501556c4f975cd8d770542"
sha256 ventura: "96f16dc00fa63906c6c8c223916ff2e82fa3aa51eaa6cdd69ae9a8b0de11508d"
end

depends_on "[email protected]" => [:build, :test]
depends_on "[email protected]" => [:build, :test]
depends_on "abseil"
depends_on "cmake"
depends_on "gz-cmake3"
Expand All @@ -17,11 +25,15 @@ class GzMsgs10 < Formula
depends_on macos: :high_sierra # c++17
depends_on "pkg-config"
depends_on "protobuf"
depends_on "[email protected]"
depends_on "tinyxml2"

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 = Formula["[email protected]"])
"-DPython3_EXECUTABLE=#{python.opt_libexec}/bin/python"
end

def install
Expand All @@ -35,8 +47,15 @@ def install
system "make", "install"
end

(lib/"python3.12/site-packages").install Dir[lib/"python/*"]
rmdir prefix/"lib/python"
# this installs python files for each message that can be used by multiple
# versions of python, so symlink the files to versioned python folders
pythons.each do |python|
# remove @ from formula name
python_name = python.name.tr("@", "")
# symlink the python files directly instead of the parent folder to avoid
# brew link errors if there is a pre-existing __pycache__ folder
(lib/"#{python_name}/site-packages/gz/msgs10").install_symlink Dir[lib/"python/gz/msgs10/*"]
end
end

test do
Expand Down Expand Up @@ -73,6 +92,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.msgs10"
pythons.each do |python|
system python.opt_libexec/"bin/python", "-c", "import gz.msgs10"
end
end
end

0 comments on commit 59d0189

Please sign in to comment.