<div dir="ltr"><div dir="ltr"><div><div dir="ltr" class="gmail_attr">On Sat, Dec 11, 2021 at 5:20 PM Ryan Schmidt <<a href="mailto:ryandesign@macports.org" target="_blank">ryandesign@macports.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br><br>On Dec 10, 2021, at 15:07, Jason Liu wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>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.:<br><span><br></span>if {${os.platform} eq "darwin" && ${os.major} <= xx} {<br><span><br></span>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.</blockquote><br>Yes, please always do that.</blockquote></div><div><br></div>Then would it be easier (or even kosher) to simply wrap the majority of the Portfile inside of a single<div><br></div><div><font face="monospace">if {${os.platform} eq "darwin"} {</font></div><div><br></div><div>and be done with it, instead of needing to add one each and every time I have a conditional involving `<font face="monospace">${os.major}</font>`?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">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`?</blockquote><br>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.<br></blockquote><div><br></div><div>That seems like a pity, and a bit of a waste, considering that <font face="monospace">platforms</font> is being included in each and every Portfile.</div><div><br clear="all"><div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><div>-- </div><div>Jason Liu</div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Dec 11, 2021 at 5:20 PM Ryan Schmidt <<a href="mailto:ryandesign@macports.org" target="_blank">ryandesign@macports.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
<br>
On Dec 10, 2021, at 15:07, Jason Liu wrote:<br>
<br>
> 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.:<br>
> <br>
> if {${os.platform} eq "darwin" && ${os.major} <= xx} {<br>
> <br>
> 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.<br>
<br>
Yes, please always do that.<br>
<br>
<br>
> But I've also always wondered why it's necessary.<br>
<br>
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:<br>
<br>
if {${os.platform} eq "darwin" && ${os.major} <= xx}<br>
<br>
(<, <=, ==, >=, >)<br>
<br>
And the other one:<br>
<br>
if {${os.platform} ne "darwin" || ${os.major} <= xx}<br>
<br>
(<, <=, ==, >=, >)<br>
<br>
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.<br>
<br>
<br>
> 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`?<br>
<br>
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.<br>
<br>
<br>
</blockquote></div></div>