From 8b76582baf19e2c90e0f438bbcd5ce25e6437eba Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Thu, 23 May 2019 15:08:29 +0200 Subject: [PATCH 1/3] Factor out list_exposed_modules --- haskell/private/actions/compile.bzl | 91 ++++++++++++++++++----------- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/haskell/private/actions/compile.bzl b/haskell/private/actions/compile.bzl index 530b23a04..60b85a570 100644 --- a/haskell/private/actions/compile.bzl +++ b/haskell/private/actions/compile.bzl @@ -515,40 +515,8 @@ def compile_library( 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, + exposed_modules_file = list_exposed_modules( + hs, ls_modules, other_modules, exposed_modules_reexports, c.interfaces_dir ) return struct( @@ -561,3 +529,58 @@ def compile_library( 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 From 36477328a244168702152dcaedae5c388bbe5f15 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Thu, 23 May 2019 15:13:25 +0200 Subject: [PATCH 2/3] Separate list_exposed_modules from compile_library These are two completely separate steps. Furthermore, only the non-profiled version would actually perform list_exposed_modules. --- haskell/private/actions/compile.bzl | 11 ----------- haskell/private/haskell_impl.bzl | 20 +++++++++++++------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/haskell/private/actions/compile.bzl b/haskell/private/actions/compile.bzl index 60b85a570..5d197c3f9 100644 --- a/haskell/private/actions/compile.bzl +++ b/haskell/private/actions/compile.bzl @@ -464,9 +464,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, @@ -512,13 +509,6 @@ def compile_library( arguments = c.args, ) - if with_profiling: - exposed_modules_file = None - else: - exposed_modules_file = list_exposed_modules( - hs, ls_modules, other_modules, exposed_modules_reexports, c.interfaces_dir - ) - return struct( interfaces_dir = c.interfaces_dir, objects_dir = c.objects_dir, @@ -526,7 +516,6 @@ def compile_library( 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, ) diff --git a/haskell/private/haskell_impl.bzl b/haskell/private/haskell_impl.bzl index 42a3875d7..758f8ce28 100644 --- a/haskell/private/haskell_impl.bzl +++ b/haskell/private/haskell_impl.bzl @@ -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", @@ -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, @@ -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: @@ -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 @@ -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, From 78bad42d885986c2cee62a42d5b45dae75b64166 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Thu, 23 May 2019 16:36:05 +0200 Subject: [PATCH 3/3] Drop exposed_modules_file in compile_binary The resulting file was never used --- haskell/private/actions/compile.bzl | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/haskell/private/actions/compile.bzl b/haskell/private/actions/compile.bzl index 5d197c3f9..2fab9b63a 100644 --- a/haskell/private/actions/compile.bzl +++ b/haskell/private/actions/compile.bzl @@ -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, )