def METHOD_NAME(sources_dir, os_name=None, os_code_name=None):
    cmd = [
        'gbp', 'buildpackage',
        '--git-ignore-new',
        '--git-ignore-branch',
        # dpkg-buildpackage args
        '-S']
    debian_before_stretch = ('squeeze', 'wheezy', 'jessie')
    ubuntu_before_artful = (
        'precise', 'quantal', 'raring', 'saucy',
        'trusty', 'utopic', 'vivid', 'wily',
        'xenial', 'yakkety', 'zesty')
    if (
        os_name == 'debian' and os_code_name not in debian_before_stretch or
        os_name == 'ubuntu' and os_code_name not in ubuntu_before_artful
    ):
        # don't fail for not installed build dependencies
        cmd.append('-d')
        # do not sign the .buildinfo file, since dpkg 1.18.19
        cmd.append('-ui')
    cmd += [
        # dpkg-buildpackage args
        '-us', '-uc',
        # debuild args for lintian
        '--lintian-opts', '--suppress-tags', 'newer-standards-version']
    # workaround for old gbp.conf values
    # https://github.com/ros-infrastructure/bloom/issues/211
    config_cmd = [
        'git', 'config',
        '--file', 'debian/gbp.conf',
        'git-buildpackage.upstream-tree']
    upstream_tree = subprocess.check_output(config_cmd, cwd=sources_dir)
    upstream_tree = upstream_tree.decode().rstrip()
    if upstream_tree != 'tag':
        config_cmd = [
            'git', 'config',
            '--file', 'debian/gbp.conf',
            'git-buildpackage.upstream-branch']
        upstream_tag = subprocess.check_output(config_cmd, cwd=sources_dir)
        upstream_tag = upstream_tag.decode().rstrip()
        cmd += [
            '--git-upstream-tag=' + upstream_tag,
            '--git-upstream-tree=tag']
    # workaround different default compression levels
    # resulting in different checksums for the tarball
    if (os_name, os_code_name) in (('ubuntu', 'zesty'), ('debian', 'stretch')):
        env = dict(os.environ)
        env['GZIP'] = '-9'
    else:
        env = None
    print("Invoking '%s' in '%s'" % (' '.join(cmd), sources_dir))
    subprocess.check_call(cmd, cwd=sources_dir, env=env)