Refactor compat32, revise filesystem layout #1
Open
zeroability opened 3 weeks ago

WIP - do not merge without approval

Able to merge without conflicts
Pull request cannot be merged now as it is pending review
  • Refactor compat32, revise filesystem layout
    Drop condition checks for compat32 support
    
    Temporarily fix paths and drop legacy paths
    3 weeks ago
  • zeroability commented 3 weeks ago

    Local "build" test successful

  • Davide Beatrici commented 2 weeks ago

    This is what I came up with:

    macros.platform

    %_native_arch           x86_64
    %_native_os             linux
    %_native_libc           glibc
    
    %_native_platform       %{_native_arch}-%{_native_os}-%{_native_libc}
    %_native_prefix         /usr/%{_native_arch}/%{_native_os}/%{_native_libc}
    

    platforms.list

    x86_64-linux-glibc
    aarch64-linux-glibc
    x86_64-linux-musl
    riscv64-linux-glibc
    x86_64-win-mingw
    

    filesystem.spec

    Name:           filesystem
    Version:        1.0
    Release:        1%{?dist}
    Summary:        Base filesystem layout and native symlinks
    License:        MIT
    BuildArch:      noarch
    
    Source0:        macros.platform
    Source1:        platforms.list
    
    Requires:       filesystem-%{_native_platform}
    
    %description
    Base directories and short-path symlinks that always point to the
    native platform. Foreign platform trees are available as separate
    subpackages generated from platforms.list.
    
    %prep
    %setup -q -c -T
    cp -p %{SOURCE0} %{SOURCE1} .
    
    # --------------------------------------------------
    # Automatically generate subpackage definitions
    # from platforms.list
    # --------------------------------------------------
    cat > subpackages.inc << 'EOF'
    # Generated file – do not edit
    EOF
    
    while read -r platform; do
        # Skip empty lines and comments
        [[ -z "$platform" || "$platform" =~ ^[[:space:]]*# ]] && continue
    
        cat >> subpackages.inc << EOF
    
    %package -n filesystem-${platform}
    Summary: Filesystem tree for ${platform}
    BuildArch: noarch
    
    %description -n filesystem-${platform}
    Directory hierarchy for the ${platform} target.
    Safe to install on any host for cross-compilation or emulation.
    Does not modify short paths (/bin, /usr/lib, …).
    
    %files -n filesystem-${platform}
    %dir /usr/${platform}
    %dir /usr/${platform}/bin
    %dir /usr/${platform}/sbin
    %dir /usr/${platform}/lib
    %dir /usr/${platform}/libexec
    %dir /usr/${platform}/include
    %dir /usr/${platform}/share
    EOF
    done < platforms.list
    
    %install
    install -D -m 644 macros.platform \
        %{buildroot}%{_rpmconfigdir}/macros.d/macros.platform
    
    # ABI-independent base directories
    mkdir -p %{buildroot}/{etc,var,boot,home,mnt,opt,root,run,srv,tmp}
    mkdir -p %{buildroot}/usr/{share,src,local,include}
    mkdir -p %{buildroot}/var/{cache,log,lib,spool,tmp}
    
    # Create every platform tree
    while read -r platform; do
        [[ -z "$platform" || "$platform" =~ ^[[:space:]]*# ]] && continue
        mkdir -p %{buildroot}/usr/${platform}/{bin,sbin,lib,libexec,include,share}
    done < platforms.list
    
    %post
    # Short paths always point to the native platform
    ln -sfn %{_native_prefix}/bin      /bin
    ln -sfn %{_native_prefix}/lib      /lib
    ln -sfn %{_native_prefix}/sbin     /sbin
    
    ln -sfn %{_native_prefix}/bin      /usr/bin
    ln -sfn %{_native_prefix}/lib      /usr/lib
    ln -sfn %{_native_prefix}/sbin     /usr/sbin
    
    ln -sfn %{_native_prefix}          /usr/native
    mkdir -p /usr/include
    
    %files
    %{_rpmconfigdir}/macros.d/macros.platform
    
    %dir /usr/include
    %dir /usr/share
    %dir /usr/src
    %dir /usr/local
    
    %dir /etc
    %dir /var
    %dir /boot
    %dir /home
    %dir /mnt
    %dir /opt
    %dir /root
    %dir /run
    %dir /srv
    %dir /tmp
    
    # Pull in all the generated subpackages
    %include subpackages.inc
    
  • zeroability commented 2 weeks ago

    Wouldn't it make sense to just build all the platform packages in one shot? Technically, the package "build" is noarch because it doesn't compile anything.

  • Davide Beatrici commented 2 weeks ago

    Yes, absolutely. The only package that shouldn't be noarch is the one that selects the native platform package automatically.

  • zeroability commented 2 weeks ago

    Yes, absolutely. The only package that shouldn't be noarch is the one that selects the native platform package automatically.

    It was meant as a general statement as there are no libraries or executables being built. I think the package should therefore create all the arch based packages on the first build pass and not do any autodetection. If the spec is doing that, it's not needed.

  • Davide Beatrici commented 2 weeks ago

    The spec file as written should indeed do that, but honestly I didn't test it yet. If you did and it doesn't result in all packages being built, that's unintended behavior.

  • zeroability commented 2 weeks ago

    I guess, I am confused what macros.platform does. It supplies %{_native_prefix} later on, but that shouldn't really need to happen. First, it's hard defined from what I can tell, and second it should be building all the platform packages so knowing the native prefix isn't really relevant. There just needs to be a substitution based on the platform for the package, which already seems to be taken care of. What am I missing?

  • Davide Beatrici commented 2 weeks ago

    macros.platform is just a concept and it allows to test the spec file, I should've clarified that. In the final form we'll have one macros file per platform, with substitution in place.

  • zeroability commented 2 weeks ago

    We probably shouldn't include it as a source, then. It should be sufficient to add the test logic to %check if you are trying to apply a test that should error out a build.

  • Davide Beatrici commented 2 weeks ago

    We'll probably have it as a template that is then used as the base for the actual macros file(s).

  • zeroability commented 2 weeks ago

    Why not just iterate over the platforms.list file and create a macro from the results, then?

1/1
Submitter zeroability
Target master
Source refac-drop-compat32
Merge Strategy
Rebase Source Branch Commits
Auto Merge OFF
Enable this option to merge the pull request automatically when ready (all reviewers approved, all required jobs passed etc.)
Watchers (4)
Reference
pr UnnamedNewDistro/Packages/filesystem#1
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover