Conditionally using the .exe extension using the Shake build system

Using the wonderful Shake build system, I want to compile the project in a way that is incompatible with the host operating system.

I am having problems detecting the presence of binary files because they have a different extension on different systems (for example: Windows uses .exe ).

If I use the need clause to determine if the required binaries exist, how can I check either Main or Main.exe depending on whether the host is Linux or Windows?

+4
source share
1 answer

The function you execute is Development.Shake.FilePath.exe , which evaluates to "exe" on Windows and "" on all other platforms. Usually you write:

 want ["MyExecutable" <.> exe] "MyExecutable" <.> exe *> \out -> cmd "MyCompiler" "-o" [out] 

For an example, see .Self.Main Examples , which builds Main on Linux and Main.exe on Windows.

The only potential distortion is that all file templates to the left of *> must be unique. If you define "//*" <.> exe *> ... then on Windows, which will only match executable files (good), but on Linux, which will match every file, when faced with all other patterns (bad) . The solution is to make the executable names different, for example, put them in a special output directory, hard-type the names as "Main" <.> exe , etc. Alternatively, you can rely on the fact that only executable files do not have an extension on Linux with:

 (\x -> drop 1 (takeExtension x) == exe) ?> \out -> ... 
+3
source

Source: https://habr.com/ru/post/1501416/


All Articles