Пример #1
0
def main(args):
    """gbs clone entry point."""

    # Determine upstream branch
    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')
    packaging_branch = configmgr.get_arg_conf(args, 'packaging_branch')
    # Construct GBP cmdline arguments
    gbp_args = [
        'dummy argv[0]', '--color-scheme=magenta:green:yellow:red',
        '--pristine-tar',
        '--upstream-branch=%s' % upstream_branch,
        '--packaging-branch=%s' % packaging_branch
    ]
    if args.all:
        gbp_args.append('--all')
    if args.depth:
        gbp_args.append('--depth=%s' % args.depth)
    if args.debug:
        gbp_args.append("--verbose")
    gbp_args.append(args.uri)
    if args.directory:
        gbp_args.append(args.directory)

    # Clone
    log.info('cloning %s' % args.uri)
    if do_clone(gbp_args):
        raise GbsError('Failed to clone %s' % args.uri)

    log.info('finished')
Пример #2
0
def main(args):
    """gbs clone entry point."""

    # Determine upstream branch
    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')
    packaging_branch = configmgr.get_arg_conf(args, 'packaging_branch')
    # Construct GBP cmdline arguments
    gbp_args = ['dummy argv[0]',
                '--color-scheme=magenta:green:yellow:red',
                '--pristine-tar',
                '--upstream-branch=%s' % upstream_branch,
                '--packaging-branch=%s' % packaging_branch]
    if args.all:
        gbp_args.append('--all')
    if args.depth:
        gbp_args.append('--depth=%s' % args.depth)
    if args.debug:
        gbp_args.append("--verbose")
    gbp_args.append(args.uri)
    if args.directory:
        gbp_args.append(args.directory)

    # Clone
    log.info('cloning %s' % args.uri)
    if do_clone(gbp_args):
        raise GbsError('Failed to clone %s' % args.uri)

    log.info('finished')
Пример #3
0
def main(args):
    """gbs pull entry point."""

    # Determine upstream branch
    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')

    # Construct GBP cmdline arguments
    gbp_args = [
        'dummy argv[0]', '--color-scheme=magenta:green:yellow:red',
        '--pristine-tar',
        '--upstream-branch=%s' % upstream_branch, '--packaging-branch=master'
    ]
    if args.depth:
        gbp_args.append('--depth=%s' % args.depth)
    if args.force:
        gbp_args.append('--force=clean')
    if args.all:
        gbp_args.append('--all')
    if args.debug:
        gbp_args.append("--verbose")

    # Clone
    log.info('updating from remote')
    ret = do_pull(gbp_args)
    if ret == 2:
        raise GbsError('Failed to update some of the branches!')
    elif ret:
        raise GbsError('Update failed!')

    log.info('finished')
Пример #4
0
def compose_gbp_args(repo, tmp_dir, spec, args):
    """Compose command line arguments for gbp-pq-rpm"""
    upstream_tag = configmgr.get_arg_conf(args, 'upstream_tag')
    # transform variables from shell to python convention ${xxx} -> %(xxx)s
    upstream_tag = re.sub(r'\$\{([^}]+)\}', r'%(\1)s', upstream_tag)

    packaging_dir = get_packaging_dir(args)

    # Compose the list of command line arguments
    argv = ["argv[0] placeholder",
            "--color-scheme=magenta:green:yellow:red",
            "--vendor=Tizen",
            "--tmp-dir=%s" % tmp_dir,
            "--packaging-dir=%s" % packaging_dir,
            "--new-packaging-dir=%s" % packaging_dir,
            "--spec-file=%s" % spec,
            "--upstream-tag=%s" % upstream_tag,
            "--pq-branch=development/%(branch)s/%(upstreamversion)s",
            "--import-files=.gbs.conf",
            "--patch-export-compress=100k",
            "--patch-export-ignore-path=^(%s/.*|.gbs.conf)" % packaging_dir]
    if args.debug:
        argv.append("--verbose")
    if args.retain_history:
        argv.append("--retain-history")

    return argv
Пример #5
0
def main(args):
    """gbs pull entry point."""

    # Determine upstream branch
    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')

    # Construct GBP cmdline arguments
    gbp_args = ['dummy argv[0]',
                '--color-scheme=magenta:green:yellow:red',
                '--pristine-tar',
                '--upstream-branch=%s' % upstream_branch,
                '--packaging-branch=master']
    if args.depth:
        gbp_args.append('--depth=%s' % args.depth)
    if args.force:
        gbp_args.append('--force=clean')
    if args.all:
        gbp_args.append('--all')
    if args.debug:
        gbp_args.append("--verbose")

    # Clone
    log.info('updating from remote')
    ret = do_pull(gbp_args)
    if ret == 2:
        raise GbsError('Failed to update some of the branches!')
    elif ret:
        raise GbsError('Update failed!')

    log.info('finished')
Пример #6
0
def compose_gbp_args(repo, tmp_dir, spec, args):
    """Compose command line arguments for gbp-pq-rpm"""
    upstream_tag = configmgr.get_arg_conf(args, 'upstream_tag')
    # transform variables from shell to python convention ${xxx} -> %(xxx)s
    upstream_tag = re.sub(r'\$\{([^}]+)\}', r'%(\1)s', upstream_tag)

    packaging_dir = get_packaging_dir(args)

    # Compose the list of command line arguments
    argv = [
        "argv[0] placeholder", "--color-scheme=magenta:green:yellow:red",
        "--vendor=Tizen",
        "--tmp-dir=%s" % tmp_dir,
        "--packaging-dir=%s" % packaging_dir,
        "--new-packaging-dir=%s" % packaging_dir,
        "--spec-file=%s" % spec,
        "--upstream-tag=%s" % upstream_tag,
        "--pq-branch=development/%(branch)s/%(upstreamversion)s",
        "--import-files=.gbs.conf", "--patch-export-compress=100k",
        "--patch-export-ignore-path=^(%s/.*|.gbs.conf)" % packaging_dir
    ]
    if args.debug:
        argv.append("--verbose")
    if args.retain_history:
        argv.append("--retain-history")

    return argv
Пример #7
0
def is_native_pkg(repo, args):
    """
    Determine if the package is "native"
    """
    forced = configmgr.get_optional_item('general', 'native')
    if forced is not None:
        return config_is_true(forced)

    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')
    return not repo.has_branch(upstream_branch)
Пример #8
0
def is_native_pkg(repo, args):
    """
    Determine if the package is "native"
    """
    forced = configmgr.get_optional_item('general', 'native')
    if forced is not None:
        return config_is_true(forced)

    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')
    return not repo.has_branch(upstream_branch)
Пример #9
0
def track_export_branches(repo, args):
    '''checking export related branches: pristine-tar, upstream.
    give warning if pristine-tar/upstream branch exist in remote
    but have not been checkout to local
    '''
    remote_branches = {}
    tracked_branches = []
    for branch in repo.get_remote_branches():
        remote_branches[branch.split('/', 1)[-1]] = branch
    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')

    # track upstream/pristine-tar branch
    for branch in [upstream_branch, 'pristine-tar']:
        if not repo.has_branch(branch) and branch in remote_branches:
            log.info('tracking branch: %s -> %s' % (remote_branches[branch],
                                                    branch))
            repo.create_branch(branch, remote_branches[branch])
            tracked_branches.append(branch)

    return tracked_branches
Пример #10
0
def export_sources(repo, commit, export_dir, spec, args, create_tarball=True):
    """
    Export packaging files using git-buildpackage
    """
    tmp = utils.Temp(prefix='gbp_', dirn=configmgr.get('tmpdir', 'general'),
                     directory=True)

    gbp_args = create_gbp_export_args(repo, commit, export_dir, tmp.path,
                                      spec, args, force_native=False,
                                      create_tarball=create_tarball)
    try:
        ret = gbp_build(gbp_args)
        if ret == 2 and not is_native_pkg(repo, args):
            errmsg = ("Generating upstream tarball and/or generating patches "
                      "failed. GBS tried this as you have upstream branch in "
                      "you git tree. Fix the problem by either:\n"
                      "  1. Update your upstream branch and/or fix the spec "
                      "file. Also, check the upstream tag format.\n"
                      "  2. Remove or rename the upstream branch (change the "
                      "package to native)\n"
                      "See https://source.tizen.org/documentation/reference/"
                      "git-build-system/upstream-package for more details.")
            fallback = configmgr.get_arg_conf(args, 'fallback_to_native')
            if config_is_true(fallback):
                # Try falling back to old logic of one monolithic tarball
                log.warn(errmsg)
                log.info("Falling back to native, i.e. creating source archive "
                         "directly from exported commit, without any patches.")
                gbp_args = create_gbp_export_args(repo, commit, export_dir,
                                                  tmp.path, spec, args,
                                                  force_native=True,
                                                  create_tarball=create_tarball)
                ret = gbp_build(gbp_args)
            else:
                log.error(errmsg)
        if ret:
            raise GbsError("Failed to export packaging files from git tree")
    except GitRepositoryError, excobj:
        raise GbsError("Repository error: %s" % excobj)
Пример #11
0
def export_sources(repo, commit, export_dir, spec, args, create_tarball=True):
    """
    Export packaging files using git-buildpackage
    """
    tmp = utils.Temp(prefix='gbp_', dirn=configmgr.get('tmpdir', 'general'),
                     directory=True)

    gbp_args = create_gbp_export_args(repo, commit, export_dir, tmp.path,
                                      spec, args, force_native=False,
                                      create_tarball=create_tarball)
    try:
        ret = gbp_build(gbp_args)
        if ret == 2 and not is_native_pkg(repo, args):
            errmsg = ("Generating upstream tarball and/or generating patches "
                      "failed. GBS tried this as you have upstream branch in "
                      "you git tree. Fix the problem by either:\n"
                      "  1. Update your upstream branch and/or fix the spec "
                      "file. Also, check the upstream tag format.\n"
                      "  2. Remove or rename the upstream branch (change the "
                      "package to native)\n"
                      "See https://source.tizen.org/documentation/reference/"
                      "git-build-system/upstream-package for more details.")
            fallback = configmgr.get_arg_conf(args, 'fallback_to_native')
            if config_is_true(fallback):
                # Try falling back to old logic of one monolithic tarball
                log.warn(errmsg)
                log.info("Falling back to native, i.e. creating source archive "
                         "directly from exported commit, without any patches.")
                gbp_args = create_gbp_export_args(repo, commit, export_dir,
                                                  tmp.path, spec, args,
                                                  force_native=True,
                                                  create_tarball=create_tarball)
                ret = gbp_build(gbp_args)
            else:
                log.error(errmsg)
        if ret:
            raise GbsError("Failed to export packaging files from git tree")
    except GitRepositoryError, excobj:
        raise GbsError("Repository error: %s" % excobj)
Пример #12
0
def create_gbp_export_args(repo, commit, export_dir, tmp_dir, spec, args,
                           create_tarball=True):
    """
    Construct the cmdline argument list for git-buildpackage export
    """
    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')
    upstream_tag = configmgr.get_arg_conf(args, 'upstream_tag')
    # transform variables from shell to python convention ${xxx} -> %(xxx)s
    upstream_tag = re.sub(r'\$\{([^}]+)\}', r'%(\1)s', upstream_tag)

    log.debug("Using upstream branch: %s" % upstream_branch)
    log.debug("Using upstream tag format: '%s'" % upstream_tag)

    # Get patch squashing option
    squash_patches_until = configmgr.get_arg_conf(args, 'squash_patches_until')

    # Determine the remote repourl
    reponame = ""
    remotes = repo.get_remote_repos()
    if remotes:
        remotename = 'origin' if 'origin' in remotes else remotes.keys()[0]
        # Take the remote repo of current branch, if available
        try:
            config_remote = repo.get_config('branch.%s.remote' % repo.branch)
        except KeyError:
            pass
        else:
            if config_remote in remotes:
                remotename = config_remote
            elif config_remote != '.':
                log.warning("You appear to have non-existent remote '%s' "
                            "configured for branch '%s'. Check your git config!"
                            % (config_remote, repo.branch))
        reponame = urlparse(remotes[remotename][0]).path.lstrip('/')

    packaging_dir = get_packaging_dir(args)
    # Now, start constructing the argument list
    export_rev = commit
    argv = ["argv[0] placeholder",
            "--git-color-scheme=magenta:green:yellow:red",
            "--git-ignore-new",
            "--git-compression-level=6",
            "--git-export-dir=%s" % export_dir,
            "--git-tmp-dir=%s" % tmp_dir,
            "--git-packaging-dir=%s" % packaging_dir,
            "--git-spec-file=%s" % spec,
            "--git-pq-branch=development/%(branch)s/%(upstreamversion)s",
            "--git-upstream-branch=%s" % upstream_branch,
            "--git-upstream-tag=%s" % upstream_tag,
            "--git-spec-vcs-tag=%s#%%(commit)s" % reponame]

    if create_tarball:
        argv.append("--git-force-create")
    else:
        argv.append("--git-no-create-orig")
    if args.debug:
        argv.append("--git-verbose")
    if is_native_pkg(repo, args) or args.no_patch_export:
        argv.extend(["--git-no-patch-export",
                     "--git-upstream-tree=%s" % commit])
    else:
        # Check if the revision seems to be of an orphan development branch
        is_orphan = False
        export_commitish = 'HEAD' if commit == 'WC.UNTRACKED' else commit
        try:
            repo.get_merge_base(export_commitish, upstream_branch)
        except GitRepositoryError:
            is_orphan = True
        # Development branch in orphan packaging model is identified in the conf
        orphan_packaging = configmgr.get('packaging_branch', 'orphan-devel')

        if not is_orphan:
            argv.extend(["--git-patch-export",
                         "--git-patch-export-compress=100k",
                         "--git-patch-export-squash-until=%s" %
                            squash_patches_until,
                         "--git-patch-export-ignore-path=^(%s/.*|.gbs.conf)" %
                            packaging_dir,
                        ])

            if orphan_packaging:
                export_rev = orphan_packaging
                argv.extend(["--git-patch-export-rev=%s" % commit])

        if repo.has_branch("pristine-tar"):
            argv.extend(["--git-pristine-tar"])

    argv.append("--git-export=%s" % export_rev)

    if 'source_rpm' in args and args.source_rpm:
        argv.extend(['--git-builder=rpmbuild',
                     '--git-rpmbuild-builddir=.',
                     '--git-rpmbuild-builddir=.',
                     '--git-rpmbuild-rpmdir=.',
                     '--git-rpmbuild-sourcedir=.',
                     '--git-rpmbuild-specdir=.',
                     '--git-rpmbuild-srpmdir=.',
                     '--git-rpmbuild-buildrootdir=.',
                     '--short-circuit', '-bs',
                     ])
    else:
        argv.extend(["--git-builder=osc", "--git-export-only"])

    return argv
Пример #13
0
def get_packaging_dir(args):
    """
    Determine the packaging dir to be used
    """
    path = configmgr.get_arg_conf(args, 'packaging_dir')
    return path.rstrip(os.sep)
Пример #14
0
def is_native_pkg(repo, args):
    """
    Determine if the package is "native"
    """
    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')
    return not repo.has_branch(upstream_branch)
Пример #15
0
def main(args):
    """gbs import entry point."""

    if args.author_name:
        os.environ["GIT_AUTHOR_NAME"] = args.author_name
    if args.author_email:
        os.environ["GIT_AUTHOR_EMAIL"] = args.author_email

    path = args.path

    tmp = Temp(prefix='gbp_',
               dirn=configmgr.get('tmpdir', 'general'),
               directory=True)

    upstream_branch = configmgr.get_arg_conf(args, 'upstream_branch')
    upstream_tag = configmgr.get_arg_conf(args, 'upstream_tag')
    # transform variables from shell to python convention ${xxx} -> %(xxx)s
    upstream_tag = re.sub(r'\$\{([^}]+)\}', r'%(\1)s', upstream_tag)

    params = ["argv[0] placeholder",
              "--color-scheme=magenta:green:yellow:red",
              "--packaging-dir=%s" % get_packaging_dir(args),
              "--upstream-branch=%s" % upstream_branch, path,
              "--upstream-tag=%s" % upstream_tag,
              "--tmp-dir=%s" % tmp.path,
              ]
    if args.debug:
        params.append("--verbose")
    if not args.no_pristine_tar and os.path.exists("/usr/bin/pristine-tar"):
        params.append("--pristine-tar")
    if args.filter:
        params += [('--filter=%s' % f) for f in args.filter]
    if args.upstream_vcs_tag:
        params.append('--upstream-vcs-tag=%s' % args.upstream_vcs_tag)

    if path.endswith('.src.rpm') or path.endswith('.spec'):
        params.append("--create-missing-branches")
        if args.allow_same_version:
            params.append("--allow-same-version")
        if args.native:
            params.append("--native")
        if args.orphan_packaging:
            params.append("--orphan-packaging")
        if args.no_patch_import:
            params.append("--no-patch-import")
        ret = gbp_import_srpm(params)
        if ret == 2:
            log.warning("Importing of patches into packaging branch failed! "
                        "Please import manually (apply and commit to git, "
                        "remove files from packaging dir and spec) in order "
                        "to enable automatic patch generation.")
        elif ret:
            raise GbsError("Failed to import %s" % path)
    else:
        if args.merge:
            params.append('--merge')
        else:
            params.append('--no-merge')
        if gbp_import_orig(params):
            raise GbsError('Failed to import %s' % path)

    log.info('done.')