@@ -13,12 +13,14 @@ import Control.Monad
1313import Control.Monad.Except (ExceptT (.. ), runExceptT , throwError )
1414import Control.Monad.IO.Class (liftIO )
1515import Data.Foldable
16+ import Data.List.Extra (replace )
1617import Data.List.NonEmpty (NonEmpty (.. ))
1718import Data.List.NonEmpty qualified as NE
1819import Data.Maybe (fromMaybe )
1920import Data.Text.IO qualified as T
21+ import Paths_plutus_metatheory (getDataFileName )
2022import System.Directory (createDirectory )
21- import System.FilePath ((</>) )
23+ import System.FilePath (takeBaseName , (</>) )
2224
2325import FFI.AgdaUnparse (AgdaUnparse (.. ))
2426import FFI.CostInfo
@@ -314,7 +316,6 @@ data AgdaCertificateProject = AgdaCertificateProject
314316 { mainModule :: (FilePath , String )
315317 , astModules :: [(FilePath , String )]
316318 , agdalib :: (FilePath , String )
317- , readme :: (FilePath , String )
318319 }
319320
320321mkAgdaLib :: String -> (FilePath , String )
@@ -329,50 +330,6 @@ mkAgdaLib name =
329330 \\n flags: --polarity"
330331 in (name <> " .agda-lib" , contents)
331332
332- mkReadme :: String -> (FilePath , String )
333- mkReadme name =
334- let contents =
335- " # Certificate: "
336- <> name
337- <> " \n \
338- \\n \
339- \This directory contains a machine-verifiable Agda certificate that\n \
340- \proves the Plutus optimizer correctly transformed a program.\n \
341- \Type-checking this project with Agda verifies the certificate.\n \
342- \\n \
343- \## Dependencies\n \
344- \\n \
345- \- [Agda](https://agda.readthedocs.io/) 2.8.0\n \
346- \- [Agda standard library](https://github.com/agda/agda-stdlib) 2.3\n \
347- \- [plutus-metatheory](https://github.com/IntersectMBO/plutus/tree/master/plutus-metatheory)\n \
348- \\n \
349- \## Type-checking\n \
350- \\n \
351- \### Using Nix (recommended)\n \
352- \\n \
353- \Enter the development shell provided by the `plutus` repository, `cd` into the root of the certificate project, \n \
354- \and use the bundled Agda wrapper that includes all required libraries:\n \
355- \\n \
356- \```\n \
357- \nix develop\n \
358- \agda-with-stdlib-and-metatheory src/"
359- <> name
360- <> " .agda\n \
361- \```\n \
362- \\n \
363- \### Without Nix\n \
364- \\n \
365- \Ensure Agda 2.8.0 is installed and that both `standard-library-2.3`\n \
366- \and `plutus-metatheory` are registered in your `$AGDA_DIR/libraries`\n \
367- \file (see `plutus-metatheory/AGDA.md` for guidance), then run:\n \
368- \\n \
369- \```\n \
370- \agda src/"
371- <> name
372- <> " .agda\n \
373- \```\n "
374- in (" README.md" , contents)
375-
376333mkAgdaCertificateProject
377334 :: Certificate
378335 -> AgdaCertificateProject
@@ -381,8 +338,7 @@ mkAgdaCertificateProject cert =
381338 mainModule = mkCertificateFile cert
382339 astModules = fmap mkAgdaAstFile (certReprAsts cert)
383340 agdalib = mkAgdaLib name
384- readme = mkReadme name
385- in AgdaCertificateProject {mainModule, astModules, agdalib, readme}
341+ in AgdaCertificateProject {mainModule, astModules, agdalib}
386342
387343writeCertificateProject
388344 :: CertDir
@@ -394,17 +350,18 @@ writeCertificateProject
394350 { mainModule
395351 , astModules
396352 , agdalib
397- , readme
398353 } =
399354 liftIO $ do
400355 let (mainModulePath, mainModuleContents) = mainModule
401356 (agdalibPath, agdalibContents) = agdalib
402- (readmePath, readmeContents) = readme
357+ certName = takeBaseName mainModulePath
403358 createDirectory certDir
404359 createDirectory (certDir </> " src" )
405360 writeFile (certDir </> " src" </> mainModulePath) mainModuleContents
406361 writeFile (certDir </> agdalibPath) agdalibContents
407- writeFile (certDir </> readmePath) readmeContents
362+ templatePath <- getDataFileName " data/certificate-README.md"
363+ readmeTemplate <- readFile templatePath
364+ writeFile (certDir </> " README.md" ) (replace " {{NAME}}" certName readmeTemplate)
408365 traverse_
409366 ( \ (path, contents) ->
410367 writeFile (certDir </> " src" </> path) contents
0 commit comments