From 37fe45cd514af77bb83d5dcc84a59a692a101054 Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Tue, 12 Nov 2024 11:06:34 +0100 Subject: [PATCH 1/2] let `AutoDoc` return GAPDoc info messages --- gap/Magic.gd | 9 +++++++-- gap/Magic.gi | 21 ++++++++++++++++++--- makedoc.g | 12 +++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/gap/Magic.gd b/gap/Magic.gd index e3366b26..1009951e 100644 --- a/gap/Magic.gd +++ b/gap/Magic.gd @@ -265,6 +265,11 @@ #! In all other cases (in particular if opt.gapdoc is #! false), this feature is disabled. #!

+#! If &GAPDoc; is invoked by then the returned +#! record has a component GAPDoc_Info, whose value is the +#! string obtained from collecting the info messages printed by +#! the &GAPDoc; functions. +#!

#! #! If opt.gapdoc is a record, it may contain the following entries. #! @@ -395,12 +400,12 @@ #! #! #! -#! @Returns nothing +#! @Returns a record #! @Arguments [packageOrDirectory], [optrec] DeclareGlobalFunction( "AutoDoc" ); #! @Section Examples #! -#! Some basic examples for using AutoDoc were already shown in +#! Some basic examples for using were already shown in #! Chapter . diff --git a/gap/Magic.gi b/gap/Magic.gi index 0bec8500..34d11af2 100644 --- a/gap/Magic.gi +++ b/gap/Magic.gi @@ -73,7 +73,8 @@ function( arg ) pkgdirstr, docdirstr, title_page, tree, is_worksheet, position_document_class, - args; + args, + outputstring, outputstream; if Length( arg ) >= 3 then Error( "too many arguments" ); @@ -589,8 +590,18 @@ function( arg ) Add( args, "nopdf" ); fi; - # Finally, invoke GAPDoc + # Finally, invoke GAPDoc (and collect info messages) + outputstring := ""; + outputstream := OutputTextString( outputstring, true ); + SetPrintFormattingStatus( outputstream, false ); + SetInfoOutput( InfoGAPDoc, outputstream ); + SetInfoOutput( InfoWarning, outputstream ); CallFuncList( MakeGAPDocDoc, args ); + CloseStream( outputstream ); + UnbindInfoOutput( InfoGAPDoc ); + UnbindInfoOutput( InfoWarning ); + Print( outputstring ); + outputstring := ReplacedString( outputstring, "\c", "" ); # NOTE: We cannot just write CopyHTMLStyleFiles(doc_dir) here, as # CopyHTMLStyleFiles its argument directly to Directory(), leading @@ -665,5 +676,9 @@ function( arg ) AUTODOC_ExtractMyManualExamples( pkgname, pkgdir, doc_dir, gapdoc.main, gapdoc.files, extract_examples ); fi; - return true; + if IsBound( outputstring ) then + return rec( GAPDoc_Info := outputstring ); + else + return rec(); + fi; end ); diff --git a/makedoc.g b/makedoc.g index 91d7454d..f0676bec 100644 --- a/makedoc.g +++ b/makedoc.g @@ -7,7 +7,7 @@ LoadPackage("AutoDoc"); -AutoDoc( rec( +res:= AutoDoc( rec( autodoc := true, gapdoc := rec( LaTeXOptions := rec( EarlyExtraPreamble := """ @@ -21,3 +21,13 @@ AutoDoc( rec( bib := "bib.xml", ) )); + +errors:= Filtered(SplitString( res.GAPDoc_Info, "\n"), + x -> StartsWith(x, "#W ") and x <> "#W There are overfull boxes:"); +if Length( errors ) = 0 then + QuitGap( true ); +else + Print( errors, "\n" ); + QuitGap( false ); +fi; +QUIT; From 3426245246c20444bcf569e26c399a26bdc6b65b Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Mon, 18 Nov 2024 14:30:26 +0100 Subject: [PATCH 2/2] make tests happy, change the strategy Just set an exit value in `AutoDoc` in case of failure, do not change the output vaue of `AutoDoc`, undo the proposed changes in `makedoc.g` and in the documentation. (In particular, do not call `QUIT` or `QuitGap` in `makedoc.g`, since this file gets read inside a testfile.) --- gap/Magic.gd | 7 +------ gap/Magic.gi | 10 +++++++--- makedoc.g | 12 +----------- tst/manual.expected/_Chapter_AutoDoc.xml | 2 +- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/gap/Magic.gd b/gap/Magic.gd index 1009951e..b6b9e834 100644 --- a/gap/Magic.gd +++ b/gap/Magic.gd @@ -265,11 +265,6 @@ #! In all other cases (in particular if opt.gapdoc is #! false), this feature is disabled. #!

-#! If &GAPDoc; is invoked by then the returned -#! record has a component GAPDoc_Info, whose value is the -#! string obtained from collecting the info messages printed by -#! the &GAPDoc; functions. -#!

#! #! If opt.gapdoc is a record, it may contain the following entries. #! @@ -400,7 +395,7 @@ #! #! #! -#! @Returns a record +#! @Returns nothing #! @Arguments [packageOrDirectory], [optrec] DeclareGlobalFunction( "AutoDoc" ); diff --git a/gap/Magic.gi b/gap/Magic.gi index 34d11af2..013bf93c 100644 --- a/gap/Magic.gi +++ b/gap/Magic.gi @@ -677,8 +677,12 @@ function( arg ) fi; if IsBound( outputstring ) then - return rec( GAPDoc_Info := outputstring ); - else - return rec(); + # If wanted then set an exit code for GAP. + if Number( SplitString( outputstring, "\n" ), + x -> StartsWith( x, "#W " ) and not + StartsWith( x, "#W There are overfull boxes" ) ) > 0 then + GapExitCode( false ); + fi; fi; + return true; end ); diff --git a/makedoc.g b/makedoc.g index f0676bec..e1742cf9 100644 --- a/makedoc.g +++ b/makedoc.g @@ -7,7 +7,7 @@ LoadPackage("AutoDoc"); -res:= AutoDoc( rec( +AutoDoc( rec( autodoc := true, gapdoc := rec( LaTeXOptions := rec( EarlyExtraPreamble := """ @@ -21,13 +21,3 @@ res:= AutoDoc( rec( bib := "bib.xml", ) )); - -errors:= Filtered(SplitString( res.GAPDoc_Info, "\n"), - x -> StartsWith(x, "#W ") and x <> "#W There are overfull boxes:"); -if Length( errors ) = 0 then - QuitGap( true ); -else - Print( errors, "\n" ); - QuitGap( false ); -fi; -QUIT; diff --git a/tst/manual.expected/_Chapter_AutoDoc.xml b/tst/manual.expected/_Chapter_AutoDoc.xml index 52d46698..d0a83c35 100644 --- a/tst/manual.expected/_Chapter_AutoDoc.xml +++ b/tst/manual.expected/_Chapter_AutoDoc.xml @@ -364,7 +364,7 @@ Examples

- Some basic examples for using AutoDoc were already shown in + Some basic examples for using were already shown in Chapter .