Skip to content
Merged
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
14 changes: 11 additions & 3 deletions lddwrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,18 @@ def _cmd_output_parser(cmd_out: str) -> List[Dependency]:
"""
dependencies = [] # type: List[Dependency]

for line in [
line.strip() for line in cmd_out.split('\n') if line.strip() != ''
]:
lines = [line.strip() for line in cmd_out.split('\n') if line.strip() != '']

if len(lines) == 0:
return []

# This is a special case of a static library. The first line refers
# to the library and the second line indicates that the library
# was statically linked.
if len(lines) == 2 and lines[1] == 'statically linked':
return []

for line in lines:
dep = _parse_line(line=line)
if dep is not None:
dependencies.append(dep)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_ldd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Test lddwrap."""
# pylint: disable=missing-docstring,too-many-public-methods
import pathlib
import tempfile
import textwrap
import unittest
from typing import Any, List, Optional
Expand Down Expand Up @@ -140,6 +141,17 @@ def test_parse_wrong_line(self):
'Expected 2 parts in the line but found {}: {}'.format(
line.count(' ') + 1, line), str(run_err))

def test_parse_static(self) -> None:
"""Test parsing of the output when we ldd a static library."""
# pylint: disable=protected-access
deps = lddwrap._cmd_output_parser(
textwrap.dedent('''\
my_static_lib.so:
statically linked
'''))

self.assertListEqual([], deps)


class TestAgainstMockLdd(unittest.TestCase):
def test_pwd(self):
Expand Down Expand Up @@ -308,6 +320,24 @@ def test_with_fantasy_unused(self):
[], diff_dependencies(ours=dep, theirs=exp_dep),
"Mismatch at the unused dependency {}".format(i))

def test_with_static_library(self) -> None:
"""Test against a fantasy static library."""
with tempfile.TemporaryDirectory() as tmp_dir:
lib_pth = pathlib.Path(tmp_dir) / "my_static_lib.so"
lib_pth.write_text("totally static!")

with tests.MockLdd(
out=textwrap.dedent('''\
my_static_lib.so:
\tstatically linked\n'''),
out_unused=''):
# pylint: enable=line-too-long
deps = lddwrap.list_dependencies(path=lib_pth, unused=True)

# The dependencies are empty since the library is
# statically linked.
self.assertListEqual([], deps)


class TestSorting(unittest.TestCase):
def test_sorting_by_all_attributes(self) -> None:
Expand Down