Skip to content

Commit 855ca10

Browse files
committed
detect symlinks to same packages
After this changes bsb_pkg.ml will not show duplicated packages warning when conflicting packages are symlinks that are pointing to the same folder.
1 parent 1ea5ed5 commit 855ca10

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

bspack.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"-w",
1010
"-40-30-3",
1111
"#{self.root / 'jscomp' / 'stubs' / 'ext_basic_hash_stubs.c'}",
12+
"#{self.root / 'jscomp' / 'stubs' / 'realpath.c'}",
1213
"unix.cmxa",
1314
"#{self.root / 'lib' / '4.06.1' / 'unstable' / 'bspack.ml'}",
1415
"-o",

jscomp/bsb/bsb_pkg.ml

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ let check_dir dir =
4646
| true -> Some(dir)
4747
| false -> None
4848

49+
let is_same_paths a b =
50+
if a = b then true
51+
else
52+
match Bs_realpath_stubs.realpath a, Bs_realpath_stubs.realpath b with
53+
| Some a, Some b -> a = b
54+
| _ -> false
55+
4956
let resolve_bs_package_aux ~cwd (pkg : t) =
5057
(* First try to resolve recursively from the current working directory *)
5158
let sub_path = make_sub_path pkg in
@@ -151,7 +158,7 @@ let resolve_bs_package ~cwd (package : t) =
151158
| Some x
152159
->
153160
let result = resolve_bs_package_aux ~cwd package in
154-
if result <> x then
161+
if not (is_same_paths result x) then
155162
begin
156163
Bsb_log.warn
157164
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."

jscomp/stubs/bs_realpath_stubs.ml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
external realpath : string -> string option = "caml_realpath"

jscomp/stubs/realpath.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <caml/mlvalues.h>
2+
#include <caml/memory.h>
3+
#include <caml/alloc.h>
4+
#include <limits.h>
5+
#include <stdlib.h>
6+
7+
#define Val_none Val_int(0)
8+
9+
static value
10+
Val_some( value v )
11+
{
12+
CAMLparam1( v );
13+
CAMLlocal1( some );
14+
some = caml_alloc(1, 0);
15+
Store_field( some, 0, v );
16+
CAMLreturn( some );
17+
}
18+
19+
CAMLprim value
20+
caml_realpath(value v) {
21+
char *input;
22+
char output[PATH_MAX];
23+
char *result;
24+
25+
CAMLparam1(v);
26+
27+
input = String_val(v);
28+
result = realpath(input, output);
29+
if (result == NULL) {
30+
CAMLreturn(Val_none);
31+
} else {
32+
CAMLreturn(Val_some(caml_copy_string(output)));
33+
}
34+
}

scripts/ciTest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function main() {
9292
'unstable',
9393
'all_ounit_tests.ml'),
9494
path.join(binDir, 'all_ounit_tests.ml'))
95-
cp.execSync(`ocamlopt.opt -g -w -40-30 ../stubs/ext_basic_hash_stubs.c -I +compiler-libs ocamlcommon.cmxa unix.cmxa str.cmxa all_ounit_tests.ml -o test.exe`,
95+
cp.execSync(`ocamlopt.opt -g -w -40-30 ../stubs/realpath.c ../stubs/ext_basic_hash_stubs.c -I +compiler-libs ocamlcommon.cmxa unix.cmxa str.cmxa all_ounit_tests.ml -o test.exe`,
9696
{
9797
cwd: binDir,
9898
stdio : [0,1,2]

scripts/ninja.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,7 @@ rule mk_bsversion
16191619
rule gcc
16201620
command = $ocamlopt -ccopt -fPIC -ccopt -O2 -ccopt -o -ccopt $out -c $in
16211621
build stubs/ext_basic_hash_stubs.o : gcc stubs/ext_basic_hash_stubs.c
1622+
build stubs/realpath.o : gcc stubs/realpath.c
16221623
rule ocamlmklib
16231624
command = $ocamlmklib $in -o $name
16241625
@@ -1629,11 +1630,13 @@ build ext/js_reserved_map.ml: mk_keywords ../scripts/build_sorted.ml keywords.li
16291630
16301631
build stubs/libbs_hash.a stubs/dllbs_hash.so: ocamlmklib stubs/ext_basic_hash_stubs.o
16311632
name = stubs/bs_hash
1633+
build stubs/libbs_realpath.a stubs/dllbs_realpath.so: ocamlmklib stubs/realpath.o
1634+
name = stubs/bs_realpath
16321635
rule stubslib
16331636
command = $ocamlopt -a $ml -o $out -cclib $clib
1634-
build stubs/stubs.cmxa : stubslib stubs/bs_hash_stubs.cmx stubs/libbs_hash.a
1635-
ml = stubs/bs_hash_stubs.cmx
1636-
clib = stubs/libbs_hash.a
1637+
build stubs/stubs.cmxa : stubslib stubs/bs_hash_stubs.cmx stubs/libbs_hash.a stubs/bs_realpath_stubs.cmx stubs/libbs_realpath.a
1638+
ml = stubs/bs_hash_stubs.cmx stubs/bs_realpath_stubs.cmx
1639+
clib = stubs/libbs_hash.a stubs/libbs_realpath.a
16371640
16381641
${generateVisitorPattern()}
16391642

scripts/ninjaFactory.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function libNinja(config){
1212
ocamlopt = ${config.ocamlopt}
1313
ext = ${config.ext}
1414
INCL = ${config.INCL}
15-
flags = -nodynlink -I $INCL -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c
15+
flags = -nodynlink -I $INCL -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c ../jscomp/stubs/realpath.c
1616
rule cc
1717
command = $ocamlopt $flags $in -o $out ${config.isWin? '' : '&& strip $out'}
1818
description = Making $out
@@ -32,4 +32,4 @@ build bsc$ext: cc $INCL/whole_compiler.mli $INCL/whole_compiler.ml
3232
`
3333
}
3434

35-
exports.libNinja = libNinja
35+
exports.libNinja = libNinja

0 commit comments

Comments
 (0)