evoldoers / biomake

GNU-Make-like utility for managing builds and complex workflows
BSD 3-Clause "New" or "Revised" License
102 stars 9 forks source link

Set environment variables with export foo=bar [feature request] #50

Closed sjackman closed 6 years ago

sjackman commented 6 years ago

A GNU Makefile can set an environment variable like so:

export foo=bar
all:
    sh -c 'echo $$foo'
❯❯❯ make
sh -c 'echo $foo'
bar
❯❯❯ biomake
Exception: error(syntax_error(GNU makefile parse error at line 1 of file Makefile: export foo=bar),_1650)
sjackman commented 6 years ago

With GNU Make I use this feature to time each command using zsh like so:

export SHELL=zsh -opipefail
export REPORTTIME=1
export TIMEFMT=time user=%U system=%S elapsed=%E cpu=%P memory=%M job=%J
sjackman commented 6 years ago

In the mean time, does biomake define a variable that I could use to skip incompatible syntax? For example…

ifndef BIOMAKE
export SHELL=zsh -opipefail
export REPORTTIME=1
export TIMEFMT=time user=%U system=%S elapsed=%E cpu=%P memory=%M job=%J
endif
sjackman commented 6 years ago

GNU Make defines the variable MAKE_VERSION, so I can use ifdef MAKE_VERSION. Could Biomake please define BIOMAKE_VERSION?

sjackman commented 6 years ago

Using ifdef to skip incompatible syntax doesn't unfortunately work as I had hoped, because biomake still parses the text inside the conditional, even when the conditional is false.

ihh commented 6 years ago

Shouldn’t be hard to mimic export syntax. Sorry have been inattentive to biomake issues, will take a look at this tomorrow too

sjackman commented 6 years ago

Thanks, Ian! While you're looking at export, I also occasionally use override. e.g.

override foo=bar

The result is to set foo to bar even when biomake foo=ook is specified on the command line. This issue is low priority for me. The workaround is simply to remove the override keyword, which is usually fine.

ihh commented 6 years ago

This should work now @sjackman. You could open fresh issues for override and/or unexport if you decide you do need them.

sjackman commented 6 years ago

Thank you, Ian! 🎈