Question about `platforms` and `${os.platform}`

Jason Liu jasonliu at umich.edu
Sun Dec 12 00:54:18 UTC 2021


On Sat, Dec 11, 2021 at 6:41 PM Chris Jones <jonesc at hep.phy.cam.ac.uk>
wrote:

> No, because that would render the port non functional on non darwin OSes.
> You should only specify the darwin platform when it is actually required,
> e.g. when then making a os.major conditional that inly makes sense in
> darwin platforms.
>

Wait a minute, didn't Ryan say that "We don't really expect many ports to
be installable on other operating systems or for maintainers to test
anything on other operating systems"? So we *should* worry about the port
being non-functional on non-Darwin OSes? I'm confused now....

That's why I originally thought that `platforms darwin` implied that the
portfile was only intended to be valid on Darwin. Now that I've learned
that `platforms darwin` doesn't actually do anything, I'm just... confused.

-- 
Jason Liu


On Sat, Dec 11, 2021 at 6:41 PM Chris Jones <jonesc at hep.phy.cam.ac.uk>
wrote:

>
>
> On 11 Dec 2021, at 10:42 pm, Jason Liu <jasonliu at umich.edu> wrote:
>
> 
> On Sat, Dec 11, 2021 at 5:20 PM Ryan Schmidt <ryandesign at macports.org>
> wrote:
>
>>
>>
>> On Dec 10, 2021, at 15:07, Jason Liu wrote:
>>
>>>
>>> A conversation in one of my PRs has brought up an interesting question
>>> that I've been wondering about for a long time. In Portfiles, whenever I've
>>> had a test for `${os.major} <= xx`, I've typically always added an
>>> additional check for darwin in the front, i.e.:
>>>
>>> if {${os.platform} eq "darwin" && ${os.major} <= xx} {
>>>
>>> I've done it that way because I basically copied what I saw from other
>>> Portfiles, and because I get gently admonished by the committers when I
>>> forget to.
>>
>>
>> Yes, please always do that.
>
>
> Then would it be easier (or even kosher) to simply wrap the majority of
> the Portfile inside of a single
>
> if {${os.platform} eq "darwin"} {
>
> and be done with it, instead of needing to add one each and every time I
> have a conditional involving `${os.major}`?
>
>
> No, because that would render the port non functional on non darwin OSes.
> You should only specify the darwin platform when it is actually required,
> e.g. when then making a os.major conditional that inly makes sense in
> darwin platforms.
>
> So basically, following the recommendations as currently given.
>
> Chris
>
>
> I was under the impression that the `platforms darwin` line means that the
>>> entire Portfile is supposed to be valid only for `${os.platform} eq
>>> "darwin"`, no? (In other words, my understanding is that a line such as
>>> `platforms darwin freebsd openbsd` is meant to signify that "this Portfile
>>> is supposed to be valid for the listed platforms".) If that's not the case,
>>> then what is the purpose of `platforms darwin`?
>>
>>
>> The platforms line is not used by MacPorts in any way at this time, other
>> than to display it in the output of "port info". There is a ticket about
>> possibly using it in the future as a way to indicate which OS versions the
>> port is compatible with, but I don't think that got beyond the idea phase.
>>
>
> That seems like a pity, and a bit of a waste, considering that platforms
> is being included in each and every Portfile.
>
> --
> Jason Liu
>
>
> On Sat, Dec 11, 2021 at 5:20 PM Ryan Schmidt <ryandesign at macports.org>
> wrote:
>
>>
>>
>> On Dec 10, 2021, at 15:07, Jason Liu wrote:
>>
>> > A conversation in one of my PRs has brought up an interesting question
>> that I've been wondering about for a long time. In Portfiles, whenever I've
>> had a test for `${os.major} <= xx`, I've typically always added an
>> additional check for darwin in the front, i.e.:
>> >
>> > if {${os.platform} eq "darwin" && ${os.major} <= xx} {
>> >
>> > I've done it that way because I basically copied what I saw from other
>> Portfiles, and because I get gently admonished by the committers when I
>> forget to.
>>
>> Yes, please always do that.
>>
>>
>> > But I've also always wondered why it's necessary.
>>
>> Your Portfile could be parsed or accessed by non-Darwin operating
>> systems. For example, before we took over server hosting duties in 2016,
>> all of the server VMs including the one that generated the PortIndex files
>> (except the actual macOS build machines) were running Linux; perhaps some
>> day we will once again want to try using a server OS other than macOS for
>> this task. There are even some users using Linux to test various things in
>> MacPorts. We don't really expect many ports to be installable on other
>> operating systems or for maintainers to test anything on other operating
>> systems, but just take 2 seconds when you're writing an OS version
>> conditional to think about what you're trying to express, and then express
>> it, including checking os.platform. Typical forms include the one you
>> mentioned:
>>
>> if {${os.platform} eq "darwin" && ${os.major} <= xx}
>>
>> (<, <=, ==, >=, >)
>>
>> And the other one:
>>
>> if {${os.platform} ne "darwin" || ${os.major} <= xx}
>>
>> (<, <=, ==, >=, >)
>>
>> Usually the decision about which to use comes down to whether the thing
>> you're doing is Mac-specific or not. For example, if you were writing a
>> conditional to use the Security framework on recent macOS and openssl on
>> older macOS, what should happen if perchance the port is used on non-macOS?
>> In this case, the answer is that frameworks are a Mac thing, so you would
>> want to use openssl for non-macOS.
>>
>>
>> > I was under the impression that the `platforms darwin` line means that
>> the entire Portfile is supposed to be valid only for `${os.platform} eq
>> "darwin"`, no? (In other words, my understanding is that a line such as
>> `platforms darwin freebsd openbsd` is meant to signify that "this Portfile
>> is supposed to be valid for the listed platforms".) If that's not the case,
>> then what is the purpose of `platforms darwin`?
>>
>> The platforms line is not used by MacPorts in any way at this time, other
>> than to display it in the output of "port info". There is a ticket about
>> possibly using it in the future as a way to indicate which OS versions the
>> port is compatible with, but I don't think that got beyond the idea phase.
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macports.org/pipermail/macports-dev/attachments/20211211/3c4c8de6/attachment.htm>


More information about the macports-dev mailing list