mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
Merge pull request #248 from tweag/nm-drop-shorten-dir
Drop rules_haskell patch shortening source-dirs
This commit is contained in:
commit
caae2b0aa3
@ -418,8 +418,6 @@ hazel_repositories(
|
|||||||
# although windows is not quite supported yet
|
# although windows is not quite supported yet
|
||||||
"x64_windows": "@io_tweag_rules_haskell_ghc_windows_amd64",
|
"x64_windows": "@io_tweag_rules_haskell_ghc_windows_amd64",
|
||||||
},
|
},
|
||||||
|
|
||||||
shorten_source_dirs_for = ["ghc-lib"] if is_windows else [],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
hazel_custom_package_hackage(
|
hazel_custom_package_hackage(
|
||||||
|
@ -1,140 +0,0 @@
|
|||||||
diff --git a/hazel/hazel.bzl b/hazel/hazel.bzl
|
|
||||||
index 41c568c..278e74d 100644
|
|
||||||
--- a/hazel/hazel.bzl
|
|
||||||
+++ b/hazel/hazel.bzl
|
|
||||||
@@ -26,6 +26,7 @@ def _cabal_haskell_repository_impl(ctx):
|
|
||||||
ctx.attr.package_flags,
|
|
||||||
ctx.attr.package_name + ".cabal",
|
|
||||||
"package.bzl",
|
|
||||||
+ ctx.attr.shorten_source_dirs,
|
|
||||||
)
|
|
||||||
|
|
||||||
_cabal_haskell_repository = repository_rule(
|
|
||||||
@@ -36,6 +37,7 @@ _cabal_haskell_repository = repository_rule(
|
|
||||||
"hazel_base_repo_name": attr.string(mandatory = True),
|
|
||||||
"download_options": attr.string_dict(mandatory = True),
|
|
||||||
"ghc_workspaces": attr.string_dict(mandatory = True),
|
|
||||||
+ "shorten_source_dirs": attr.bool(mandatory = True),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -102,7 +104,8 @@ def hazel_repositories(
|
|
||||||
extra_flags = {},
|
|
||||||
extra_libs = {},
|
|
||||||
exclude_packages = [],
|
|
||||||
- ghc_workspaces = default_ghc_workspaces):
|
|
||||||
+ ghc_workspaces = default_ghc_workspaces,
|
|
||||||
+ shorten_source_dirs_for = []):
|
|
||||||
"""Generates external dependencies for a set of Haskell packages.
|
|
||||||
|
|
||||||
This macro should be invoked in the WORKSPACE. It generates a set of
|
|
||||||
@@ -210,6 +213,7 @@ def hazel_repositories(
|
|
||||||
hazel_base_repo_name = hazel_base_repo_name,
|
|
||||||
download_options = download_options,
|
|
||||||
ghc_workspaces = ghc_workspaces,
|
|
||||||
+ shorten_source_dirs = p in shorten_source_dirs_for,
|
|
||||||
)
|
|
||||||
|
|
||||||
for p in core_packages:
|
|
||||||
diff --git a/hazel/hazel_base_repository/cabal2bazel.hs b/hazel/hazel_base_repository/cabal2bazel.hs
|
|
||||||
index 282bb71..202a754 100644
|
|
||||||
--- a/hazel/hazel_base_repository/cabal2bazel.hs
|
|
||||||
+++ b/hazel/hazel_base_repository/cabal2bazel.hs
|
|
||||||
@@ -20,6 +20,11 @@ import Distribution.PackageDescription.Parse
|
|
||||||
(readGenericPackageDescription, parseHookedBuildInfo, ParseResult(..))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+import Control.Monad (when)
|
|
||||||
+import Data.List (nub) -- I know...
|
|
||||||
+import Data.Maybe (fromMaybe)
|
|
||||||
+
|
|
||||||
+
|
|
||||||
import Distribution.Text (display, simpleParse)
|
|
||||||
import Distribution.Verbosity (normal)
|
|
||||||
import System.Environment (getArgs)
|
|
||||||
@@ -37,15 +42,39 @@ import Skylark
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
- ghcVersionStr:cabalFile:outFile:flagArgs <- getArgs
|
|
||||||
+ ghcVersionStr:cabalFile:outFile:shorten:flagArgs <- getArgs
|
|
||||||
gdesc <- readGenericPackageDescription normal cabalFile
|
|
||||||
let ghcVersion = case simpleParse ghcVersionStr of
|
|
||||||
Nothing -> error $ "Error parsing ghc version: " ++ show ghcVersionStr
|
|
||||||
Just v -> v
|
|
||||||
packageFlags = parseFlags flagArgs
|
|
||||||
desc <- maybeConfigure $ flattenToDefaultFlags ghcVersion packageFlags gdesc
|
|
||||||
+
|
|
||||||
+ let doShorten = shorten == "do_shorten"
|
|
||||||
+ mlibHsSourceDirs = (P.hsSourceDirs . P.libBuildInfo) <$> P.library desc
|
|
||||||
+ libHsSourceDirs = fromMaybe [] mlibHsSourceDirs
|
|
||||||
+ exeHsSourceDirs = concatMap (P.hsSourceDirs . P.buildInfo) $ P.executables desc
|
|
||||||
+ allHsSourceDirs = nub $ libHsSourceDirs <> exeHsSourceDirs
|
|
||||||
+ newSourceDirs = (\i -> "d" <> show i) <$> ([1 .. ] :: [Int])
|
|
||||||
+ mappings = zip allHsSourceDirs newSourceDirs
|
|
||||||
+ updateBuildInfo binfo = binfo { P.hsSourceDirs =
|
|
||||||
+ map
|
|
||||||
+ (\dir -> fromMaybe (error "expected mapping") (lookup dir mappings))
|
|
||||||
+ (P.hsSourceDirs binfo)
|
|
||||||
+ }
|
|
||||||
+ updateLib lib = lib { P.libBuildInfo = updateBuildInfo $ P.libBuildInfo lib }
|
|
||||||
+ updateExe exe = exe { P.buildInfo = updateBuildInfo $ P.buildInfo exe }
|
|
||||||
+ desc' = desc
|
|
||||||
+ { P.library = updateLib <$> P.library desc
|
|
||||||
+ , P.executables = updateExe <$> P.executables desc
|
|
||||||
+ }
|
|
||||||
+ desc'' = if doShorten then desc' else desc
|
|
||||||
+
|
|
||||||
+ when doShorten $
|
|
||||||
+ mapM_ (\(f,t) -> putStrLn (f <> ":" <> t)) mappings
|
|
||||||
+
|
|
||||||
writeFile outFile $ show $ renderStatements
|
|
||||||
- [Assign "package" $ packageDescriptionExpr desc]
|
|
||||||
+ [Assign "package" $ packageDescriptionExpr desc'']
|
|
||||||
|
|
||||||
parseFlags :: [String] -> Map.Map P.FlagName Bool
|
|
||||||
parseFlags = \case
|
|
||||||
diff --git a/hazel/hazel_base_repository/hazel_base_repository.bzl b/hazel/hazel_base_repository/hazel_base_repository.bzl
|
|
||||||
index fdc1364..358357b 100644
|
|
||||||
--- a/hazel/hazel_base_repository/hazel_base_repository.bzl
|
|
||||||
+++ b/hazel/hazel_base_repository/hazel_base_repository.bzl
|
|
||||||
@@ -69,7 +69,7 @@ hazel_base_repository = repository_rule(
|
|
||||||
)
|
|
||||||
|
|
||||||
# TODO: don't reload all package names into every repository.
|
|
||||||
-def symlink_and_invoke_hazel(ctx, hazel_base_repo_name, ghc_workspace, package_flags, cabal_path, output):
|
|
||||||
+def symlink_and_invoke_hazel(ctx, hazel_base_repo_name, ghc_workspace, package_flags, cabal_path, output, shorten_source_dirs):
|
|
||||||
cabal2bazel = get_executable_name("cabal2bazel", ctx)
|
|
||||||
for f in [cabal2bazel, "ghc-version"]:
|
|
||||||
ctx.symlink(Label("@" + hazel_base_repo_name + "//:" + f), f)
|
|
||||||
@@ -87,6 +87,8 @@ def symlink_and_invoke_hazel(ctx, hazel_base_repo_name, ghc_workspace, package_f
|
|
||||||
|
|
||||||
flag_args = []
|
|
||||||
|
|
||||||
+ shorten_source_dirs_arg = ["do_shorten"] if shorten_source_dirs else ["dont_shorten"]
|
|
||||||
+
|
|
||||||
for flag in package_flags:
|
|
||||||
if package_flags[flag] == "True":
|
|
||||||
flag_args += ["-flag-on", flag]
|
|
||||||
@@ -98,7 +100,7 @@ def symlink_and_invoke_hazel(ctx, hazel_base_repo_name, ghc_workspace, package_f
|
|
||||||
ghc_version,
|
|
||||||
cabal_path,
|
|
||||||
output,
|
|
||||||
- ] + flag_args, quiet = False)
|
|
||||||
+ ] + shorten_source_dirs_arg + flag_args, quiet = False)
|
|
||||||
|
|
||||||
if res.return_code != 0:
|
|
||||||
fail("Error running hazel on {}:\n{}\n{}".format(
|
|
||||||
@@ -108,6 +110,12 @@ def symlink_and_invoke_hazel(ctx, hazel_base_repo_name, ghc_workspace, package_f
|
|
||||||
))
|
|
||||||
if res.stderr:
|
|
||||||
print(res.stderr)
|
|
||||||
+
|
|
||||||
+ if shorten_source_dirs and res.stdout:
|
|
||||||
+ for line in res.stdout.splitlines():
|
|
||||||
+ (f, t) = line.split(":")
|
|
||||||
+ ctx.symlink(f, t)
|
|
||||||
+
|
|
||||||
ctx.file("BUILD", """
|
|
||||||
load("@ai_formation_hazel//third_party/cabal2bazel:bzl/cabal_package.bzl",
|
|
||||||
"cabal_haskell_package",
|
|
1
deps.bzl
1
deps.bzl
@ -65,7 +65,6 @@ def daml_deps():
|
|||||||
urls = ["https://github.com/tweag/rules_haskell/archive/%s.tar.gz" % rules_haskell_version],
|
urls = ["https://github.com/tweag/rules_haskell/archive/%s.tar.gz" % rules_haskell_version],
|
||||||
sha256 = rules_haskell_sha256,
|
sha256 = rules_haskell_sha256,
|
||||||
patches = [
|
patches = [
|
||||||
"@com_github_digital_asset_daml//bazel_tools:haskell-hazel-shorten-source-dirs.patch",
|
|
||||||
"@com_github_digital_asset_daml//bazel_tools:hackage_mirror.patch",
|
"@com_github_digital_asset_daml//bazel_tools:hackage_mirror.patch",
|
||||||
],
|
],
|
||||||
patch_args = ["-p2"],
|
patch_args = ["-p2"],
|
||||||
|
Loading…
Reference in New Issue
Block a user