Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip directories when looking up programs in the PATH #1628

Merged
2 commits merged into from Dec 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ unreleased
- unstable-fmt: use boxes to wrap some lists (#1608, fix #1153, @emillon,
thanks to @rgrinberg)

- skip directories when looking up programs in the PATH (#1628, fixes
#1616, @diml)

1.6.2 (05/12/2018)
------------------

10 changes: 8 additions & 2 deletions src/stdune/bin.ml
Original file line number Diff line number Diff line change
@@ -18,13 +18,19 @@ let cons_path p ~_PATH =

let exe = if Sys.win32 then ".exe" else ""

let exists fn =
match Unix.stat (Path.to_string fn) with
| { st_kind = S_DIR; _ } -> false
| exception (Unix.Unix_error _) -> false
| _ -> true

let best_prog dir prog =
let fn = Path.relative dir (prog ^ ".opt" ^ exe) in
if Path.exists fn then
if exists fn then
Some fn
else
let fn = Path.relative dir (prog ^ exe) in
if Path.exists fn then
if exists fn then
Some fn
else
None
10 changes: 10 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
@@ -455,6 +455,14 @@
test-cases/github1560
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))

(alias
(name github1616)
(deps (package dune) (source_tree test-cases/github1616))
(action
(chdir
test-cases/github1616
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))

(alias
(name github20)
(deps (package dune) (source_tree test-cases/github20))
@@ -1225,6 +1233,7 @@
(alias github1529)
(alias github1549)
(alias github1560)
(alias github1616)
(alias github20)
(alias github24)
(alias github25)
@@ -1368,6 +1377,7 @@
(alias github1529)
(alias github1549)
(alias github1560)
(alias github1616)
(alias github20)
(alias github24)
(alias github25)
2 changes: 2 additions & 0 deletions test/blackbox-tests/test-cases/github1616/bin1/prog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec echo 'Hello, World!'
Empty file.
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/github1616/root/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(alias
(name default)
(action (run prog)))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.6)
6 changes: 6 additions & 0 deletions test/blackbox-tests/test-cases/github1616/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Regression test for #1616

$ env PATH="$PWD/bin2:$PWD/bin1:$PATH" dune build --root root
Entering directory 'root'
prog alias default
Hello, World!