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

No way to distinguish between macOS and other Unix with attributes #1682

Open
benjamineskola opened this issue Oct 2, 2023 · 7 comments
Open

Comments

@benjamineskola
Copy link

benjamineskola commented Oct 2, 2023

Currently it seems like it's not possible to define a recipe for everything but macOS. For example, I can write a recipe that runs only on macOS:

[macos]
blah:
    echo blah

But it appears that there's no way to write the inverse, a recipe that does not run on macOS, because linux is false on BSDs (correctly so), but unix is true on macOS (also correctly).

(A bsd attribute wouldn't really help, since arguably that should also be true on Darwin anyway.)

Perhaps being able to negate an attribute:

[macos]
blah:
  echo this is macOS

[no-macos]
blah:
  echo this is {{os()}}

Alternatively, or additionally, maybe there should be attributes for every possible value of os()? But I don't know if that function even has a complete list.

Edit:

It's possible to work around this by invoking a new instance of just:

default:
   just only-{{ os() }}

only-macos:
  echo do something macOS-specific

only-openbsd:
  echo do something bsd-specific

But this way can't take advantage of the attribute system, and I suspect there are other downsides as well to a child process (e.g., dependencies may behave differently).

@runeimp
Copy link

runeimp commented Oct 3, 2023

What is the use case that should work on all UNIX variants except Linux and macOS in a recipe?

@benjamineskola
Copy link
Author

What is the use case that should work on all UNIX variants except Linux and macOS in a recipe?

I don't have such a use case. I don't care about excluding Linux; I care about excluding macOS.

Currently, there's no way to write a recipe for "all Unixes except macOS". I can write a macOS recipe, and a Linux recipe; but there's no way to write one for Free/Net/OpenBSD (or, I presume, Solaris or any other platforms — I have no idea how many are theoretically supported).

So if I have platform-specific tasks, where things are done one way on macOS and a different way on other Unixes, I can't use the attribute system to implement that. What I think should work is something like:

default: platform

[macos]
platform:
    # macOS specific here

[not-macos]
platform:
    # other-platform-specific here

Or:

[linux,freebsd,openbsd]
platform:
    # listing all the platforms would also be fine

@runeimp
Copy link

runeimp commented Oct 3, 2023

I'm not the developer but I believe it would very likely help to have a use case to justify the dev time and ensure there is an overall benefit to the community. I like the idea of having the more granular options (dragonfly, freebsd, netbsd, solaris, etc.) but I can't think of a reason where it would be specifically beneficial. I just happen to like the idea of it. All Unixes follow the POSIX standard pretty close so a programatic reason to treat any of them differently would be enlightening.

@benjamineskola
Copy link
Author

I'm not suggesting treating them differently. I'm suggesting making it possible to indicate them in a way that makes use of the existing feature.

The issue is that there's an asymmetry in the current OS attributes. There's unix and windows, which obviously do not overlap. Then there's linux and macos, which are both treated as subsets of unix. But then there are some OSes which are unix but not linux and not macos. What this means is that if you want to use linux or macos attributes and another unix that doesn't have a more specific attribute, there's no way to make this distinction.

I'd happily try writing a pull request for this myself, but I'd like to make sure that the developer is interested in such a change before doing so.

@casey
Copy link
Owner

casey commented Oct 9, 2023

Sorry for letting this sit! This seems like a totally reasonable feature. I'm not sure if we should implement this in a more general way, e.g., allowing inverting attributes. Or, if we should implement it in a narrow way, e.g., an attribute which is true on non-macos unixes.

@runeimp
Copy link

runeimp commented Oct 9, 2023

I prefer the narrow way but I don't see how you can do that with any rationality. If I remember correctly, Darwin is a fork of FreeBSD UNIX. It seems to have over 80% of the BSD UNIX spec if not the entire POSIX spec. A bsdunix and unix should both legitimately include macos. I can think of no rational to separate it out from those two categories. Now if we name each exact distribution, that could work. But then if I (for some unlikely reason) want to include all the UNIXes except macOS as the one exclusion the list is going to be pretty long.

The one rational in my mind for separating macOS from the other UNI is that it doesn't come with X Window installed by default. As do "server" versions of many distributions. So, have an x-window tag that checks if X Window is installed on the current OS makes way more sense to me than arbitrarily trying to exclude macos. But if you're going to do it no-macos is the only rational way to handle that situation in my opinion. Listing out 10+ other UNIX distros just to include all UNI except macos just doesn't make any sense to me.

@benjamineskola
Copy link
Author

If I remember correctly, Darwin is a fork of FreeBSD UNIX. It seems to have over 80% of the BSD UNIX spec if not the entire POSIX spec.

Yes, as I mentioned in my initial post. It's difficult to find a meaningful name for the grouping of unix && !macos (or unix && !macos && !linux).

I could see an argument for simply having an attribute tag for every supported platform, but this could easily become impractical since I think the Attribute enum would need to contain a complete list of those, as well as having the correct logic in the enabled method.

And actually, I think that in order to implement this, enabled would either need to check for target_os = freebsd || netbsd || openbsd || dragonfly, or otherwise it would boil down to being unix && !macos after all. The latter probably scales better, but that still leaves the question of the name.

The one rational in my mind for separating macOS from the other UNI

The rationale is that its behaviour and configuration is significantly different from other Unixes. Although it is, strictly speaking, a descendent of BSD Unix, the others are all far more similar to each other in a lot of ways than macOS is.

So, have an x-window tag that checks if X Window is installed on the current OS makes way more sense to me than arbitrarily trying to exclude macOS.

I don't think this could make sense. Many Unix machines do not include X11, because X11 is not usually installed on servers either. (And Wayland might mean that an increasing number of desktops/laptops do not have X11 installed either.) It certainly wouldn't have solved my original specific usecase, though it might be something that other people would find useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants