Skip to content

Commit

Permalink
Merge pull request #891 from tweag/list_exposed_modules
Browse files Browse the repository at this point in the history
Separate list_exposed_modules from compile_library
  • Loading branch information
mboes authored May 24, 2019
2 parents 8947d54 + 78bad42 commit f9eaf6d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 71 deletions.
119 changes: 55 additions & 64 deletions haskell/private/actions/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -427,33 +427,12 @@ def compile_binary(
arguments = c.args,
)

if with_profiling:
exposed_modules_file = None
else:
exposed_modules_file = hs.actions.declare_file(
target_unique_name(hs, "exposed-modules"),
)
hs.actions.run(
inputs = [c.interfaces_dir, hs.toolchain.global_pkg_db],
outputs = [exposed_modules_file],
executable = ls_modules,
arguments = [
c.interfaces_dir.path,
hs.toolchain.global_pkg_db.path,
"/dev/null", # no hidden modules
"/dev/null", # no reexported modules
exposed_modules_file.path,
],
use_default_shell_env = True,
)

return struct(
objects_dir = c.objects_dir,
source_files = c.source_files,
extra_source_files = c.extra_source_files,
import_dirs = c.import_dirs,
compile_flags = c.compile_flags,
exposed_modules_file = exposed_modules_file,
coverage_data = coverage_data,
)

Expand All @@ -464,9 +443,6 @@ def compile_library(
dep_info,
plugin_dep_info,
srcs,
ls_modules,
other_modules,
exposed_modules_reexports,
import_dir_map,
extra_srcs,
user_compile_flags,
Expand Down Expand Up @@ -512,52 +488,67 @@ def compile_library(
arguments = c.args,
)

if with_profiling:
exposed_modules_file = None
else:
hidden_modules_file = hs.actions.declare_file(
target_unique_name(hs, "hidden-modules"),
)
hs.actions.write(
output = hidden_modules_file,
content = ", ".join(other_modules),
)
reexported_modules_file = hs.actions.declare_file(
target_unique_name(hs, "reexported-modules"),
)
hs.actions.write(
output = reexported_modules_file,
content = ", ".join(exposed_modules_reexports),
)
exposed_modules_file = hs.actions.declare_file(
target_unique_name(hs, "exposed-modules"),
)
hs.actions.run(
inputs = [
c.interfaces_dir,
hs.toolchain.global_pkg_db,
hidden_modules_file,
reexported_modules_file,
],
outputs = [exposed_modules_file],
executable = ls_modules,
arguments = [
c.interfaces_dir.path,
hs.toolchain.global_pkg_db.path,
hidden_modules_file.path,
reexported_modules_file.path,
exposed_modules_file.path,
],
use_default_shell_env = True,
)

return struct(
interfaces_dir = c.interfaces_dir,
objects_dir = c.objects_dir,
compile_flags = c.compile_flags,
source_files = c.source_files,
extra_source_files = c.extra_source_files,
import_dirs = c.import_dirs,
exposed_modules_file = exposed_modules_file,
coverage_data = coverage_data,
)

def list_exposed_modules(
hs,
ls_modules,
other_modules,
exposed_modules_reexports,
interfaces_dir):
"""Construct file listing the exposed modules of this package.
Args:
hs: The Haskell context.
ls_modules: The ls_modules.py executable.
other_modules: List of hidden modules.
exposed_modules_reexports: List of re-exported modules.
interfaces_dir: The directory containing the interface files.
Returns:
File: File holding the package ceonfiguration exposed-modules value.
"""
hidden_modules_file = hs.actions.declare_file(
target_unique_name(hs, "hidden-modules"),
)
hs.actions.write(
output = hidden_modules_file,
content = ", ".join(other_modules),
)
reexported_modules_file = hs.actions.declare_file(
target_unique_name(hs, "reexported-modules"),
)
hs.actions.write(
output = reexported_modules_file,
content = ", ".join(exposed_modules_reexports),
)
exposed_modules_file = hs.actions.declare_file(
target_unique_name(hs, "exposed-modules"),
)
hs.actions.run(
inputs = [
interfaces_dir,
hs.toolchain.global_pkg_db,
hidden_modules_file,
reexported_modules_file,
],
outputs = [exposed_modules_file],
executable = ls_modules,
arguments = [
interfaces_dir.path,
hs.toolchain.global_pkg_db.path,
hidden_modules_file.path,
reexported_modules_file.path,
exposed_modules_file.path,
],
use_default_shell_env = True,
)
return exposed_modules_file
20 changes: 13 additions & 7 deletions haskell/private/haskell_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ load(
"empty_HaskellCcInfo",
)
load(":cc.bzl", "cc_interop_info")
load(
":private/actions/compile.bzl",
"list_exposed_modules",
)
load(
":private/actions/link.bzl",
"link_binary",
Expand Down Expand Up @@ -337,9 +341,6 @@ def haskell_library_impl(ctx):
dep_info,
plugin_dep_info,
srcs = srcs_files,
ls_modules = ctx.executable._ls_modules,
other_modules = other_modules,
exposed_modules_reexports = exposed_modules_reexports,
import_dir_map = import_dir_map,
extra_srcs = depset(ctx.files.extra_srcs),
user_compile_flags = ctx.attr.compiler_flags,
Expand All @@ -349,6 +350,14 @@ def haskell_library_impl(ctx):
plugins = ctx.attr.plugins,
)

exposed_modules_file = list_exposed_modules(
hs,
ls_modules = ctx.executable._ls_modules,
other_modules = other_modules,
exposed_modules_reexports = exposed_modules_reexports,
interfaces_dir = c.interfaces_dir,
)

c_p = None

if with_profiling:
Expand All @@ -359,9 +368,6 @@ def haskell_library_impl(ctx):
dep_info,
plugin_dep_info,
srcs = srcs_files,
ls_modules = ctx.executable._ls_modules,
other_modules = other_modules,
exposed_modules_reexports = exposed_modules_reexports,
import_dir_map = import_dir_map,
# NOTE We must make the object files compiled without profiling
# available to this step for TH to work, presumably because GHC is
Expand Down Expand Up @@ -424,7 +430,7 @@ def haskell_library_impl(ctx):
c_p.interfaces_dir if c_p != None else None,
static_library,
dynamic_library,
c.exposed_modules_file,
exposed_modules_file,
other_modules,
my_pkg_id,
static_library_prof = static_library_prof,
Expand Down

0 comments on commit f9eaf6d

Please sign in to comment.