Writing a "pure Swift" replacement for Make?

I'm interested in writing a sort of replacement for Make (using a different Makefile syntax). From some cursory research it looks like Foundation.Process is going to be important for this, along with probably swift-argument-parser. However, I'd like to avoid using Foundation if possible. Is there any other way to run bash/zsh/etc commands from a Swift executable package?

2 Likes

You can use C's system, POSIX's popen, or POSIX's exec family of functions.

2 Likes

Looking at the swift-corelibs-foundation implementation for Linux, it appears that Foundation.Process uses posix_spawn internally.

1 Like

If your project is open source, perhaps you could lift Process wholesale from Foundation?

Please don't use system(). It runs he command in a shell, which is an unnecessary extra process and you don't have as much control over the environment as you might wish for.

1 Like

Please don't use system.

It’s also a security vulnerability looking for a place to happen.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

4 Likes

Interestingly there's no warning about a security vulnerability in the man page.

1 Like

That surprised me when I looked up system(3) in the man pages, and is why I didn't explicitly mention security in my plea. The Linux man page has detailed discussion about the security implications.

2 Likes

Oh wow, that’s not good. I’ve filed a bug requesting that we add something about this (r. 106131057).

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

4 Likes

popen (which was also mentioned) runs a shell as well.