def lilac_build(build_prefix=None, oldver=None, newver=None, accept_noupdate=False, depends=(), bindmounts=()): with lilacpy.load_lilac() as mod: run_cmd([ "sh", "-c", "rm -f -- *.pkg.tar.xz *.pkg.tar.xz.sig *.src.tar.gz" ]) success = False global build_output # reset in case no one cleans it up build_output = None try: if not hasattr(mod, '_G'): # fill nvchecker result unless already filled (e.g. by hand) mod._G = SimpleNamespace(oldver=oldver, newver=newver) if hasattr(mod, 'pre_build'): logger.debug('accept_noupdate=%r, oldver=%r, newver=%r', accept_noupdate, oldver, newver) mod.pre_build() recv_gpg_keys() need_build_first = set() build_prefix = build_prefix or mod.build_prefix depend_packages = [] for x in depends: p = x.resolve() if p is None: if not x.in_repo(): # ignore depends that are not in repo continue need_build_first.add(x.pkgname) else: depend_packages.append(p) if need_build_first: raise MissingDependencies(need_build_first) logger.info('depends: %s', depend_packages) makechrootpkg_args = [] if hasattr(mod, 'makechrootpkg_args'): makechrootpkg_args = mod.makechrootpkg_args call_build_cmd(build_prefix, depend_packages, bindmounts, makechrootpkg_args) pkgs = [x for x in os.listdir() if x.endswith('.pkg.tar.xz')] if not pkgs: raise Exception('no package built') if hasattr(mod, 'post_build'): mod.post_build() success = True finally: if hasattr(mod, 'post_build_always'): mod.post_build_always(success=success)
def lilac_build(mod: LilacMod, build_prefix: Optional[str] = None, oldver: Optional[str] = None, newver: Optional[str] = None, accept_noupdate: bool = False, depends: Iterable[Dependency] = (), bindmounts: Iterable[str] = (), ) -> None: run_cmd(["sh", "-c", "rm -f -- *.pkg.tar.xz *.pkg.tar.xz.sig *.src.tar.gz"]) success = False global build_output # reset in case no one cleans it up build_output = None try: if not hasattr(mod, '_G'): # fill nvchecker result unless already filled (e.g. by hand) mod._G = SimpleNamespace(oldver = oldver, newver = newver) pre_build = getattr(mod, 'pre_build', None) if pre_build is not None: logger.debug('accept_noupdate=%r, oldver=%r, newver=%r', accept_noupdate, oldver, newver) pre_build() recv_gpg_keys() need_build_first = set() build_prefix = build_prefix or getattr( mod, 'build_prefix', 'extra-x86_64') depend_packages = [] for x in depends: p = x.resolve() if p is None: if not x.managed(): # ignore depends that are not in repo continue need_build_first.add(x.pkgname) else: depend_packages.append(p) if need_build_first: raise MissingDependencies(need_build_first) logger.info('depends: %s, resolved: %s', depends, depend_packages) makechrootpkg_args: List[str] = [] if hasattr(mod, 'makechrootpkg_args'): makechrootpkg_args = mod.makechrootpkg_args call_build_cmd(build_prefix, depend_packages, bindmounts, makechrootpkg_args) pkgs = [x for x in os.listdir() if x.endswith('.pkg.tar.xz')] if not pkgs: raise Exception('no package built') post_build = getattr(mod, 'post_build', None) if post_build is not None: post_build() success = True finally: post_build_always = getattr(mod, 'post_build_always', None) if post_build_always is not None: post_build_always(success=success)
def git_add_files(files): if isinstance(files, str): files = [files] try: run_cmd(['git', 'add', '--'] + files) except CalledProcessError: # on error, there may be a partial add, e.g. some files are ignored run_cmd(['git', 'reset', '--'] + files) raise
def _update_aur_repo_real(pkgname): aurpath = os.path.join(AUR_REPO_DIR, pkgname) if not os.path.isdir(aurpath): logger.info('cloning AUR repo: %s', aurpath) with at_dir(AUR_REPO_DIR): run_cmd(['git', 'clone', '[email protected]:%s.git' % pkgname]) else: with at_dir(aurpath): git_reset_hard() git_pull() logger.info('copying files to AUR repo: %s', aurpath) files = run_cmd(['git', 'ls-files']).splitlines() for f in files: if f in SPECIAL_FILES: continue logger.debug('copying file %s', f) shutil.copy(f, aurpath) with at_dir(aurpath): with open('.SRCINFO', 'wb') as srcinfo: subprocess.run( ['makepkg', '--printsrcinfo'], stdout=srcinfo, check=True, ) run_cmd(['git', 'add', '.']) run_cmd(['git', 'commit', '-m', 'update by lilac']) run_cmd(['git', 'push'])
def git_commit(*, check_status=True): if check_status: ret = [ x for x in run_cmd(["git", "status", "-s", "."]).splitlines() if x.split(None, 1)[0] != '??' ] if not ret: return run_cmd([ 'git', 'commit', '-m', 'auto update for package %s' % (os.path.split(os.getcwd())[1]) ])
def update_pkgver_and_pkgrel(newver): pkgver, pkgrel = get_pkgver_and_pkgrel() for line in edit_file('PKGBUILD'): if line.startswith('pkgver=') and pkgver != newver: line = f'pkgver={newver}' elif line.startswith('pkgrel='): if pkgver != newver: line = 'pkgrel=1' else: line = f'pkgrel={int(pkgrel)+1}' print(line) run_cmd(["updpkgsums"])
def call_build_cmd(tag, depends, bindmounts=(), makechrootpkg_args=[]): global build_output if tag == 'makepkg': cmd = ['makepkg', '--holdver'] else: cmd = ['%s-build' % tag, '--'] if depends: for x in depends: cmd += ['-I', x] if bindmounts: for x in bindmounts: # Skipping non-existent source paths # See --bind in systemd-nspawn(1) for bindmount spec details # Note that this check does not consider all possible formats source_dir = x.split(':')[0] if not os.path.exists(source_dir): logger.warn('Invalid bindmount spec %s: source dir does not exist', x) continue cmd += ['-d', x] cmd.extend(makechrootpkg_args) cmd.extend(['--', '--holdver']) # NOTE that Ctrl-C here may not succeed try: build_output = run_cmd(cmd, use_pty=True) except CalledProcessError: build_output = None raise
def aur_post_build(): git_rm_files(_g.aur_pre_files) git_add_files(_g.aur_building_files, force=True) output = run_cmd(["git", "status", "-s", "."]).strip() if output: git_commit() del _g.aur_pre_files, _g.aur_building_files
def aur_post_build(): git_rm_files(_g.aur_pre_files) git_add_files(_g.aur_building_files) output = run_cmd(["git", "status", "-s", "."]).strip() if output: git_commit() del _g.aur_pre_files, _g.aur_building_files
def call_build_cmd(tag, depends, bindmounts=(), makechrootpkg_args=[]): global build_output if tag == 'makepkg': cmd = ['makepkg', '--holdver'] else: cmd = ['%s-build' % tag, '--'] if depends: for x in depends: cmd += ['-I', x] if bindmounts: for x in bindmounts: # Skipping non-existent source paths # See --bind in systemd-nspawn(1) for bindmount spec details # Note that this check does not consider all possible formats source_dir = x.split(':')[0] if not os.path.exists(source_dir): logger.warn( 'Invalid bindmount spec %s: source dir does not exist', x) continue cmd += ['-d', x] cmd.extend(makechrootpkg_args) cmd.extend(['--', '--holdver']) # NOTE that Ctrl-C here may not succeed try: build_output = run_cmd(cmd, use_pty=True) except CalledProcessError: build_output = None raise
def clean_directory(): '''clean all PKGBUILD and related files''' files = run_cmd(['git', 'ls-files']).splitlines() logger.info('clean directory') ret = [] for f in files: if f in SPECIAL_FILES: continue try: logger.debug('unlink file %s', f) os.unlink(f) ret.append(f) except FileNotFoundError: pass return ret
def call_build_cmd(tag, depends, bindmounts=(), makechrootpkg_args=[]): global build_output if tag == 'makepkg': cmd = ['makepkg', '--holdver'] else: cmd = ['%s-build' % tag, '--'] if depends: for x in depends: cmd += ['-I', x] if bindmounts: for x in bindmounts: cmd += ['-d', x] cmd.extend(makechrootpkg_args) cmd.extend(['--', '--holdver']) # NOTE that Ctrl-C here may not succeed try: build_output = run_cmd(cmd, use_pty=True) except CalledProcessError as e: build_output = e.output raise
def pkgrel_changed(revisions, pkgname): cmd = ["git", "diff", "-p", revisions, '--', pkgname + '/PKGBUILD'] r = run_cmd(cmd, silent=True).splitlines() return any(x.startswith('+pkgrel=') for x in r)
def git_rm_files(files): if files: run_cmd(['git', 'rm', '--cached', '--'] + files)
def recv_gpg_keys(): run_cmd(['recv_gpg_keys'])
def pypi_pre_build( depends=None, python2=False, pypi_name=None, arch=None, makedepends=None, depends_setuptools=True, provides=None, optdepends=None, license=None, ): if os.path.exists('PKGBUILD'): pkgver, pkgrel = get_pkgver_and_pkgrel() else: pkgver = None pkgname = os.path.basename(os.getcwd()) if pypi_name is None: pypi_name = pkgname.split('-', 1)[-1] pkgbuild = run_cmd(['pypi2pkgbuild', pypi_name], silent=True) if depends_setuptools: if depends is None: depends = ['python-setuptools'] else: depends.append('python-setuptools') elif makedepends is None: makedepends = ['python-setuptools'] elif makedepends: makedepends.append('python-setuptools') pkgbuild = re.sub(r'^pkgname=.*', f'pkgname={pkgname}', pkgbuild, flags=re.MULTILINE) if license: pkgbuild = re.sub(r'^license=.*', f'license=({license})', pkgbuild, flags=re.MULTILINE) if depends: pkgbuild = pkgbuild.replace( "depends=('python')", "depends=('python' %s)" % ' '.join(f"'{x}'" for x in depends)) if makedepends: pkgbuild = pkgbuild.replace( '\nsource=', '\nmakedepends=(%s)\nsource=' % ' '.join("'%s'" % x for x in makedepends)) if optdepends: pkgbuild = pkgbuild.replace( '\nsource=', '\noptdepends=(%s)\nsource=' % ' '.join("'%s'" % x for x in optdepends)) if provides: pkgbuild = pkgbuild.replace( '\nsource=', '\nprovides=(%s)\nsource=' % ' '.join("'%s'" % x for x in provides)) if python2: pkgbuild = re.sub(r'\bpython3?(?!\.)', 'python2', pkgbuild) if arch is not None: pkgbuild = pkgbuild.replace( "arch=('any')", "arch=(%s)" % ' '.join("'%s'" % x for x in arch)) with open('PKGBUILD', 'w') as f: f.write(pkgbuild) new_pkgver = get_pkgver_and_pkgrel()[0] if pkgver and pkgver == new_pkgver: # change pkgrel to what specified in PKGBUILD update_pkgrel(pkgrel)
def git_last_commit(ref=None): cmd = ['git', 'log', '-1', '--format=%H'] if ref: cmd.append(ref) return run_cmd(cmd).strip()
def git_reset_hard(): run_cmd(['git', 'reset', '--hard'])
def lilac_build( mod: LilacMod, build_prefix: Optional[str] = None, oldver: Optional[str] = None, newver: Optional[str] = None, accept_noupdate: bool = False, depends: Iterable[Dependency] = (), bindmounts: Iterable[str] = (), ) -> None: run_cmd( ["sh", "-c", "rm -f -- *.pkg.tar.xz *.pkg.tar.xz.sig *.src.tar.gz"]) success = False global build_output # reset in case no one cleans it up build_output = None try: if not hasattr(mod, '_G'): # fill nvchecker result unless already filled (e.g. by hand) mod._G = SimpleNamespace(oldver=oldver, newver=newver) pre_build = getattr(mod, 'pre_build', None) if pre_build is not None: logger.debug('accept_noupdate=%r, oldver=%r, newver=%r', accept_noupdate, oldver, newver) pre_build() pkgbuild.check_srcinfo() recv_gpg_keys() need_build_first = set() build_prefix = build_prefix or getattr(mod, 'build_prefix', 'extra-x86_64') depend_packages = [] for x in depends: p = x.resolve() if p is None: if not x.managed(): # ignore depends that are not in repo continue need_build_first.add(x.pkgname) else: depend_packages.append(p) if need_build_first: raise MissingDependencies(need_build_first) logger.info('depends: %s, resolved: %s', depends, depend_packages) makechrootpkg_args: List[str] = [] if hasattr(mod, 'makechrootpkg_args'): makechrootpkg_args = mod.makechrootpkg_args call_build_cmd(build_prefix, depend_packages, bindmounts, makechrootpkg_args) pkgs = [x for x in os.listdir() if x.endswith('.pkg.tar.xz')] if not pkgs: raise Exception('no package built') post_build = getattr(mod, 'post_build', None) if post_build is not None: post_build() success = True finally: post_build_always = getattr(mod, 'post_build_always', None) if post_build_always is not None: post_build_always(success=success)