Skip to content

Commit 78a9bd0

Browse files
committed
Address review comment: use static file for readme
1 parent de2cc99 commit 78a9bd0

3 files changed

Lines changed: 42 additions & 51 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Certificate: {{NAME}}
2+
3+
This directory contains a machine-verifiable Agda certificate that
4+
proves the Plutus optimizer correctly transformed a program.
5+
Type-checking this project with Agda verifies the certificate.
6+
7+
## Dependencies
8+
9+
- [Agda](https://agda.readthedocs.io/) 2.8.0
10+
- [Agda standard library](https://github.com/agda/agda-stdlib) 2.3
11+
- [plutus-metatheory](https://github.com/IntersectMBO/plutus/tree/master/plutus-metatheory)
12+
13+
## Type-checking
14+
15+
### Using Nix (recommended)
16+
17+
Enter the development shell provided by the `plutus` repository, `cd` into the root of the certificate project,
18+
and use the bundled Agda wrapper that includes all required libraries:
19+
20+
```
21+
nix develop
22+
agda-with-stdlib-and-metatheory src/{{NAME}}.agda
23+
```
24+
25+
### Without Nix
26+
27+
Ensure Agda 2.8.0 is installed and that both `standard-library-2.3`
28+
and `plutus-metatheory` are registered in your `$AGDA_DIR/libraries`
29+
file (see `plutus-metatheory/AGDA.md` for guidance), then run:
30+
31+
```
32+
agda src/{{NAME}}.agda
33+
```

plutus-metatheory/plutus-metatheory.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ maintainer: james.chapman@iohk.io
1313
category: Development
1414
build-type: Simple
1515
data-files:
16+
data/certificate-README.md
1617
plutus-metatheory.agda-lib
1718
README.md
1819
src/**/*.lagda.md

plutus-metatheory/src/Certifier.hs

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import Control.Monad
1313
import Control.Monad.Except (ExceptT (..), runExceptT, throwError)
1414
import Control.Monad.IO.Class (liftIO)
1515
import Data.Foldable
16+
import Data.List.Extra (replace)
1617
import Data.List.NonEmpty (NonEmpty (..))
1718
import Data.List.NonEmpty qualified as NE
1819
import Data.Maybe (fromMaybe)
1920
import Data.Text.IO qualified as T
21+
import Paths_plutus_metatheory (getDataFileName)
2022
import System.Directory (createDirectory)
21-
import System.FilePath ((</>))
23+
import System.FilePath (takeBaseName, (</>))
2224

2325
import FFI.AgdaUnparse (AgdaUnparse (..))
2426
import 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

320321
mkAgdaLib :: String -> (FilePath, String)
@@ -329,50 +330,6 @@ mkAgdaLib name =
329330
\\nflags: --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-
376333
mkAgdaCertificateProject
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

387343
writeCertificateProject
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

Comments
 (0)