From 2186632d3866348e5a1c1732bfdd80b6c3315ebb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 5 Oct 2021 09:56:03 +0200 Subject: Redo CLI compilation using ad hoc recipes/rules --- repositories.manifest | 4 + xsd/build/root.build | 13 ++- xsd/doc/buildfile | 235 ++++++++++++++++++++++++++------------------------ xsd/manifest | 3 +- xsd/xsd/buildfile | 80 +++++++++-------- 5 files changed, 176 insertions(+), 159 deletions(-) diff --git a/repositories.manifest b/repositories.manifest index 5dd16c3..0a75293 100644 --- a/repositories.manifest +++ b/repositories.manifest @@ -20,3 +20,7 @@ location: https://git.codesynthesis.com/libcutl/libcutl.git##HEAD : role: prerequisite location: https://git.codesynthesis.com/libxsd-frontend/libxsd-frontend.git##HEAD + +: +role: prerequisite +location: https://git.codesynthesis.com/cli/cli.git##HEAD diff --git a/xsd/build/root.build b/xsd/build/root.build index ace0237..4407c3e 100644 --- a/xsd/build/root.build +++ b/xsd/build/root.build @@ -1,6 +1,11 @@ # file : build/root.build # license : GNU GPL v2 + exceptions; see accompanying LICENSE file +config [bool] config.xsd.develop ?= false + +define cli: file +cli{*}: extension = cli + using in cxx.std = latest @@ -20,14 +25,6 @@ if ($cxx.class == 'msvc') cxx.poptions =+ "-I$out_root" "-I$src_root" -# Load the cli module but only if it's available. This way a distribution -# that includes pre-generated files can be built without installing cli. -# This is also the reason why we need to explicitly spell out individual -# source file prerequisites instead of using the cli.cxx{} group (it won't -# be there unless the module is configured). -# -using? cli - # Extract the copyright notice from the LICENSE file. # # Note that cat is a builtin which means this is both portable and fast. diff --git a/xsd/doc/buildfile b/xsd/doc/buildfile index ccfc060..b15831a 100644 --- a/xsd/doc/buildfile +++ b/xsd/doc/buildfile @@ -25,7 +25,7 @@ png{*}: extension = png define svg: file svg{*}: extension = svg -import? [metadata] cli = cli%exe{cli} +import! [metadata] cli = cli%exe{cli} # Import the html2ps and ps2pdf14 programs only if present on the system. This # way a distribution that includes pre-generated files can be built without @@ -34,99 +34,103 @@ import? [metadata] cli = cli%exe{cli} import? html2ps = html2ps%exe{html2ps} import? ps2pdf14 = ps2pdf14%exe{ps2pdf14} +if $config.xsd.develop +{ + if ($html2ps == [null] || $ps2pdf14 == [null]) + warn "html2ps and/or ps2pdf14 are not available, not generating .ps and .pdf documentation" +} + ./: xsd{custom-literals} -# Note that we include the cli, html2ps, and ps2pdf14 generated files into the -# distribution and don't remove them when cleaning in src (so that clean -# results in a state identical to distributed). +# Generate the man pages. +# +ops = $(src_root)/xsd/cxx/cli{options tree/options parser/options} + +doc_version = [string] "$version.major\.$version.minor\.$version.patch" +if $version.pre_release + doc_version += "-$version.pre_release_string" -# Generate the man pages if the cli program is available and handle (install, -# distribute, etc) the pre-generated files otherwise, if present. +# Let's take the last for-digit number to cover 2000-2021,2022. # -if ($cli != [null]) -{ - ./: {man1 xhtml}{xsd} - - man_topics = $(src_root)/xsd/cxx/cli{options tree/options parser/options} - - man_options = -v project="XSD" \ - -v version="$version.project_id" \ - -v copyright="$copyright" \ - -I $src_root \ - --stdout \ - --suppress-undocumented \ - --exclude-base - - man1{xsd}: $man_topics \ - man1{xsd-prologue \ - xsd-tree-header \ - xsd-parser-header \ - xsd-epilogue} \ - $cli - { - dist = true - clean = ($src_root != $out_root) - } - {{ - diag cli $> : ($<[0]) # @@ TMP: revise +doc_year = $regex.replace($copyright, '.+[-, ]([0-9][0-9][0-9][0-9]) .+', '\1') - # Note that the date change doesn't change the script semantics, thus the - # variable is defined locally. - # - date +"%B %Y" | set date - - $cli --generate-man -v date="$date" $man_options \ - --class CXX::options \ - --class options \ - --man-prologue-file $path($<[3]) \ - $path($<[0]) >$path($>) - - $cli --generate-man -v date="$date" $man_options \ - --man-prologue-file $path($<[4]) \ - $path($<[1]) >>$path($>) - - $cli --generate-man -v date="$date" $man_options \ - --man-prologue-file $path($<[5]) \ - --man-epilogue-file $path($<[6]) \ - $path($<[2]) >>$path($>) - }} - - xhtml{xsd}: $man_topics \ - xhtml{xsd-prologue \ - xsd-tree-header \ - xsd-parser-header \ - xsd-epilogue} \ - css{*} \ - $cli - { - dist = true - clean = ($src_root != $out_root) - } - {{ - diag cli $> : ($<[0]) # @@ TMP: revise - - date +"%B %Y" | set date - - $cli --generate-html -v date="$date" $man_options \ - --class CXX::options \ - --class options \ - --html-prologue-file $path($<[3]) \ - $path($<[0]) >$path($>) - - $cli --generate-html -v date="$date" $man_options \ - --html-prologue-file $path($<[4]) \ - $path($<[1]) >>$path($>) - - $cli --generate-html -v date="$date" $man_options \ - --html-prologue-file $path($<[5]) \ - --html-epilogue-file $path($<[6]) \ - $path($<[2]) >>$path($>) - }} +man_options = -v project="XSD" \ + -v version="$doc_version" \ + -v copyright="$copyright" \ + -I $src_root \ + --stdout \ + --suppress-undocumented \ + --exclude-base + + +# Note: *logue and *-header are not real man pages. +# +./: man1{xsd}: $ops \ + file{xsd-prologue.1 \ + xsd-tree-header.1 \ + xsd-parser-header.1 \ + xsd-epilogue.1} \ + $cli +{ + dist = true # Include into the distribution for user's convenience. } -else - # Distribute both the pre-generated file (if present) and the sources. +{{ + diag cli --man ($<[0]) + + # Use the copyright year to approximate the last authoring date. # - ./: {man1 xhtml}{+xsd xsd-*} css{*} + $cli --generate-man -v date="January $doc_year" \ + $man_options \ + --class CXX::options \ + --class options \ + --man-prologue-file $path($<[3]) \ + $path($<[0]) >$path($>) + + $cli --generate-man -v date="January $doc_year" \ + $man_options \ + --man-prologue-file $path($<[4]) \ + $path($<[1]) >>$path($>) + + $cli --generate-man -v date="January $doc_year" \ + $man_options \ + --man-prologue-file $path($<[5]) \ + --man-epilogue-file $path($<[6]) \ + $path($<[2]) >>$path($>) +}} + +# Note: *logue and *-header are not real xhtml files. +# +./: xhtml{xsd}: $ops \ + file{xsd-prologue.xhtml \ + xsd-tree-header.xhtml \ + xsd-parser-header.xhtml \ + xsd-epilogue.xhtml} \ + css{*} \ + $cli +{ + dist = true +} +{{ + diag cli --html ($<[0]) + + $cli --generate-html -v date="January $doc_year" \ + $man_options \ + --class CXX::options \ + --class options \ + --html-prologue-file $path($<[3]) \ + $path($<[0]) >$path($>) + + $cli --generate-html -v date="January $doc_year" \ + $man_options \ + --html-prologue-file $path($<[4]) \ + $path($<[1]) >>$path($>) + + $cli --generate-html -v date="January $doc_year" \ + $man_options \ + --html-prologue-file $path($<[5]) \ + --html-epilogue-file $path($<[6]) \ + $path($<[2]) >>$path($>) +}} # Generate the user guide/manual ps/pdf files if the html2ps and ps2pdf14 # programs are imported and handle (install, distribute, etc) the @@ -138,50 +142,55 @@ for d: cxx/parser/guide/ cxx/tree/guide/ cxx/tree/manual/ l = "([dir_path] $path.leaf($d))" # guide, manual f = "cxx-$p-$l" # cxx-parser-guide, etc - ./: $d/xhtml{index}: $d/{png svg}{*} + ./: $d/{png svg}{*} - $d/xhtml{index}: $d/in{index} + ./: $d/xhtml{index}: $d/in{index} { in.symbol = '@' + + dist = true + clean = ($src_root != $out_root) } - if ($html2ps != [null]) + if ($html2ps != [null] && $ps2pdf14 != [null]) { + # Note that we include these generated files into the distribution and + # don't remove them when cleaning in src (so that clean results in a state + # identical to distributed). + # ./: $d/ps{$f}: $d/xhtml{index} $d/html2ps{$l} $html2ps { + base = $src_base/$d + + dist = true + clean = ($src_root != $out_root) + } + {{ + diag html2ps ($<[0]) + + # Note: --base must include trailing directory separator. + # + $html2ps --base $base -f $path($<[1]) -o $path($>) $path($<[0]) + }} + + ./: $d/pdf{$f}: $d/ps{$f} $ps2pdf14 + { dist = true clean = ($src_root != $out_root) } {{ - diag html2ps $> : ($<[0]) # @@ TMP: revise + diag ps2pdf14 ($<[0]) - $html2ps -f $path($<[1]) -o $path($>) $path($<[0]) + $ps2pdf14 -dOptimize=true -dEmbedAllFonts=true $path($<[0]) $path($>) }} - if ($ps2pdf14 != [null]) + $d/html2ps{$l}: $d/in{$l} { - ./: $d/pdf{$f}: $d/ps{$f} $ps2pdf14 - { - dist = true - clean = ($src_root != $out_root) - } - {{ - diag ps2pdf14 $> : ($<[0]) # @@ TMP: revise - - $ps2pdf14 -dOptimize=true -dEmbedAllFonts=true $path($<[0]) $path($>) - }} + in.symbol = '@' } - else - ./: $d/pdf{+$f} } else - ./: $d/{ps pdf}{+$f} $d/html2ps{$l} - - $d/html2ps{$l}: $d/in{$l} - { - in.symbol = '@' - } + ./: $d/{ps pdf}{+$f} $d/file{$l.html2ps.in} } -{man1 xhtml}{xsd-*}: install = false # xsd-prologue, etc -doc{*}: install.subdirs = true +doc{*}: install.subdirs = true diff --git a/xsd/manifest b/xsd/manifest index d256d9b..fcbadbe 100644 --- a/xsd/manifest +++ b/xsd/manifest @@ -15,10 +15,9 @@ requires: host requires: c++11 depends: * build2 >= 0.14.0- depends: * bpkg >= 0.14.0- -# @@ Should probably become conditional dependency. -requires: ? cli ; Only required if changing .cli files. depends: libxsd-frontend ^2.1.0- depends: libcutl ^1.11.0- depends: libxerces-c ^3.0.0 +depends: * cli ^1.2.0- tests: * xsd-tests == $ examples: * xsd-examples == $ diff --git a/xsd/xsd/buildfile b/xsd/xsd/buildfile index 49fbf2c..2b356b6 100644 --- a/xsd/xsd/buildfile +++ b/xsd/xsd/buildfile @@ -5,11 +5,13 @@ import libs = libxsd-frontend%lib{xsd-frontend} import libs += libcutl%lib{cutl} import libs += libxerces-c%lib{xerces-c} -options_topics = options cxx/options cxx/parser/options cxx/tree/options +import! [metadata] cli = cli%exe{cli} -./: exe{xsd}: {hxx ixx txx cxx}{** -{$options_topics} -version} \ - {hxx ixx cxx}{$options_topics} \ - {hxx}{version} \ +ops = options cxx/options cxx/parser/options cxx/tree/options + +./: exe{xsd}: {hxx ixx txx cxx}{** -{$ops} -version} \ + {hxx ixx cxx}{$ops} \ + {hxx}{version} \ $libs # Target metadata, see also --build2-metadata in xsd.cxx. @@ -24,45 +26,51 @@ exe{xsd}: hxx{version}: in{version} $src_root/manifest -# Build options. +# Generated options parser. # -# Pass the copyright notice extracted from the LICENSE file. +# Note: tracking .cli dependencies manually. # -obj{xsd cxx/parser/generator cxx/tree/generator}: \ - cxx.poptions += -DXSD_COPYRIGHT=\"$copyright\" +cli_options = --std c++11 -I $src_root --generate-specifier \ +--generate-file-scanner --suppress-undocumented \ +--ostream-type ::std::wostream --exclude-base \ +--include-with-brackets --option-length 28 \ +--cxx-prologue '"#include "' # TMP: WTF? -# Generated options parser. -# -if $cli.configured +<{hxx ixx cxx}{options}>: cli{options} { - cli.cxx{options}: cli{options} - cxx/cli.cxx{options}: cxx/cli{options} - cxx/parser/cli.cxx{options}: cxx/parser/cli{options} - cxx/tree/cli.cxx{options}: cxx/tree/cli{options} - - cli.options += --std c++11 -I $src_root --generate-specifier \ ---ostream-type ::std::wostream --exclude-base --suppress-undocumented \ ---generate-file-scanner --include-with-brackets --option-length 28 \ ---cxx-prologue '#include ' - - cli.cxx{options}: cli.options += --include-prefix xsd --guard-prefix XSD + cli_options += --include-prefix xsd --guard-prefix XSD +} - cxx/cli.cxx{options}: cli.options += --include-prefix xsd/cxx \ - --guard-prefix XSD_CXX +: cxx/cli{options} cli{options} +{ + cli_options += --include-prefix xsd/cxx --guard-prefix XSD_CXX +} - cxx/parser/cli.cxx{options}: cli.options += --include-prefix xsd/cxx/parser \ - --guard-prefix XSD_CXX_PARSER +: cxx/parser/cli{options} cxx/cli{options} \ + cli{options} +{ + cli_options += --include-prefix xsd/cxx/parser --guard-prefix XSD_CXX_PARSER +} - cxx/tree/cli.cxx{options}: cli.options += --include-prefix xsd/cxx/tree \ - --guard-prefix XSD_CXX_TREE +: cxx/tree/cli{options} cxx/cli{options} \ + cli{options} +{ + cli_options += --include-prefix xsd/cxx/tree --guard-prefix XSD_CXX_TREE +} - # Include the generated cli files into the distribution and don't remove - # them when cleaning in src (so that clean results in a state identical to - # distributed). +: cli{~'/\1/'} $cli +{ + # Symlink the generated code in src for convenience of development. # - cli.cxx{*}: - { - dist = true - clean = ($src_root != $out_root) - } + backlink = true } +{{ + $cli $cli_options -o $directory($path($>[0])) $path($<[0]) +}} + +# Build options. +# +# Pass the copyright notice extracted from the LICENSE file. +# +obj{xsd cxx/parser/generator cxx/tree/generator}: \ + cxx.poptions += -DXSD_COPYRIGHT=\"$copyright\" -- cgit v1.1