Skip to content

Commit

Permalink
Read virtual packages from deb/RPM repositories
Browse files Browse the repository at this point in the history
These virtual packages are supported by the rosdep tool, so should be
acceptable for use here as well.
  • Loading branch information
cottsay committed Mar 26, 2024
1 parent 6bb1db3 commit ba27b04
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ros_buildfarm/debian_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,17 @@ def get_debian_repo_index(debian_repository_baseurl, target, cache_dir):

package_versions[debian_pkg_name] = PlatformPackageDescriptor(version, source_name)

prefix = 'Provides: '
provides = [line[len(prefix):] for line in lines if line.startswith(prefix)]
provides = [provide.strip() for line in provides for provide in line.split(',')]

for provide in provides:
provide_version = None
if ' ' in provide:
provide, provide_spec = provide.split(' ', 1)
if provide_spec.startswith('(=') and provide_spec.endswith(')'):
provide_version = provide_spec[2:-1].strip()

package_versions[provide] = PlatformPackageDescriptor(provide_version, source_name)

return package_versions
12 changes: 12 additions & 0 deletions ros_buildfarm/rpm_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ def get_rpm_repo_index(rpm_repository_baseurl, target, cache_dir):
pkg_source_name = None
package_versions[pkg_name] = PlatformPackageDescriptor(
pkg_version + '-' + pkg_release, pkg_source_name)
pkg_provides = pkg_format.getElementsByTagName('rpm:provides')
for provide in pkg_provides:
for entry in provide.getElementsByTagName('rpm:entry'):
entry_name = entry.getAttribute('name')
if entry.getAttribute('flags') == 'EQ':
entry_version = entry.getAttribute('ver')
entry_release = entry.getAttribute('rel')
desc_version = entry_version + '-' + entry_release
else:
desc_version = None
package_versions[entry_name] = PlatformPackageDescriptor(
desc_version, pkg_source_name)

return package_versions

Expand Down
Binary file not shown.
Binary file added test/mock_rpm_index/9/x86_64/repodata/primary.xml.gz
Binary file not shown.
7 changes: 7 additions & 0 deletions test/mock_rpm_index/9/x86_64/repodata/repomd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
<revision>0</revision>
<data type="primary">
<location href="repodata/primary.xml.gz"/>
</data>
</repomd>
44 changes: 44 additions & 0 deletions test/test_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import pytest

from ros_buildfarm.common import PlatformPackageDescriptor
from ros_buildfarm.common import Target
from ros_buildfarm.package_repo import get_package_repo_data

mock_deb_index_path = os.path.join(os.path.dirname(__file__), 'mock_deb_index')
mock_rpm_index_path = os.path.join(os.path.dirname(__file__), 'mock_rpm_index')


@pytest.mark.parametrize('target,mock_index_path', [
(Target('rhel', '9', 'x86_64'), mock_rpm_index_path),
(Target('ubuntu', 'noble', 'amd64'), mock_deb_index_path),
])
def test_get_repo_data(tmpdir, target, mock_index_path):
mock_index_url = 'file://' + mock_index_path
data = get_package_repo_data(mock_index_url, (target,), str(tmpdir))

assert target in data
target_data = data[target]

expected = PlatformPackageDescriptor('1.2.3-1', 'pkg-with-prov')
assert expected == target_data.get('pkg-with-prov')
assert expected == target_data.get('pkg-with-prov-a')
assert expected == target_data.get('pkg-with-prov-b')

expected = PlatformPackageDescriptor(None, 'pkg-with-prov')
assert expected == target_data.get('pkg-with-prov-no-ver')

0 comments on commit ba27b04

Please sign in to comment.