xref: /llvm-project/lldb/packages/Python/lldbsuite/test/lldbplatform.py (revision 8652b249e6ede3f495bf96820b6f34110aafa84d)
1""" This module represents an abstraction of an lldb target / host platform. """
2
3from __future__ import absolute_import
4
5# System modules
6import itertools
7
8# Third-party modules
9import six
10
11# LLDB modules
12import use_lldb_suite
13import lldb
14
15windows, linux, macosx, darwin, ios, tvos, watchos, bridgeos, darwin_all, darwin_embedded, freebsd, netbsd, bsd_all, android = range(
16    14)
17
18__name_lookup = {
19    windows: ["windows"],
20    linux: ["linux"],
21    macosx: ["macosx"],
22    darwin: ["darwin"],
23    ios: ["ios"],
24    tvos: ["tvos"],
25    watchos: ["watchos"],
26    bridgeos: ["bridgeos"],
27    darwin_all: ["macosx", "darwin", "ios", "tvos", "watchos", "bridgeos"],
28    darwin_embedded: ["ios", "tvos", "watchos", "bridgeos"],
29    freebsd: ["freebsd"],
30    netbsd: ["netbsd"],
31    bsd_all: ["freebsd", "netbsd"],
32    android: ["android"]
33}
34
35
36def translate(values):
37
38    if isinstance(values, six.integer_types):
39        # This is a value from the platform enumeration, translate it.
40        return __name_lookup[values]
41    elif isinstance(values, six.string_types):
42        # This is a raw string, return it.
43        return [values]
44    elif hasattr(values, "__iter__"):
45        # This is an iterable, convert each item.
46        result = [translate(x) for x in values]
47        result = list(itertools.chain(*result))
48        return result
49    return values
50