Skip to content

Account for "public" setting in bsconfig #824

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

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
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
35 changes: 27 additions & 8 deletions analysis/src/FindFiles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ let getNamespace config =
either fromString fromName |> Option.map nameSpaceToName
else None

module StringSet = Set.Make (String)

let getPublic config =
let public = config |> Json.get "public" in
match public with
| None -> None
| Some public -> (
match public |> Json.array with
| None -> None
| Some public ->
Some (public |> List.filter_map Json.string |> StringSet.of_list))

let collectFiles directory =
let allFiles = Files.readDirectory directory in
let compileds = allFiles |> List.filter isCompiledFile |> filterDuplicates in
Expand All @@ -124,8 +136,7 @@ let collectFiles directory =
| Some res -> Some (modName, SharedTypes.Impl {cmt; res}))

(* returns a list of (absolute path to cmt(i), relative path from base to source file) *)
let findProjectFiles ~namespace ~path ~sourceDirectories ~libBs =
let module StringSet = Set.Make (String) in
let findProjectFiles ~public ~namespace ~path ~sourceDirectories ~libBs =
let dirs =
sourceDirectories |> List.map (Filename.concat path) |> StringSet.of_list
in
Expand Down Expand Up @@ -179,10 +190,18 @@ let findProjectFiles ~namespace ~path ~sourceDirectories ~libBs =
in
let result =
normals
|> List.map (fun (name, paths) ->
match namespace with
| None -> (name, paths)
| Some namespace -> (name ^ "-" ^ namespace, paths))
|> List.filter_map (fun (name, paths) ->
let originalName = name in
let name =
match namespace with
| None -> name
| Some namespace -> name ^ "-" ^ namespace
in
match public with
| Some public ->
if public |> StringSet.mem originalName then Some (name, paths)
else None
| None -> Some (name, paths))
in
match namespace with
| None -> result
Expand Down Expand Up @@ -236,8 +255,8 @@ let findDependencyFiles base config =
| Some _ -> libBs :: compiledDirectories
in
let projectFiles =
findProjectFiles ~namespace ~path ~sourceDirectories
~libBs
findProjectFiles ~public:(getPublic inner) ~namespace
~path ~sourceDirectories ~libBs
in
Some (compiledDirectories, projectFiles))
| None -> None)
Expand Down
5 changes: 3 additions & 2 deletions analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ let newBsPackage ~rootPath =
config
in
let projectFilesAndPaths =
FindFiles.findProjectFiles ~namespace ~path:rootPath
~sourceDirectories ~libBs
FindFiles.findProjectFiles
~public:(FindFiles.getPublic config)
~namespace ~path:rootPath ~sourceDirectories ~libBs
in
projectFilesAndPaths
|> List.iter (fun (_name, paths) -> Log.log (showPaths paths));
Expand Down