# HG changeset patch # User wenzelm # Date 1544479400 -3600 # Node ID c3c9440cbf9b3afd91a0b7ef8a85a6f98839b688 # Parent 61396b9713d8b81761589d8155561205b7c815bb more formal Haskell project setup, with dependencies on packages from "stackage"; diff -r 61396b9713d8 -r c3c9440cbf9b lib/scripts/getsettings --- a/lib/scripts/getsettings Mon Dec 10 22:38:03 2018 +0100 +++ b/lib/scripts/getsettings Mon Dec 10 23:03:20 2018 +0100 @@ -113,6 +113,7 @@ if [ -d "$ISABELLE_STACK_ROOT" -a -f "$ISABELLE_STACK_ROOT/ISABELLE_GHC_PROGRAMS" ]; then if [ -f "$(cat "$ISABELLE_STACK_ROOT/ISABELLE_GHC_PROGRAMS")/$ISABELLE_GHC_VERSION/bin/ghc" ]; then ISABELLE_GHC="$ISABELLE_HOME/lib/scripts/ghc" + ISABELLE_GHC_STACK=true fi fi diff -r 61396b9713d8 -r c3c9440cbf9b src/Pure/Tools/ghc.ML --- a/src/Pure/Tools/ghc.ML Mon Dec 10 22:38:03 2018 +0100 +++ b/src/Pure/Tools/ghc.ML Mon Dec 10 23:03:20 2018 +0100 @@ -9,6 +9,8 @@ val print_codepoint: UTF8.codepoint -> string val print_symbol: Symbol.symbol -> string val print_string: string -> string + val project_template: {depends: string list, modules: string list} -> string + val new_project: Path.T -> {name: string, depends: string list, modules: string list} -> unit end; structure GHC: GHC = @@ -42,4 +44,47 @@ val print_string = quote o implode o map print_symbol o Symbol.explode; + +(* project setup *) + +fun project_template {depends, modules} = + Input.source_content_string \{-# START_FILE {{name}}.cabal #-} +name: {{name}} +version: 0.1.0.0 +homepage: default +license: BSD3 +author: default +maintainer: default +category: default +build-type: Simple +cabal-version: >=1.10 + +executable {{name}} + hs-source-dirs: src + main-is: Main.hs + default-language: Haskell2010 + build-depends: \ ^ commas ("base >= 4.7 && < 5" :: depends) ^ + Input.source_content_string \ + other-modules: \ ^ commas modules ^ + Input.source_content_string \ +{-# START_FILE Setup.hs #-} +import Distribution.Simple +main = defaultMain + +{-# START_FILE src/Main.hs #-} +module Main where + +main :: IO () +main = return () +\; + +fun new_project dir {name, depends, modules} = + let + val template_path = Path.append dir (Path.basic name |> Path.ext "hsfiles"); + val _ = File.write template_path (project_template {depends = depends, modules = modules}); + val {rc, err, ...} = + Bash.process ("cd " ^ File.bash_path dir ^ + "; isabelle ghc_stack new " ^ Bash.string name ^ " --bare " ^ File.bash_path template_path); + in if rc = 0 then () else error err end; + end; diff -r 61396b9713d8 -r c3c9440cbf9b src/Tools/Haskell/Haskell.thy --- a/src/Tools/Haskell/Haskell.thy Mon Dec 10 22:38:03 2018 +0100 +++ b/src/Tools/Haskell/Haskell.thy Mon Dec 10 23:03:20 2018 +0100 @@ -8,7 +8,7 @@ imports Pure begin -generate_file "Library.hs" = \ +generate_file "Isabelle/Library.hs" = \ {- Title: Tools/Haskell/Library.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -102,7 +102,7 @@ clean_name = reverse #> dropWhile (== '_') #> reverse \ -generate_file "Value.hs" = \ +generate_file "Isabelle/Value.hs" = \ {- Title: Haskell/Tools/Value.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -155,7 +155,7 @@ parse_real = Read.readMaybe \ -generate_file "Buffer.hs" = \ +generate_file "Isabelle/Buffer.hs" = \ {- Title: Tools/Haskell/Buffer.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -181,7 +181,7 @@ content (Buffer xs) = concat (reverse xs) \ -generate_file "Properties.hs" = \ +generate_file "Isabelle/Properties.hs" = \ {- Title: Tools/Haskell/Properties.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -215,7 +215,7 @@ else props \ -generate_file "Markup.hs" = \ +generate_file "Isabelle/Markup.hs" = \ {- Title: Haskell/Tools/Markup.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -585,7 +585,7 @@ no_output = ("", "") \ -generate_file "Completion.hs" = \ +generate_file "Isabelle/Completion.hs" = \ {- Title: Tools/Haskell/Completion.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -646,7 +646,7 @@ markup_report [make limit name_props make_names] \ -generate_file "File.hs" = \ +generate_file "Isabelle/File.hs" = \ {- Title: Tools/Haskell/File.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -681,7 +681,7 @@ IO.withFile path IO.AppendMode (\h -> do setup h; IO.hPutStr h s) \ -generate_file "XML.hs" = \ +generate_file "Isabelle/XML.hs" = \ {- Title: Tools/Haskell/XML.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -760,7 +760,7 @@ show_text = concatMap encode \ -generate_file "XML/Encode.hs" = \ +generate_file "Isabelle/XML/Encode.hs" = \ {- Title: Tools/Haskell/XML/Encode.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -846,7 +846,7 @@ variant fs x = [tagged (the (get_index (\f -> f x) fs))] \ -generate_file "XML/Decode.hs" = \ +generate_file "Isabelle/XML/Decode.hs" = \ {- Title: Tools/Haskell/XML/Decode.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -957,7 +957,7 @@ variant _ _ = err_body \ -generate_file "YXML.hs" = \ +generate_file "Isabelle/YXML.hs" = \ {- Title: Tools/Haskell/YXML.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -1085,7 +1085,7 @@ _ -> err "multiple results" \ -generate_file "Pretty.hs" = \ +generate_file "Isabelle/Pretty.hs" = \ {- Title: Tools/Haskell/Pretty.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -1239,7 +1239,7 @@ big_list name prts = block (fbreaks (str name : prts)) \ -generate_file "Term.hs" = \ +generate_file "Isabelle/Term.hs" = \ {- Title: Tools/Haskell/Term.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -1286,7 +1286,7 @@ deriving Show \ -generate_file "Term_XML/Encode.hs" = \ +generate_file "Isabelle/Term_XML/Encode.hs" = \ {- Title: Tools/Haskell/Term_XML/Encode.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) @@ -1328,7 +1328,7 @@ \case { App a -> Just ([], pair term term a); _ -> Nothing }] \ -generate_file "Term_XML/Decode.hs" = \ +generate_file "Isabelle/Term_XML/Decode.hs" = \ {- Title: Tools/Haskell/Term_XML/Decode.hs Author: Makarius LICENSE: BSD 3-clause (Isabelle) diff -r 61396b9713d8 -r c3c9440cbf9b src/Tools/Haskell/Test.thy --- a/src/Tools/Haskell/Test.thy Mon Dec 10 22:38:03 2018 +0100 +++ b/src/Tools/Haskell/Test.thy Mon Dec 10 23:03:20 2018 +0100 @@ -8,15 +8,18 @@ begin ML \ - Isabelle_System.with_tmp_dir "ghc" (fn dir => + Isabelle_System.with_tmp_dir "ghc" (fn tmp_dir => let - val files = Generated_Files.write_files \<^theory>\Haskell\ dir; + val src_dir = Path.append tmp_dir (Path.explode "src"); + val files = Generated_Files.write_files \<^theory>\Haskell\ src_dir; + + val modules = files + |> map (Path.implode #> unsuffix ".hs" #> space_explode "/" #> space_implode "."); + val _ = GHC.new_project tmp_dir {name = "isabelle", depends = [], modules = modules}; + val (out, rc) = Isabelle_System.bash_output - (cat_lines - ["set -e", - "cd " ^ File.bash_path dir, - "\"$ISABELLE_GHC\" " ^ File.bash_paths files]); + (cat_lines ["set -e", "cd " ^ File.bash_path tmp_dir, "isabelle ghc_stack build 2>&1"]); in if rc = 0 then writeln out else error out end) \ diff -r 61396b9713d8 -r c3c9440cbf9b src/Tools/ROOT --- a/src/Tools/ROOT Mon Dec 10 22:38:03 2018 +0100 +++ b/src/Tools/ROOT Mon Dec 10 23:03:20 2018 +0100 @@ -12,5 +12,5 @@ session Haskell in Haskell = Pure + theories Haskell - theories [condition = ISABELLE_GHC] + theories [condition = ISABELLE_GHC_STACK] Test