From f69babef6d6a496dfea2896859a897baddf853eb Mon Sep 17 00:00:00 2001 From: Inari Listenmaa Date: Wed, 27 Jul 2022 14:53:58 +0200 Subject: [PATCH 1/7] add link to Inari's blog --- index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/index.html b/index.html index f657cc5b5..0b9090ee7 100644 --- a/index.html +++ b/index.html @@ -57,6 +57,7 @@
  • Shell Reference
  • Best Practices [PDF]
  • Scaling Up (Computational Linguistics 2020)
  • +
  • GF blog
  • From 08fb29e6b846e24f9f1e4de21e05d220bdf54624 Mon Sep 17 00:00:00 2001 From: krangelov Date: Fri, 12 Aug 2022 10:51:56 +0200 Subject: [PATCH 2/7] fix the reference counting for pgf.BIND --- src/runtime/python/pypgf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c index 941986593..e6df2632b 100644 --- a/src/runtime/python/pypgf.c +++ b/src/runtime/python/pypgf.c @@ -1184,6 +1184,8 @@ BIND_alloc(PyTypeObject *self, Py_ssize_t nitems) { if (BIND_instance == NULL) BIND_instance = PyType_GenericAlloc(self, nitems); + else + Py_INCREF(BIND_instance); return BIND_instance; } @@ -1720,6 +1722,7 @@ Concr_complete(ConcrObject* self, PyObject *args, PyObject *keywds) sentence = PyUnicode_AsUTF8(sentence0); } else { PyErr_SetString(PyExc_TypeError, "The sentence must be either a string or a tuple of string and pgf.BIND"); + return NULL; } PgfType* type; From 3acb7d2da481350a7be328d6f7c0b095661d05ec Mon Sep 17 00:00:00 2001 From: krangelov Date: Fri, 12 Aug 2022 10:54:43 +0200 Subject: [PATCH 3/7] silence harmless warnings --- src/runtime/python/pypgf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c index e6df2632b..bca151ba7 100644 --- a/src/runtime/python/pypgf.c +++ b/src/runtime/python/pypgf.c @@ -385,7 +385,7 @@ Expr_call(ExprObject* self, PyObject* args, PyObject* kw) pyexpr->pool = gu_new_pool(); pyexpr->expr = self->expr; - for (Py_ssize_t i = 0; i < n_args; i++) { + for (size_t i = 0; i < n_args; i++) { PyObject* obj = PyTuple_GetItem(args, i); if (obj->ob_type != &pgf_ExprType) { PyErr_SetString(PyExc_TypeError, "the arguments must be expressions"); @@ -549,7 +549,7 @@ Expr_visit(ExprObject* self, PyObject *args) return NULL; } - for (size_t i = 0; i < app->n_args; i++) { + for (size_t i = 0; i < (size_t) app->n_args; i++) { ExprObject* pyarg = (ExprObject*) pgf_ExprType.tp_alloc(&pgf_ExprType, 0); if (pyarg == NULL) { Py_DECREF(args); @@ -856,7 +856,7 @@ Type_init(TypeObject *self, PyObject *args, PyObject *kwds) self->type->cid = gu_string_copy(catname_s, self->pool); self->type->n_exprs = n_exprs; - for (Py_ssize_t i = 0; i < n_exprs; i++) { + for (size_t i = 0; i < n_exprs; i++) { PyObject* obj = PyList_GetItem(py_exprs, i); if (Py_TYPE(obj) != &pgf_ExprType) { PyErr_SetString(PyExc_TypeError, "the arguments in the second list must be expressions"); @@ -1680,7 +1680,7 @@ Concr_complete(ConcrObject* self, PyObject *args, PyObject *keywds) static char *kwlist[] = {"sentence", "cat", "prefix", "n", NULL}; PyObject* sentence0 = NULL; - char* sentence = NULL; + const char* sentence = NULL; PyObject* start = NULL; GuString prefix = ""; bool prefix_bind = false; @@ -1690,10 +1690,10 @@ Concr_complete(ConcrObject* self, PyObject *args, PyObject *keywds) &prefix, &max_count)) return NULL; - IterObject* pyres = (IterObject*) - pgf_IterType.tp_alloc(&pgf_IterType, 0); - if (pyres == NULL) { - return NULL; + IterObject* pyres = (IterObject*) + pgf_IterType.tp_alloc(&pgf_IterType, 0); + if (pyres == NULL) { + return NULL; } pyres->source = (PyObject*) self->grammar; From 1294269cd60f3db7b056135104615625baeb528c Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Wed, 24 Aug 2022 11:57:47 +0200 Subject: [PATCH 4/7] workaround for the Nix madness --- README.md | 15 +++++++ Setup.hs | 81 ++++++++++++++++++++-------------- gf.cabal | 14 +----- src/compiler/GF/Interactive.hs | 2 - 4 files changed, 65 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 79e6ab68f..2d64a999f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,21 @@ or: ``` stack install ``` +Note that if you are unlucky to have Cabal 3.0 or later, then it uses +the so-called Nix style commands. Using those for GF development is +a pain. Every time when you change something in the source code, Cabal +will generate a new folder for GF to look for the GF libraries and +the GF cloud. Either reinstall everything with every change in the +compiler, or be sane and stop using cabal-install. Instead you can do: +``` +runghc Setup.hs configure +runghc Setup.hs build +runghc Setup.hs install +``` +The script will install the GF dependencies globally. The only solution +to the Nix madness that I found is radical: + + "No person, no problem" (Нет человека – нет проблемы). For more information, including links to precompiled binaries, see the [download page](https://www.grammaticalframework.org/download/index.html). diff --git a/Setup.hs b/Setup.hs index f8309cc00..58dc3e0c6 100644 --- a/Setup.hs +++ b/Setup.hs @@ -4,42 +4,68 @@ import Distribution.Simple.LocalBuildInfo(LocalBuildInfo(..),absoluteInstallDirs import Distribution.Simple.Setup(BuildFlags(..),Flag(..),InstallFlags(..),CopyDest(..),CopyFlags(..),SDistFlags(..)) import Distribution.PackageDescription(PackageDescription(..),emptyHookedBuildInfo) import Distribution.Simple.BuildPaths(exeExtension) +import System.Directory import System.FilePath((),(<.>)) +import System.Process +import Control.Monad(forM_,unless) +import Control.Exception(bracket_) +import Data.Char(isSpace) import WebSetup --- | Notice about RGL not built anymore -noRGLmsg :: IO () -noRGLmsg = putStrLn "Notice: the RGL is not built as part of GF anymore. See https://github.com/GrammaticalFramework/gf-rgl" - main :: IO () main = defaultMainWithHooks simpleUserHooks - { preBuild = gfPreBuild + { preConf = gfPreConf + , preBuild = gfPreBuild , postBuild = gfPostBuild , preInst = gfPreInst , postInst = gfPostInst , postCopy = gfPostCopy } where - gfPreBuild args = gfPre args . buildDistPref - gfPreInst args = gfPre args . installDistPref + gfPreConf args flags = do + pkgs <- fmap (map (dropWhile isSpace) . tail . lines) + (readProcess "ghc-pkg" ["list"] "") + forM_ dependencies $ \pkg -> do + let name = takeWhile (/='/') (drop 36 pkg) + unless (name `elem` pkgs) $ do + let fname = name <.> ".tar.gz" + callProcess "wget" [pkg,"-O",fname] + callProcess "tar" ["-xzf",fname] + removeFile fname + bracket_ (setCurrentDirectory name) (setCurrentDirectory ".." >> removeDirectoryRecursive name) $ do + exists <- doesFileExist "Setup.hs" + unless exists $ do + writeFile "Setup.hs" (unlines [ + "import Distribution.Simple", + "main = defaultMain" + ]) + let to_descr = reverse . + (++) (reverse ".cabal") . + drop 1 . + dropWhile (/='-') . + reverse + callProcess "wget" [to_descr pkg, "-O", to_descr name] + callProcess "runghc" ["Setup.hs","configure"] + callProcess "runghc" ["Setup.hs","build"] + callProcess "sudo" ["runghc","Setup.hs","install"] + + preConf simpleUserHooks args flags + + gfPreBuild args = gfPre args . buildDistPref + gfPreInst args = gfPre args . installDistPref gfPre args distFlag = do return emptyHookedBuildInfo gfPostBuild args flags pkg lbi = do - -- noRGLmsg let gf = default_gf lbi buildWeb gf flags (pkg,lbi) gfPostInst args flags pkg lbi = do - -- noRGLmsg - saveInstallPath args flags (pkg,lbi) installWeb (pkg,lbi) gfPostCopy args flags pkg lbi = do - -- noRGLmsg - saveCopyPath args flags (pkg,lbi) copyWeb flags (pkg,lbi) -- `cabal sdist` will not make a proper dist archive, for that see `make sdist` @@ -47,27 +73,16 @@ main = defaultMainWithHooks simpleUserHooks gfSDist pkg lbi hooks flags = do return () -saveInstallPath :: [String] -> InstallFlags -> (PackageDescription, LocalBuildInfo) -> IO () -saveInstallPath args flags bi = do - let - dest = NoCopyDest - dir = datadir (uncurry absoluteInstallDirs bi dest) - writeFile dataDirFile dir - -saveCopyPath :: [String] -> CopyFlags -> (PackageDescription, LocalBuildInfo) -> IO () -saveCopyPath args flags bi = do - let - dest = case copyDest flags of - NoFlag -> NoCopyDest - Flag d -> d - dir = datadir (uncurry absoluteInstallDirs bi dest) - writeFile dataDirFile dir - --- | Name of file where installation's data directory is recording --- This is a last-resort way in which the seprate RGL build script --- can determine where to put the compiled RGL files -dataDirFile :: String -dataDirFile = "DATA_DIR" +dependencies = [ + "https://hackage.haskell.org/package/utf8-string-1.0.2/utf8-string-1.0.2.tar.gz", + "https://hackage.haskell.org/package/json-0.10/json-0.10.tar.gz", + "https://hackage.haskell.org/package/network-bsd-2.8.1.0/network-bsd-2.8.1.0.tar.gz", + "https://hackage.haskell.org/package/httpd-shed-0.4.1.1/httpd-shed-0.4.1.1.tar.gz", + "https://hackage.haskell.org/package/exceptions-0.10.5/exceptions-0.10.5.tar.gz", + "https://hackage.haskell.org/package/stringsearch-0.3.6.6/stringsearch-0.3.6.6.tar.gz", + "https://hackage.haskell.org/package/multipart-0.2.1/multipart-0.2.1.tar.gz", + "https://hackage.haskell.org/package/cgi-3001.5.0.0/cgi-3001.5.0.0.tar.gz" + ] -- | Get path to locally-built gf default_gf :: LocalBuildInfo -> FilePath diff --git a/gf.cabal b/gf.cabal index 53548cd40..da54010d1 100644 --- a/gf.cabal +++ b/gf.cabal @@ -2,7 +2,7 @@ name: gf version: 3.11.0-git cabal-version: 1.22 -build-type: Custom +build-type: Simple license: OtherLicense license-file: LICENSE category: Natural Language Processing, Compiler @@ -44,14 +44,6 @@ data-files: www/translator/*.css www/translator/*.js -custom-setup - setup-depends: - base >= 4.9.1 && < 4.16, - Cabal >= 1.22.0.0, - directory >= 1.3.0 && < 1.4, - filepath >= 1.4.1 && < 1.5, - process >= 1.0.1.1 && < 1.7 - source-repository head type: git location: https://github.com/GrammaticalFramework/gf-core.git @@ -89,9 +81,7 @@ library mtl >= 2.2.1 && < 2.3, pretty >= 1.1.3 && < 1.2, random >= 1.1 && < 1.3, - utf8-string >= 1.0.1.1 && < 1.1, - -- We need transformers-compat >= 0.6.3, but that is only in newer snapshots where it is redundant. - transformers-compat >= 0.5.1.4 && < 0.7 + utf8-string >= 1.0.1.1 && < 1.1 if impl(ghc<8.0) build-depends: diff --git a/src/compiler/GF/Interactive.hs b/src/compiler/GF/Interactive.hs index 1ea62e4b3..676511680 100644 --- a/src/compiler/GF/Interactive.hs +++ b/src/compiler/GF/Interactive.hs @@ -38,8 +38,6 @@ import GF.Server(server) #endif import GF.Command.Messages(welcome) --- Provides an orphan instance of MonadFail for StateT in ghc versions < 8 -import Control.Monad.Trans.Instances () -- | Run the GF Shell in quiet mode (@gf -run@). mainRunGFI :: Options -> [FilePath] -> IO () From 3fac8415ca76964de684c4d40d56f5a5ac1338b7 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Wed, 24 Aug 2022 12:00:43 +0200 Subject: [PATCH 5/7] forgot to mention sudo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d64a999f..ba35795a4 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ compiler, or be sane and stop using cabal-install. Instead you can do: ``` runghc Setup.hs configure runghc Setup.hs build -runghc Setup.hs install +sudo runghc Setup.hs install ``` The script will install the GF dependencies globally. The only solution to the Nix madness that I found is radical: From e9bbd38f686a5026179b7295427d9620cf967ab7 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Wed, 24 Aug 2022 12:02:10 +0200 Subject: [PATCH 6/7] `gf --version` now prints the shared folder to be used by the RGL --- src/compiler/GF/Main.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/GF/Main.hs b/src/compiler/GF/Main.hs index 1b90430d6..2bf84dbc8 100644 --- a/src/compiler/GF/Main.hs +++ b/src/compiler/GF/Main.hs @@ -48,7 +48,10 @@ getOptions = do mainOpts :: Options -> [FilePath] -> IO () mainOpts opts files = case flag optMode opts of - ModeVersion -> putStrLn $ "Grammatical Framework (GF) version " ++ showVersion version ++ "\n" ++ buildInfo + ModeVersion -> do datadir <- getDataDir + putStrLn $ "Grammatical Framework (GF) version " ++ showVersion version ++ "\n" ++ + buildInfo ++ "\n" ++ + "Shared folder: " ++ datadir ModeHelp -> putStrLn helpMessage ModeServer port -> GFI1.mainServerGFI opts port files ModeCompiler -> mainGFC opts files From dc8dce90a034db82dee913ceeb1ea46034211b64 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Wed, 24 Aug 2022 14:00:22 +0200 Subject: [PATCH 7/7] added a Setup script to compile without cabal-install --- src/runtime/haskell-bind/Setup.hs | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/runtime/haskell-bind/Setup.hs diff --git a/src/runtime/haskell-bind/Setup.hs b/src/runtime/haskell-bind/Setup.hs new file mode 100644 index 000000000..e8ef27dbb --- /dev/null +++ b/src/runtime/haskell-bind/Setup.hs @@ -0,0 +1,3 @@ +import Distribution.Simple + +main = defaultMain