Skip to content

Commit

Permalink
hie-bios: Don't hard-code import-dirs (digital-asset#2562)
Browse files Browse the repository at this point in the history
* hie-bios: Don't hard-code import-dirs

* Formatting
  • Loading branch information
aherrmann-da authored and mergify[bot] committed Aug 15, 2019
1 parent f209950 commit 76b9a47
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
29 changes: 0 additions & 29 deletions .hie-bios
Original file line number Diff line number Diff line change
@@ -1,31 +1,2 @@
#!/bin/sh
cat "$HIE_BIOS_ARGS" | sed "s/'//g" | sed "s/-qg//g" | sed "s/+RTS.*-RTS//" | sed "s|/bazel-out|bazel-out|g" | sed "s/-fexternal-interpreter//g"

BAZEL_GENFILES="$(bazel info bazel-genfiles)"

# For now we hardcode include paths as Bazel passes the list of files explicitly
# and does not use include paths so we cannot get it from the GHCi invocation.
echo \
-i"${BAZEL_GENFILES}" \
-i"${BAZEL_GENFILES}"/compiler/scenario-service/protos \
-i"${BAZEL_GENFILES}"/daml-lf/archive \
-icompiler/damlc/daml-compiler/src \
-icompiler/damlc/daml-doc/src \
-icompiler/damlc/daml-doctest/src \
-icompiler/damlc/daml-ide/src \
-icompiler/damlc/daml-ide-core/src \
-icompiler/damlc/daml-lf-conversion/src \
-icompiler/damlc/daml-opts/daml-opts \
-icompiler/damlc/daml-opts/daml-opts-types \
-icompiler/damlc/daml-preprocessor/src \
-icompiler/damlc/lib \
-icompiler/daml-lf-ast/src \
-icompiler/daml-lf-proto/src \
-icompiler/daml-lf-reader/src \
-icompiler/daml-lf-tools/src \
-icompiler/hie-core/src \
-icompiler/scenario-service/client/src \
-idaml-assistant/ \
-idaml-assistant/daml-project-config \
-ilibs-haskell/bazel-runfiles/src \
-ilibs-haskell/da-hs-base/src
54 changes: 54 additions & 0 deletions bazel_tools/haskell_public_ghci_repl_wrapper.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,57 @@ index 1d31257..6037b84 100644
allow_single_file = True,
default = Label("@rules_haskell//haskell:private/ghci_repl_wrapper.sh"),
),
diff --git a/haskell/repl.bzl b/haskell/repl.bzl
index 1d31257..2ef2f3c 100644
--- a/haskell/repl.bzl
+++ b/haskell/repl.bzl
@@ -28,6 +28,7 @@ HaskellReplLoadInfo = provider(
""",
fields = {
"source_files": "Set of files that contain Haskell modules.",
+ "import_dirs": "Set of Haskell import directories.",
"cc_info": "CcInfo of transitive C dependencies.",
"compiler_flags": "Flags to pass to the Haskell compiler.",
"repl_ghci_args": "Arbitrary extra arguments to pass to GHCi. This extends `compiler_flags` and `repl_ghci_args` from the toolchain",
@@ -72,18 +73,21 @@ HaskellReplInfo = provider(

def _merge_HaskellReplLoadInfo(load_infos):
source_files = depset()
+ import_dirs = depset()
cc_infos = []
compiler_flags = []
repl_ghci_args = []

for load_info in load_infos:
source_files = depset(transitive = [source_files, load_info.source_files])
+ import_dirs = depset(transitive = [import_dirs, load_info.import_dirs])
cc_infos.append(load_info.cc_info)
compiler_flags += load_info.compiler_flags
repl_ghci_args += load_info.repl_ghci_args

return HaskellReplLoadInfo(
source_files = source_files,
+ import_dirs = import_dirs,
cc_info = cc_common.merge_cc_infos(cc_infos = cc_infos),
compiler_flags = compiler_flags,
repl_ghci_args = repl_ghci_args,
@@ -114,6 +118,7 @@ def _create_HaskellReplCollectInfo(target, ctx):
if not HaskellToolchainLibraryInfo in target:
load_infos[target.label] = HaskellReplLoadInfo(
source_files = hs_info.source_files,
+ import_dirs = set.to_depset(hs_info.import_dirs),
cc_info = cc_common.merge_cc_infos(cc_infos = [
# Collect pure C library dependencies, no Haskell dependencies.
dep[CcInfo]
@@ -235,6 +240,10 @@ def _create_repl(hs, ctx, repl_info, output):
)
link_libraries(ghci_extra_libs, args)

+ # Add import directories
+ for import_dir in repl_info.load_info.import_dirs.to_list():
+ args.append("-i" + (import_dir if import_dir else "."))
+
# Load source files
# Force loading by source with `:add *...`.
# See https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html#ghci-cmd-:add

5 changes: 3 additions & 2 deletions compiler/damlc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ da_haskell_binary(
hazel_deps = [
"base",
],
src_strip_prefix = "src",
src_strip_prefix = "exe",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
Expand All @@ -46,7 +46,7 @@ da_haskell_binary(
hazel_deps = [
"base",
],
src_strip_prefix = "src",
src_strip_prefix = "exe",
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
Expand Down Expand Up @@ -124,6 +124,7 @@ da_haskell_library(
"unordered-containers",
"uniplate",
],
src_strip_prefix = "lib",
visibility = ["//visibility:public"],
deps = [
"//:sdk-version-hs-lib",
Expand Down

0 comments on commit 76b9a47

Please sign in to comment.