ocaml/oasis — pull request #45 by fdopen (2014-03-18 18:59:51+00:00)
Title: improve windows support

I've added the following changes, in order to ease the compilation of oasis packages on windows.

**1) I've introduced a '--use-bash' switch for configure**

If this switch is used, external shell commands in \_oasis will be executed by bash, instead of plain Sys.command \(cmd.exe on windows\). (e.g. ocaml setup.ml \-configure \-\-use-bash C:\cygwin\bin\bash.exe\)

This is necessary in many cases in order to build packages on windows. Instructions like

PreConfCommand: config/detect.sh
PostConfCommand: config/discover.sh $ocamlc lib/config.mlh lib/config.h
PostConfCommand: mkdir -p _build/test
PostConfCommand: mkdir _build ; mkdir _build.2

are quite common.

I've also added some code that will warn oasis users, if they use possibly non-portable commands \(quite primitive checks, of course\).

The most common build systems for ocaml \(ocamlbuild and gmake\) already requires bash, so users have to install cygwin \(or msys\) anyway. Only omake is in theory independent of cygwin, but most OMakefiles use unix commands in their rules. In practice this switch doesn't currently add a further dependency.

**2) better quote handling**

Necessary for windows because of common white space characters in paths. Users with restricted rights might even not be able to create a new file in a folder, that doesn't contain a space character.

a) quote parameters:

PostConfCommand: config/help.sh $ocamlc

will be treated as:

PostConfCommand: config/help.sh "$ocamlc"

b) quote the program itself:

PostConfCommand: $rm file

will possibly treated \(on windows platforms\) as:

PostConfCommand: "$rm" file

The problem here is, that "$rm" could be "rm -f" \(no quoting intended\) or "C:\Program Files\My Program\del.exe" \(quoting intended\).
There is no clean solution to this problem, as long as expansions like "rm -f" are supposed to work. See my comment in src/oasis/OASISExec.ml and the current workaround.

c) use uniform path separators \(windows only\)

Windows supports two path separators: \ and /. I capture the output of several commands and enforce a uniform path separator. If '--use-bash' is used, '/' is preferable, because it doesn't need to be quoted; otherwise '\' should be used.

**Still to do**

**a) Better implementation of OASISValues.command_line**

PostBuildCommand: long-command -param 1 \
-param2 -param3 ...

is not portable, because windows batch doesn't support this syntax. The escaped newline could also be inside an string, which complicates it further:

PostBuildCommand: long-command -param 1 "test\
string" -param2 -param3 ...

An improved version should recognize quoted parameters and automatically remove trivial syntax incompatibilities as in the example above.