Opened 2 years ago

Closed 8 months ago

#64863 closed defect (fixed)

base: (linux) invalid `os_arch` on debian-based distros

Reported by: harens (Haren S) Owned by:
Priority: Normal Milestone:
Component: base Version:
Keywords: Cc: mascguy (Christopher Nielsen)
Port:

Description

I'm currently running MacPorts on Raspberry Pi OS with an armv7l processor. os_arch is set to "armv7l" rather than the standard "arm" which causes breakages for ports that have a platform arm block.

I think this is due to this code snippet from macports.tcl:

# set up platform info variables
set os_arch $tcl_platform(machine)
# Set os_arch to match `uname -p`
if {$os_arch eq "Power Macintosh"} {
    set os_arch "powerpc"
} elseif {$os_arch eq "i586" || $os_arch eq "i686" || $os_arch eq "x86_64"} {
    set os_arch "i386"
} elseif {$os_arch eq "arm64"} {
    set os_arch "arm"
}

The issue is thatuname -pisn't defined on all linux distributions. Most notably, it's not defined on debian-based distros (excluding ubuntu and its derivatives). See here for an explanation why.

As a result, the output of uname -p is unknown, which doesn't match with any of the if statements. Somehow though, MacPorts sets os_arch to armv7l, which is the output of uname -m.

The easiest fix might be to check uname -m if uname -p is unknown e.g. set os_arch to arm if uname -m begins with arm.

Change History (6)

comment:1 Changed 2 years ago by ryandesign (Ryan Carsten Schmidt)

MacPorts doesn't use uname directly. As you see it uses $tcl_platform(machine) which according to the documentation is the output of uname -m. But we want the equivalent of uname -p for which I guess Tcl doesn't offer us a variable so we turn certain known values from uname -m into their corresponding uname -p-like values. As you see we have not programmed MacPorts base to know how to transform "armv7l" into "arm" here but it could easily be extended to do so. Might be a good time to change all those if statements into a switch:

switch $os_arch {
    arm64 -
    armv7l {
        set os_arch "arm"
    }
    i586 -
    i686 -
    x86_64 {
        set os_arch "i386"
    }
    "Power Macintosh" {
        set os_arch "powerpc"
    }
}}

comment:2 Changed 2 years ago by harens (Haren S)

Ah okay, thank you for explaining. That makes a lot of sense. The issue isn't to do with uname -p, it's just that the architecture hasn't been set in MacPorts base.

Also, I really like that switch statement. I found a list of some possible uname -m values, and thought I'd try to future proof the code a bit. Thoughts?

switch -regexp -- $os_arch {
    {^(Power Macintosh|ppc)} {
        set os_arch "powerpc"
    }
    {^(i[3-7]86|x86_64)} {
        set os_arch "i386"
    }
    {^(arm|aarch)} {
        set os_arch "arm"
    }
}

For instance, it fixes the current problem by mapping anything that begins with arm or aarch to arm.

Last edited 2 years ago by harens (Haren S) (previous) (diff)

comment:3 Changed 2 years ago by ryandesign (Ryan Carsten Schmidt)

Seems plausible!

comment:5 Changed 19 months ago by mascguy (Christopher Nielsen)

Cc: mascguy added

comment:6 Changed 8 months ago by jmroot (Joshua Root)

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.