summaryrefslogtreecommitdiffstats
path: root/meta/site/arm-common
blob: 198c98c6a7498c747beeda5ef9a96ca31828381a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# general
ac_cv_va_val_copy=${ac_cv_va_val_copy=yes}
ac_cv_func_lstat_dereferences_slashed_symlink=${ac_cv_func_lstat_dereferences_slashed_symlink=yes}
ac_cv_func_lstat_empty_string_bug=${ac_cv_func_lstat_empty_string_bug=no}
ac_cv_func_stat_empty_string_bug=${ac_cv_func_stat_empty_string_bug=no}
ac_cv_func_stat_ignores_trailing_slash=${ac_cv_func_stat_ignores_trailing_slash=no}
ac_cv_header_netinet_sctp_h=${ac_cv_header_netinet_sctp_h=no}
ac_cv_header_netinet_sctp_uio_h=${ac_cv_header_netinet_sctp_uio_h=no}
ac_cv_sctp=${ac_cv_sctp=no}

# bash
ac_cv_c_long_double=${ac_cv_c_long_double=yes}
bash_cv_func_sigsetjmp=${bash_cv_func_sigsetjmp=missing}

# coreutils
utils_cv_sys_open_max=${utils_cv_sys_open_max=1019}

# cvs
cvs_cv_func_printf_ptr=${cvs_cv_func_printf_ptr=yes}

# db (sleepycat)
db_cv_fcntl_f_setfd=${db_cv_fcntl_f_setfd=yes}
db_cv_sprintf_count=${db_cv_sprintf_count=yes}
db_cv_align_t=${db_cv_align_t='unsigned long long'}
db_cv_alignp_t=${db_cv_alignp_t='unsigned long'}

# D-BUS
ac_cv_func_posix_getpwnam_r=${ac_cv_func_posix_getpwnam_r=yes}

# edb
db_cv_spinlocks=${db_cv_spinlocks=no}

# ettercap
ettercap_cv_type_socklen_t=${ettercap_cv_type_socklen_t=yes}

# fget
compat_cv_func_snprintf_works=${compat_cv_func_snprintf_works=yes}
compat_cv_func_basename_works=${compat_cv_func_basename_works=no}
compat_cv_func_dirname_works=${compat_cv_func_dirname_works=no}

# fnmatch
ac_cv_func_fnmatch_works=${ac_cv_func_fnmatch_works=yes}

# gettext
am_cv_func_working_getline=${am_cv_func_working_getline=yes}

# glib
glib_cv_stack_grows=${glib_cv_stack_grows=no}
glib_cv_uscore=${glib_cv_uscore=no}
glib_cv_use_pid_surrogate=${glib_cv_use_pid_surrogate=yes}
glib_cv_has__inline=${glib_cv_has__inline=yes}
glib_cv_has__inline__=${glib_cv_has__inline__=yes}
glib_cv_hasinline=${glib_cv_hasinline=yes}
glib_cv_sane_realloc=${glib_cv_sane_realloc=yes}
glib_cv_uscore=${glib_cv_uscore=no}
glib_cv_va_val_copy=${glib_cv_va_val_copy=yes}
glib_cv_rtldglobal_broken=${glib_cv_rtldglobal_broken=no}
glib_cv_sys_pthread_mutex_trylock_posix=${glib_cv_sys_pthread_mutex_trylock_posix=yes}
glib_cv_sys_pthread_getspecific_posix=${glib_cv_sys_pthread_getspecific_posix=yes}
glib_cv_sys_pthread_cond_timedwait_posix=${glib_cv_sys_pthread_cond_timedwait_posix=yes}

# glib-2.0
glib_cv_long_long_format=${glib_cv_long_long_format=ll}
glib_cv_sys_use_pid_niceness_surrogate=${glib_cv_sys_use_pid_niceness_surrogate=yes}

#gstreamer
as_cv_unaligned_access=${as_cv_unaligned_access=no}

# httppc
ac_cv_strerror_r_SUSv3=${ac_cv_strerror_r_SUSv3=no}

# lftp
ac_cv_need_trio=${ac_cv_need_trio=no}
lftp_cv_va_val_copy=${lftp_cv_va_val_copy=yes}

# libesmtp
acx_working_snprintf=${acx_working_snprintf=yes}

# libidl
libIDL_cv_long_long_format=${libIDL_cv_long_long_format=ll}

# libnet 
ac_libnet_have_packet_socket=${ac_libnet_have_packet_socket=yes}

# libpcap
ac_cv_linux_vers=${ac_cv_linux_vers=2}

# libxfce4util
with_broken_putenv=${with_broken_putenv=no}

# links
ac_cv_lib_png_png_create_info_struct=${ac_cv_lib_png_png_create_info_struct=yes}

# mysql
mysql_cv_func_atomic_sub=${mysql_cv_func_atomic_sub=no}
mysql_cv_func_atomic_add=${mysql_cv_func_atomic_add=no}

# nano
ac_cv_regexec_segfault_emptystr=${ac_cv_regexec_segfault_emptystr=no}
nano_cv_func_regexec_segv_emptystr=${nano_cv_func_regexec_segv_emptystr=no}

# php
ac_cv_pread=${ac_cv_pread=no}
ac_cv_pwrite=${ac_cv_pwrite=no}
php_cv_lib_cookie_io_functions_use_off64_t=${php_cv_lib_cookie_io_functions_use_off64_t=yes}

# rsync
rsync_cv_HAVE_BROKEN_LARGEFILE=${rsync_cv_HAVE_BROKEN_LARGEFILE=no}
rsync_cv_HAVE_SOCKETPAIR=${rsync_cv_HAVE_SOCKETPAIR=yes}
rsync_cv_HAVE_LONGLONG=${rsync_cv_HAVE_LONGLONG=yes}
rsync_cv_HAVE_OFF64_T=${rsync_cv_HAVE_OFF64_T=no}
rsync_cv_HAVE_SHORT_INO_T=${rsync_cv_HAVE_SHORT_INO_T=no}
rsync_cv_HAVE_UNSIGNED_CHAR=${rsync_cv_HAVE_UNSIGNED_CHAR=no}
rsync_cv_HAVE_BROKEN_READDIR=${rsync_cv_HAVE_BROKEN_READDIR=no}
rsync_cv_HAVE_GETTIMEOFDAY_TZ=${rsync_cv_HAVE_GETTIMEOFDAY_TZ=yes}
rsync_cv_HAVE_SECURE_MKSTEMP=${rsync_cv_HAVE_SECURE_MKSTEMP=yes}
rsync_cv_REPLACE_INET_NTOA=${rsync_cv_REPLACE_INET_NTOA=no}
rsync_cv_REPLACE_INET_ATON=${rsync_cv_REPLACE_INET_ATON=no}

# screen
screen_cv_sys_bcopy_overlap=${screen_cv_sys_bcopy_overlap=no}
screen_cv_sys_memcpy_overlap=${screen_cv_sys_memcpy_overlap=no}
screen_cv_sys_memmove_overlap=${screen_cv_sys_memmove_overlap=no}
screen_cv_sys_fifo_broken_impl=${screen_cv_sys_fifo_broken_impl=yes}
screen_cv_sys_fifo_usable=${screen_cv_sys_fifo_usable=yes}
screen_cv_sys_select_broken_retval=${screen_cv_sys_select_broken_retval=no}
screen_cv_sys_sockets_nofs=${screen_cv_sys_sockets_nofs=no}
screen_cv_sys_sockets_usable=${screen_cv_sys_sockets_usable=yes}
screen_cv_sys_terminfo_used=${screen_cv_sys_terminfo_used=yes}

# slrn
slrn_cv_va_val_copy=${slrn_cv_va_val_copy=yes}

# socat
ac_cv_ispeed_offset=${ac_cv_ispeed_offset=13}
sc_cv_termios_ispeed=${sc_cv_termios_ispeed=yes}

# ssh
ac_cv_have_space_d_name_in_struct_dirent=${ac_cv_dirent_have_space_d_name=yes}
ac_cv_have_broken_snprintf=${ac_cv_have_broken_snprintf=no}
ac_cv_have_accrights_in_msghdr=${ac_cv_have_accrights_in_msghdr=no}
ac_cv_have_control_in_msghdr=${ac_cv_have_control_in_msghdr=yes}
ac_cv_have_openpty_ctty_bug=${ac_cv_have_openpty_ctty_bug=yes}

# startup-notification
lf_cv_sane_realloc=yes

# xffm
jm_cv_func_working_readdir=yes

# evolution-data-server
ac_cv_libiconv_utf8=${ac_cv_libiconv_utf8=yes}
_dep_regression'>mgh/rpm_dep_regression OpenEmbedded Core user contribution treesGrokmirror user
aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/pythondeps
blob: 3e13a587eefc1a8a2dde34048f6762df47e058e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env python3
#
# Determine dependencies of python scripts or available python modules in a search path.
#
# Given the -d argument and a filename/filenames, returns the modules imported by those files.
# Given the -d argument and a directory/directories, recurses to find all
# python packages and modules, returns the modules imported by these.
# Given the -p argument and a path or paths, scans that path for available python modules/packages.

import argparse
import ast
import importlib
from importlib import machinery
import logging
import os.path
import sys


logger = logging.getLogger('pythondeps')

suffixes = importlib.machinery.all_suffixes()

class PythonDepError(Exception):
    pass


class DependError(PythonDepError):
    def __init__(self, path, error):
        self.path = path
        self.error = error
        PythonDepError.__init__(self, error)

    def __str__(self):
        return "Failure determining dependencies of {}: {}".format(self.path, self.error)


class ImportVisitor(ast.NodeVisitor):
    def __init__(self):
        self.imports = set()
        self.importsfrom = []

    def visit_Import(self, node):
        for alias in node.names:
            self.imports.add(alias.name)

    def visit_ImportFrom(self, node):
        self.importsfrom.append((node.module, [a.name for a in node.names], node.level))


def walk_up(path):
    while path:
        yield path
        path, _, _ = path.rpartition(os.sep)


def get_provides(path):
    path = os.path.realpath(path)

    def get_fn_name(fn):
        for suffix in suffixes:
            if fn.endswith(suffix):
                return fn[:-len(suffix)]

    isdir = os.path.isdir(path)
    if isdir:
        pkg_path = path
        walk_path = path
    else:
        pkg_path = get_fn_name(path)
        if pkg_path is None:
            return
        walk_path = os.path.dirname(path)

    for curpath in walk_up(walk_path):
        if not os.path.exists(os.path.join(curpath, '__init__.py')):
            libdir = curpath
            break
    else:
        libdir = ''

    package_relpath = pkg_path[len(libdir)+1:]
    package = '.'.join(package_relpath.split(os.sep))
    if not isdir:
        yield package, path
    else:
        if os.path.exists(os.path.join(path, '__init__.py')):
            yield package, path

        for dirpath, dirnames, filenames in os.walk(path):
            relpath = dirpath[len(path)+1:]
            if relpath:
                if '__init__.py' not in filenames:
                    dirnames[:] = []
                    continue
                else:
                    context = '.'.join(relpath.split(os.sep))
                    if package:
                        context = package + '.' + context
                    yield context, dirpath
            else:
                context = package

            for fn in filenames:
                adjusted_fn = get_fn_name(fn)
                if not adjusted_fn or adjusted_fn == '__init__':
                    continue

                fullfn = os.path.join(dirpath, fn)
                if context:
                    yield context + '.' + adjusted_fn, fullfn
                else:
                    yield adjusted_fn, fullfn


def get_code_depends(code_string, path=None, provide=None, ispkg=False):
    try:
        code = ast.parse(code_string, path)
    except TypeError as exc:
        raise DependError(path, exc)
    except SyntaxError as exc:
        raise DependError(path, exc)

    visitor = ImportVisitor()
    visitor.visit(code)
    for builtin_module in sys.builtin_module_names:
        if builtin_module in visitor.imports:
            visitor.imports.remove(builtin_module)

    if provide:
        provide_elements = provide.split('.')
        if ispkg:
            provide_elements.append("__self__")
        context = '.'.join(provide_elements[:-1])
        package_path = os.path.dirname(path)
    else:
        context = None
        package_path = None

    levelzero_importsfrom = (module for module, names, level in visitor.importsfrom
                             if level == 0)
    for module in visitor.imports | set(levelzero_importsfrom):
        if context and path:
            module_basepath = os.path.join(package_path, module.replace('.', '/'))
            if os.path.exists(module_basepath):
                # Implicit relative import
                yield context + '.' + module, path
                continue

            for suffix in suffixes:
                if os.path.exists(module_basepath + suffix):
                    # Implicit relative import
                    yield context + '.' + module, path
                    break
            else:
                yield module, path
        else:
            yield module, path

    for module, names, level in visitor.importsfrom:
        if level == 0:
            continue
        elif not provide:
            raise DependError("Error: ImportFrom non-zero level outside of a package: {0}".format((module, names, level)), path)
        elif level > len(provide_elements):
            raise DependError("Error: ImportFrom level exceeds package depth: {0}".format((module, names, level)), path)
        else:
            context = '.'.join(provide_elements[:-level])
            if module:
                if context:
                    yield context + '.' + module, path
                else:
                    yield module, path


def get_file_depends(path):
    try:
        code_string = open(path, 'r').read()
    except (OSError, IOError) as exc:
        raise DependError(path, exc)

    return get_code_depends(code_string, path)


def get_depends_recursive(directory):
    directory = os.path.realpath(directory)

    provides = dict((v, k) for k, v in get_provides(directory))
    for filename, provide in provides.items():
        if os.path.isdir(filename):
            filename = os.path.join(filename, '__init__.py')
            ispkg = True
        elif not filename.endswith('.py'):
            continue
        else:
            ispkg = False

        with open(filename, 'r') as f:
            source = f.read()

        depends = get_code_depends(source, filename, provide, ispkg)
        for depend, by in depends:
            yield depend, by


def get_depends(path):
    if os.path.isdir(path):
        return get_depends_recursive(path)
    else:
        return get_file_depends(path)


def main():
    logging.basicConfig()

    parser = argparse.ArgumentParser(description='Determine dependencies and provided packages for python scripts/modules')
    parser.add_argument('path', nargs='+', help='full path to content to be processed')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-p', '--provides', action='store_true',
                       help='given a path, display the provided python modules')
    group.add_argument('-d', '--depends', action='store_true',
                       help='given a filename, display the imported python modules')

    args = parser.parse_args()
    if args.provides:
        modules = set()
        for path in args.path:
            for provide, fn in get_provides(path):
                modules.add(provide)

        for module in sorted(modules):
            print(module)
    elif args.depends:
        for path in args.path:
            try:
                modules = get_depends(path)
            except PythonDepError as exc:
                logger.error(str(exc))
                sys.exit(1)

            for module, imp_by in modules:
                print("{}\t{}".format(module, imp_by))
    else:
        parser.print_help()
        sys.exit(2)


if __name__ == '__main__':
    main()