Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(*): deprecate presumptive _archive #6702

Merged
merged 1 commit into from
Dec 29, 2024

Conversation

oklopfer
Copy link
Member

@oklopfer oklopfer commented Nov 24, 2024

Requires pacstall/pacstall#1271

if a script has ${_archive} and _archive= is not defined:

  • if it is a tar archive or zip:
    • replace all instances with ${pkgname~${pkgver}
    • prefix all source[0] entries (as well as source_*[0]) with
      • @${pkgname~${pkgver}:: or
      • dest@${pkgname~${pkgver}:: if there was a dest prefix before
  • otherwise:
    • replace all instances with ${srcdir}

Not directly caused by this, but will be more prevalent after:
the website API should strip out anything before :: for final source entries, so that repology will be more likely to accept us again.

This should not be altered here, as for the default behavior, we want full source entries to be given, so that entries may be parsable to pacstall in the form they would be used to build. Given this, I am also leaning away from making the change in go-srcinfo, and towards only altering it in the final stretch on the website's end.

(EDIT: site fix done here pacstall/website#1097)

script to convert:
#!/usr/bin/env python3

import glob
import re
import os

def process_pacscript(pacscript_path):
    with open(pacscript_path, 'r') as f:
        content = f.read()
    if '${_archive}' not in content or '_archive=' in content:
        return
    source_pattern = re.compile(r'^(source(?:_[a-zA-Z0-9_]+)?=\(\s*)(.*?)(\s*\))$', re.DOTALL | re.MULTILINE)

    def modify_source_block(match):
        opening = match.group(1)
        sources_text = match.group(2)
        closing = match.group(3)
        lines = sources_text.splitlines()
        new_lines = []
        first_entry_modified = False
        for line in lines:
            stripped_line = line.strip()
            if not stripped_line or stripped_line.startswith('#'):
                new_lines.append(line)
                continue
            if not first_entry_modified:
                match_line = re.match(r'^(\s*)(["\']?)(.*?)(["\']?)(,?\s*)$', line)
                if match_line:
                    indent, quote_start, content_line, quote_end, comma = match_line.groups()
                    if '::' in content_line:
                        prefix, suffix = content_line.split('::', 1)
                        new_content = f'{prefix}@${{pkgname}}~${{pkgver}}::{suffix}'
                    else:
                        new_content = f'@${{pkgname}}~${{pkgver}}::{content_line}'

                    new_line = f'{indent}{quote_start}{new_content}{quote_end}{comma}'
                    new_lines.append(new_line)
                    first_entry_modified = True
                else:
                    new_lines.append(line)
                    first_entry_modified = True
            else:
                new_lines.append(line)
        reconstructed_block = f'{opening}' + '\n'.join(new_lines) + f'{closing}'
        return reconstructed_block

    if re.search(r'\.tar|\.zip|\.tgz', content):
        content = content.replace('${_archive}', '${pkgname}~${pkgver}')
        content_new = source_pattern.sub(modify_source_block, content)
    else:
        content_new = content.replace('${_archive}', '${srcdir}')
    if content_new != content:
        with open(pacscript_path, 'w') as f:
            f.write(content_new)
        print(f"Processed {pacscript_path}")
    else:
        print(f"No changes made to {pacscript_path}")

def main():
    pacscript_files = glob.glob('packages/*/*.pacscript')
    for pacscript in pacscript_files:
        process_pacscript(pacscript)

if __name__ == '__main__':
    main()

@oklopfer oklopfer requested review from Elsie19 and vigress8 November 24, 2024 22:41
@oklopfer oklopfer self-assigned this Nov 24, 2024
@github-actions github-actions bot removed the refactor Refactors code label Nov 24, 2024
@oklopfer oklopfer force-pushed the archive_is_kill branch 4 times, most recently from fa86ad0 to 8b5f90c Compare November 28, 2024 02:44
@oklopfer oklopfer force-pushed the archive_is_kill branch 2 times, most recently from e805e0d to d85a5f1 Compare December 23, 2024 00:42
@oklopfer oklopfer marked this pull request as ready for review December 29, 2024 02:30
@oklopfer oklopfer merged commit dab28c1 into pacstall:master Dec 29, 2024
1 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant