News for hackers. Stuff that matters.
Re:Show HN: Minimal build system using just /bin/sh by vog on Friday August 18, 2017 @04:01AM (#15044386)
I applaud the effort, but is "pure /bin/sh" really a good feature in today's systems?

To my knowledge, today every Unix system has Python, usually at least 2.7, if not Python 3. Some even replaced most of their system shell scripts with Python scripts. (Formerly, Perl had this status, but never really caught on in that area.)

Python is a much cleaner language than any shell language, especially with regard to error handling. (yes, I'm aware of "set -eu") Also, if you occationally need some more elaborated data structures or algorithms, you can express these in a straight forward way, rather than a series of complicated (and usually very fragile) text processing steps.

Re:Show HN: Minimal build system using just /bin/sh by majewsky on Friday August 18, 2017 @10:12AM (#15046332)
I see you've not yet encountered Alpine-based Docker containers.

  $ docker run --rm -ti alpine sh             
  / # bash
  sh: bash: not found
  / # python
  sh: python: not found
  / # perl
  sh: perl: not found
  / # ruby
  sh: ruby: not found
Sure, you can install all of these with a single `apk add`, but it makes your container much fatter, i.e. every CI job that has to pull the image will be taking a longer time. Same for when you push the image into a far-away datacenter.
Re:Show HN: Minimal build system using just /bin/sh by wrs on Friday August 18, 2017 @01:12PM (#15047962)
In a base Alpine container, it would be awfully hard to build anything interesting. You are probably going to need to install some build tools first anyway. (Thus the two-stage container pattern.)
Re:Show HN: Minimal build system using just /bin/sh by user5994461 on Friday August 18, 2017 @12:16PM (#15047493)
It's one of the reason that alpine should not be used outside of tests and toys projects. It cannot be substituted to an usual distribution.
Re:Show HN: Minimal build system using just /bin/sh by swiley on Friday August 18, 2017 @10:35AM (#15046531)
Python never works right for me, having to deal with yet another dependency just to use the build system is obnoxious.

Just use make. It's not hard and it works even for fairly large projects.

Re:Show HN: Minimal build system using just /bin/sh by edwinyzh on Friday August 18, 2017 @11:48AM (#15047220)
Speaking of using Python or Node.js as a language for a build process, there were so many times it failed when I trying to run the build script included in the github open source project I found interesting and downloaded to my local file system, and usually it's a project not written in my familiar language, and since I'm NOT familiar with Python nor node.js, so when the build script emit something like a dependency error, after several tries without success, I usually just give up.
Re:Show HN: Minimal build system using just /bin/sh by akkartik on Friday August 18, 2017 @04:04AM (#15044398)
Totally agreed; I'd use a different language if I needed even an array.
Re:Show HN: Minimal build system using just /bin/sh by nailer on Friday August 18, 2017 @07:55AM (#15045342)
Also most current Unixes have at least Bash. Bourne shell is surprisingly rare outside BSD.
Re:Show HN: Minimal build system using just /bin/sh by kingmanaz on Friday August 18, 2017 @10:36AM (#15046537)
Or Korn, which is better than Bash, IMHO.
Re:Show HN: Minimal build system using just /bin/sh by adtac on Friday August 18, 2017 @04:05AM (#15044402)
I'm having a hard time thinking of a use case for complex data structures in a build script. Can you give a real world example?

Array is the only one that I have found lacking, in my experience.

Re:Show HN: Minimal build system using just /bin/sh by dom0 on Friday August 18, 2017 @07:35AM (#15045252)
> I'm having a hard time thinking of a use case for complex data structures in a build script. Can you give a real world example?

Look at how a modern build system (like qbs) organizes the build. It builds a declarative object graph describing the project and maps that to a dependency graph where each node can be a relatively complex object ("compile C++ file X using flags Y" or "link LargeSetOfFiles") annotated with modification data (like input file hashes). (Then it compares the dependency graph to what is found on the system and creates a list of commands to execute in order to bring whatever is on the system to the desired state, i.e. create an up to date build).

Re:Show HN: Minimal build system using just /bin/sh by vog on Friday August 18, 2017 @04:09AM (#15044416)
If you aim for slightly larger projects and efficiency, you'd need at least a DAG (because that's the fundamental nature of a dependency graph).

You can find a nice explanation in the "tup" build tool, although there are of course many others: http://gittup.org/tup/

And yes, you can express DAGs with text and/or filesystem operations (plus symlinks), but not efficiently and writing code that operates on that level is cumbersome.

Re:Show HN: Minimal build system using just /bin/sh by svckr on Friday August 18, 2017 @07:29AM (#15045227)
Regarding DAG: tsort (1) sorts input lines by interpreting them as a list of edges. I guess that's what you where referring to when you said "cumbersome" :)

    $ cat > f
    a c
    a d
    b c
    ^D
    $ tsort f
    a
    b
    d
    c
Re:Show HN: Minimal build system using just /bin/sh by vog on Friday August 18, 2017 @08:12AM (#15045413)
The problem is not tsort, it is adding, removing, updating items in such a text file. (not to mention nasty corner cases like filenames containing whitespaces, or the security implications of filenames containing newlines)
Re:Show HN: Minimal build system using just /bin/sh by chenglou on Friday August 18, 2017 @06:34AM (#15045002)
Tup is pretty darn amazing. I've never had such a high success rate while writing build rules under it. "Once it builds, it has no bug". Not to mention the great speed to begin with.

Is there any similar build system? I know of https://github.com/droundy/fac, but it's not cross-platform

Re:Show HN: Minimal build system using just /bin/sh by dom0 on Friday August 18, 2017 @07:37AM (#15045264)
tup sounds similar to qbs. I found qbs to be a most amazing C++ build system, it's the only one I used that is

1) reasonably easy to use 2) very fast 3) very correct

Most build systems fail 3), usually 2) and often also 1).

Re:Show HN: Minimal build system using just /bin/sh by CJefferson on Friday August 18, 2017 @12:00PM (#15047325)
What makes tup amazing is it traces which files a program touches, so assuming your programs obey the rule "I need to rerun if I have different command line arguments or something I read has changed", you get perfect dependencies for any program. I use it for running experiments with custom programs and scripts all the time, and it just refund the parts I need.
Re:Show HN: Minimal build system using just /bin/sh by akkartik on Friday August 18, 2017 @05:07AM (#15044652)
Ah, thanks for the pointer to `tup`! I'd spent a while looking for it a few months ago but couldn't remember the name.
Re:Show HN: Minimal build system using just /bin/sh by chubot on Friday August 18, 2017 @09:21AM (#15045814)
Hash tables are useful for expressing build variants -- some examples at the end of this comment:

https://news.ycombinator.com/item?id=15043633

debug/release, internationalized builds, coverage builds, profile-directed feedback, running parameterized test suites, etc.

Re:Show HN: Minimal build system using just /bin/sh by johnt15 on Friday August 18, 2017 @04:12AM (#15044429)
Any large project needs a build system with complex data structures to express all the dependencies just due to sheer amount of them. Add various types of source generation, tooling, non-trivial build steps and simple build systems quickly become infeasible.
Re:Show HN: Minimal build system using just /bin/sh by cbcoutinho on Friday August 18, 2017 @04:10AM (#15044422)
I've used a project in the past that was a number of shell scripts that were written to handle cross-platform and (at least on Linux) various shells (bash, zsh, etc.). It can be done, but it becomes a complete kludge very quickly.