Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
outputconfiguration.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6#include "config.h"
7
8#include <QtCore/qdir.h>
9#include <QtCore/qregularexpression.h>
10
11#include <optional>
12
13QT_BEGIN_NAMESPACE
14
15using namespace Qt::StringLiterals;
16
17/*!
18 \enum Pipeline
19 \internal
20 \inmodule QDoc
21 \relates OutputSelection
22 \brief Identifies an implementation that can own publication formats.
23
24 Format identity is independent of the implementation that renders it.
25 Selecting a pipeline does not require it to own any document format.
26
27 \value Legacy The compiled-in legacy generators.
28 \value Template The template engine with its effective package capabilities.
29*/
30
31/*!
32 \struct PipelineCapabilities
33 \internal
34 \inmodule QDoc
35 \brief Describes a pipeline without constructing generators or loading packages.
36
37 The caller supplies compiled-in legacy capabilities or the effective
38 template package's capabilities. Resolution reads these values without
39 retaining references to them. An unavailable selected pipeline is an error.
40
41 A declared but broken format remains an ownership claim even when it is
42 absent from \c{supportedFormats}. A broken template declaration therefore
43 prevents fallback to legacy. Extensions supply defaults only; they do not
44 determine format identity, ownership, or template selection.
45*/
46
47/*!
48 \variable PipelineCapabilities::pipeline
49 \brief The pipeline whose capabilities this record describes.
50*/
51
52/*!
53 \variable PipelineCapabilities::available
54 \brief Whether this pipeline can run in the invoking build and environment.
55
56 Set this to \c false for a compiled-out engine or an unusable package.
57*/
58
59/*!
60 \variable PipelineCapabilities::supportedFormats
61 \brief The case-sensitive format identities this pipeline can render.
62*/
63
64/*!
65 \variable PipelineCapabilities::brokenFormats
66 \brief The declared formats whose requirements the pipeline cannot satisfy.
67
68 These identities need not also appear in \c{supportedFormats}. A requested
69 broken declaration is an error, not permission to choose another owner.
70*/
71
72/*!
73 \variable PipelineCapabilities::formatExtensions
74 \brief The pipeline or effective-package extension defaults, keyed by format.
75
76 Resolution applies an explicit \c{<Format>.extension} override. Each
77 requested format needs a non-empty effective extension; unfamiliar formats
78 do not inherit another format's extension.
79*/
80
81/*!
82 \struct OutputConfigurationInput
83 \internal
84 \inmodule QDoc
85 \brief Supplies invocation-specific selections and pipeline capabilities.
86
87 The caller supplies command-line values in their original order. A
88 non-empty list replaces the corresponding configuration selection; it is
89 not additive. Represent an explicit empty argument with an empty string,
90 rather than an absent list. These inputs do not expose a public option or
91 invoke package loading.
92*/
93
94/*!
95 \variable OutputConfigurationInput::cliPipelines
96 \brief The ordered command-line pipeline selection, or an empty list if absent.
97*/
98
99/*!
100 \variable OutputConfigurationInput::cliFormats
101 \brief The ordered command-line format selection, or an empty list if absent.
102
103 This selection may introduce formats absent from the configuration.
104*/
105
106/*!
107 \variable OutputConfigurationInput::pipelineCapabilities
108 \brief The capability records for pipelines known to the caller.
109
110 Supply one effective record per pipeline. Absence of a selected pipeline's
111 record is an error, as is a record whose \c{available} value is false.
112*/
113
114/*!
115 \struct OutputSelection
116 \internal
117 \inmodule QDoc
118 \brief Resolves format requests and ownership independently of destination layout.
119
120 Explicit pipeline presence in a configuration file or include, or an
121 explicit command-line selection, opts in to the new publication model.
122 Without either, the result is a compatibility marker; existing runtime
123 interpretation retains control.
124
125 The result retains the full configured format order, followed by CLI-only
126 identities. Repeated identities keep their first occurrence. Identity
127 tokens are trimmed and empty tokens are discarded; path values do not use
128 this normalization. Requested flags record CLI replacement without losing
129 configured positions needed by subsequent layout planning.
130
131 Template owns its declared formats before legacy, independently of pipeline
132 order. Ownership and extension values are usable for requested formats only
133 in New mode when hasErrors() returns \c false. Non-requested entries retain
134 configured identity and position without requiring a usable owner.
135
136 Resolution never creates output, constructs generators, loads packages, or
137 emits diagnostics. The caller handles errors before publication and emits
138 migration notices outside the authored-documentation warning budget.
139*/
140
141/*!
142 \enum OutputSelection::Mode
143 \internal
144 \brief Identifies which configuration interpretation controls publication.
145
146 \value Compatibility No explicit pipeline selection; use existing runtime behavior.
147 \value New Explicit pipeline selection; use the resolved publication model.
148*/
149
150/*!
151 \struct OutputSelection::Diagnostic
152 \internal
153 \inmodule QDoc
154 \brief Carries a source-positioned publication diagnostic without emitting it.
155
156 Resolution deduplicates equal severity, file, line, message, and details.
157 The caller owns presentation and failure handling; this record does not
158 increment QDoc's warning or error counters.
159*/
160
161/*!
162 \enum OutputSelection::Diagnostic::Kind
163 \internal
164 \brief Distinguishes blocking errors from migration advice.
165
166 \value Error The configuration cannot be published as resolved.
167 \value Notice Migration advice, not an authored-documentation warning.
168*/
169
170/*!
171 \variable OutputSelection::Diagnostic::kind
172 \brief The diagnostic's effect on publication validity.
173*/
174
175/*!
176 \variable OutputSelection::Diagnostic::location
177 \brief The responsible configuration declaration, if known.
178
179 CLI-only and programmatic selections can have an empty location.
180*/
181
182/*!
183 \variable OutputSelection::Diagnostic::message
184 \brief The primary explanation of the configuration problem or migration advice.
185*/
186
187/*!
188 \variable OutputSelection::Diagnostic::details
189 \brief Optional context to accompany the primary message.
190*/
191
192/*!
193 \struct OutputSelection::Format
194 \internal
195 \inmodule QDoc
196 \brief Records a format's identity, request status, owner, and extension.
197
198 A configured but unrequested entry remains in the result to preserve layout
199 assignment. Consumers must not mistake it for an additional publication.
200*/
201
202/*!
203 \variable OutputSelection::Format::format
204 \brief The case-sensitive permanent publication identity.
205*/
206
207/*!
208 \variable OutputSelection::Format::requested
209 \brief Whether the effective invocation requests this format.
210*/
211
212/*!
213 \variable OutputSelection::Format::configured
214 \brief Whether the identity occurs in the configured format list, including defaults.
215*/
216
217/*!
218 \variable OutputSelection::Format::pipeline
219 \brief The selected owner, usable only for a valid requested format in New mode.
220*/
221
222/*!
223 \variable OutputSelection::Format::fileExtension
224 \brief The effective extension without an automatically added separator.
225
226 The caller combines this value with the document name. It does not select
227 templates or imply a publication destination.
228*/
229
230/*!
231 \variable OutputSelection::Format::location
232 \brief The format-list declaration from which this entry derives.
233
234 This is empty for a CLI-only identity or a programmatic declaration without
235 source provenance.
236*/
237
238/*!
239 \variable OutputSelection::mode
240 \brief The configuration interpretation selected for this invocation.
241*/
242
243/*!
244 \variable OutputSelection::pipelines
245 \brief The available enabled pipelines in selection order, without duplicates.
246
247 This order does not determine format ownership. An unavailable selection
248 contributes an error rather than an entry in this list.
249*/
250
251/*!
252 \variable OutputSelection::formats
253 \brief The configured formats followed by CLI-only formats, in first-occurrence order.
254*/
255
256/*!
257 \variable OutputSelection::diagnostics
258 \brief The deduplicated errors and notices collected during resolution.
259*/
260
261namespace {
262
263using Diagnostic = OutputSelection::Diagnostic;
264
265QString pipelineName(Pipeline pipeline)
266{
267 return pipeline == Pipeline::Legacy ? u"legacy"_s : u"template"_s;
268}
269
270std::optional<Pipeline> pipelineFromName(const QString &name)
271{
272 if (name == "legacy"_L1)
273 return Pipeline::Legacy;
274 if (name == "template"_L1)
275 return Pipeline::Template;
276 return std::nullopt;
277}
278
279QString configKey(const QString &format, const QString &suffix)
280{
281 return format + Config::dot + suffix;
282}
283
284QStringList filterIdentityTokens(const QStringList &values)
285{
286 QStringList result;
287 for (const QString &value : values) {
288 const QString trimmed = value.trimmed();
289 if (!trimmed.isEmpty() && !result.contains(trimmed))
290 result.append(trimmed);
291 }
292 return result;
293}
294
295bool isValidModuleDir(const QString &project)
296{
297 static const QRegularExpression unsafe(uR"([/\<>:"|?*\x00-\x1F])"_s);
298 return !project.isEmpty() && project != "."_L1 && project != ".."_L1
299 && project == project.trimmed() && !project.endsWith(u'.')
300 && !unsafe.match(project).hasMatch();
301}
302
303std::optional<PublicationLayout> parsePublicationLayout(const QString &value)
304{
305 if (value == "flat"_L1)
307 if (value == "per-module"_L1)
309 return std::nullopt;
310}
311
312QString joinPath(const QString &base, const QString &sub)
313{
314 if (sub.isEmpty())
315 return base.isEmpty() ? u"."_s : QDir::cleanPath(base);
316 if (base.isEmpty())
317 return QDir::cleanPath(sub);
318 return QDir::cleanPath(base + u'/' + sub);
319}
320
321class DiagnosticReporter
322{
323public:
324 explicit DiagnosticReporter(QVector<Diagnostic> &diagnostics) : m_diagnostics(diagnostics)
325 {
326 for (const auto &diagnostic : diagnostics)
327 m_seen.insert(key(diagnostic));
328 }
329
330 void add(Diagnostic::Kind kind, const Location &location, QString message,
331 QString details = {})
332 {
333 Diagnostic diagnostic{kind, location, std::move(message), std::move(details)};
334 const QString identity = key(diagnostic);
335 if (m_seen.contains(identity))
336 return;
337 m_seen.insert(identity);
338 m_diagnostics.push_back(std::move(diagnostic));
339 }
340
341private:
342 static QString key(const Diagnostic &diagnostic)
343 {
344 return QString::number(static_cast<int>(diagnostic.kind)) + u'\0'
345 + diagnostic.location.filePath() + u'\0'
346 + QString::number(diagnostic.location.lineNo()) + u'\0'
347 + diagnostic.message + u'\0' + diagnostic.details;
348 }
349
350 QVector<Diagnostic> &m_diagnostics;
351 QSet<QString> m_seen;
352};
353
354} // namespace
355
356/*!
357 Resolves publication requests from \a config and the explicit \a input.
358
359 Returns diagnostics as data and leaves both inputs unchanged. Compatibility
360 mode returns no format plan but can carry notices for new-only settings
361 without explicit pipeline opt-in. In New mode, errors invalidate the result;
362 callers must check hasErrors() before using requested owners or extensions.
363*/
365 const OutputConfigurationInput &input)
366{
367 OutputSelection result;
368 DiagnosticReporter reporter(result.diagnostics);
369 const bool cliPipelines = !input.cliPipelines.isEmpty();
370 if (!cliPipelines && !config.contains(CONFIG_PIPELINE)) {
371 const auto flagNewOnlySetting = [&](const QString &var) {
372 reporter.add(Diagnostic::Kind::Notice, config.get(var).location(),
373 "New publication setting '%1' has no effect without an explicit "
374 "'pipeline' selection."_L1.arg(var));
375 };
376 if (config.contains(CONFIG_PUBLICATIONLAYOUT))
377 flagNewOnlySetting(CONFIG_PUBLICATIONLAYOUT);
378 if (config.contains(CONFIG_TEMPLATEPACKAGE))
379 flagNewOnlySetting(CONFIG_TEMPLATEPACKAGE);
380 for (const QString &key : config.variableNames()) {
381 if (key.endsWith(Config::dot + CONFIG_PUBLICATIONLAYOUT))
382 flagNewOnlySetting(key);
383 }
384 return result;
385 }
386 result.mode = Mode::New;
387
388 const PipelineCapabilities *legacy = nullptr;
389 const PipelineCapabilities *templated = nullptr;
390 for (const auto &capability : input.pipelineCapabilities) {
391 if (capability.pipeline == Pipeline::Legacy)
392 legacy = &capability;
393 else
394 templated = &capability;
395 }
396
397 const auto &pipelineVar = config.get(CONFIG_PIPELINE);
398 const Location pipelineSource = cliPipelines ? Location() : pipelineVar.location();
399 const auto selected = filterIdentityTokens(cliPipelines ? input.cliPipelines
400 : pipelineVar.asStringList());
401 if (selected.isEmpty())
402 reporter.add(Diagnostic::Kind::Error, pipelineSource, u"Pipeline selection is empty."_s,
403 u"Select at least one pipeline in the configuration or on the command line."_s);
404 for (const QString &name : selected) {
405 const auto pipeline = pipelineFromName(name);
406 if (!pipeline) {
407 reporter.add(Diagnostic::Kind::Error, pipelineSource,
408 "Pipeline '%1' is not recognized."_L1.arg(name),
409 u"QDoc supports the 'legacy' and 'template' pipelines."_s);
410 continue;
411 }
412 const auto *capability = *pipeline == Pipeline::Legacy ? legacy : templated;
413 if (!capability || !capability->available) {
414 reporter.add(Diagnostic::Kind::Error, pipelineSource,
415 "Pipeline '%1' is unavailable."_L1.arg(name));
416 continue;
417 }
418 result.pipelines.push_back(*pipeline);
419 }
420
421 const auto &formatsVar = config.get(CONFIG_OUTPUTFORMATS);
422 const auto configured = filterIdentityTokens(formatsVar.asStringList());
423 const auto requested = input.cliFormats.isEmpty() ? configured
424 : filterIdentityTokens(input.cliFormats);
425 if (requested.isEmpty())
426 reporter.add(Diagnostic::Kind::Error,
427 input.cliFormats.isEmpty() ? formatsVar.location() : Location(),
428 u"Format selection is empty."_s,
429 u"Select at least one output format in the configuration or on the command line."_s);
430
431 const QSet<QString> requestedSet(requested.cbegin(), requested.cend());
432 const bool templateEnabled = result.pipelines.contains(Pipeline::Template);
433 const bool legacyEnabled = result.pipelines.contains(Pipeline::Legacy);
434 const auto declares = [](const PipelineCapabilities *capability, const QString &format) {
435 return capability && (capability->supportedFormats.contains(format)
436 || capability->brokenFormats.contains(format));
437 };
438 const auto addFormat = [&](const QString &format, const Location &location, bool configured) {
439 Format entry;
440 entry.format = format;
441 entry.requested = requestedSet.contains(format);
442 entry.configured = configured;
443 entry.location = location;
444 if (!isValidFormatIdentity(format)) {
445 reporter.add(Diagnostic::Kind::Error, location,
446 "Invalid format identity '%1'."_L1.arg(format),
447 u"Format names may contain letters, digits, and underscores only."_s);
448 }
449
450 const PipelineCapabilities *owner = nullptr;
451 if (templateEnabled && declares(templated, format))
452 owner = templated;
453 else if (legacyEnabled && declares(legacy, format))
454 owner = legacy;
455
456 if (owner) {
457 entry.pipeline = owner->pipeline;
458 entry.fileExtension = owner->formatExtensions.value(format);
459 if (entry.requested && owner->brokenFormats.contains(format)) {
460 reporter.add(Diagnostic::Kind::Error, location,
461 "Format '%1' is declared by pipeline '%2' but the declaration "
462 "is broken."_L1.arg(format, pipelineName(owner->pipeline)),
463 u"QDoc does not fall back to another pipeline for a broken declaration."_s);
464 } else {
465 const QString extensionKey = configKey(format, u"extension"_s);
466 const auto &extension = config.get(extensionKey);
467 const bool overridden = config.contains(extensionKey);
468 if (overridden) {
469 const auto values = extension.asStringList();
470 entry.fileExtension = values.value(0);
471 if (entry.requested && values.size() > 1)
472 reporter.add(Diagnostic::Kind::Error, extension.location(),
473 "%1 must contain a single value."_L1.arg(extensionKey));
474 }
475 if (entry.requested && entry.fileExtension.isEmpty())
476 reporter.add(Diagnostic::Kind::Error,
477 overridden ? extension.location() : location,
478 "Format '%1' has no file extension."_L1.arg(format),
479 "Provide a pipeline default or a non-empty %1."_L1.arg(extensionKey));
480 }
481 } else if (entry.requested) {
482 QStringList names;
483 for (Pipeline pipeline : result.pipelines)
484 names.append(pipelineName(pipeline));
485 reporter.add(Diagnostic::Kind::Error, location,
486 "Format '%1' is not supported by any selected pipeline."_L1.arg(format),
487 names.isEmpty() ? u"No pipeline is available."_s
488 : "Selected pipelines: %1."_L1.arg(names.join(u", "_s)));
489 }
490 result.formats.push_back(std::move(entry));
491 };
492
493 for (const QString &format : configured)
494 addFormat(format, formatsVar.location(), true);
495 for (const QString &format : requested) {
496 if (!configured.contains(format))
497 addFormat(format, Location(), false);
498 }
499 return result;
500}
501
502/*!
503 Returns \c true if \a format can serve as a publication identity and as a
504 configuration key segment.
505
506 Identities are case-sensitive and consist of letters, digits, and
507 underscores only, so that \c{<Format>.extension} and similar keys parse
508 unambiguously. Template packages apply the same rule to declared formats.
509*/
510bool OutputSelection::isValidFormatIdentity(const QString &format)
511{
512 static const QRegularExpression identity(uR"(^[A-Za-z0-9_]+$)"_s);
513 return identity.match(format).hasMatch();
514}
515
516/*!
517 Returns \c true if any diagnostic blocks publication. Notices alone do not
518 invalidate the selection or consume the documentation warning budget.
519*/
521{
522 for (const auto &diagnostic : diagnostics) {
523 if (diagnostic.kind == Diagnostic::Kind::Error)
524 return true;
525 }
526 return false;
527}
528
529/*!
530 Returns the entry for the case-sensitive identity \a format, or \c{nullptr}
531 if it is absent. The entry may be configured but unrequested.
532
533 The result borrows storage from this selection and is valid only while that
534 storage remains alive and unchanged. Looking up an entry does not validate it.
535*/
536const OutputSelection::Format *OutputSelection::findFormat(const QString &format) const
537{
538 for (const auto &entry : formats) {
539 if (entry.format == format)
540 return &entry;
541 }
542 return nullptr;
543}
544
545/*!
546 \enum PublicationLayout
547 \internal
548 \inmodule QDoc
549 \relates OutputConfiguration
550 \brief Determines whether a format's publication tree has a module directory.
551
552 Layout is independent of execution mode and format directory selection.
553
554 \value Flat Modules can share the format directory. Image and style
555 subdirectories remain possible.
556 \value PerModule Append the lower-case project identity to the format directory.
557*/
558
559/*!
560 \struct OutputConfiguration
561 \internal
562 \inmodule QDoc
563 \brief Adds publication destinations to a resolved output selection.
564
565 Resolution consumes OutputSelection without constructing generators, parsing
566 source, creating output, or emitting diagnostics. Compatibility mode remains
567 a marker for the unchanged legacy interpretation, not a new layout plan.
568
569 The first configured format defaults to the publication root. Later
570 configured formats and CLI-only formats default to lower-case format names.
571 Explicit \c{<Format>.outputsubdir} values apply literally, including empty
572 and \c{../} values. Replacing requested formats or moving the first format
573 does not promote another configured format into the root.
574
575 Layout precedence is \c{<Format>.publicationlayout}, \c{publicationlayout},
576 the explicit deprecated \c{<Format>.nosubdirs} alias, then Flat. The alias
577 maps true to Flat and false, including an empty declaration, to PerModule.
578 Invalid or empty new layout values are errors, not a request to use an
579 inherited alias. PerModule requires a safe module directory component.
580
581 Equal normalized destinations for requested formats are errors; nested
582 trees are allowed. Before writing, consumers must also validate filesystem
583 aliases and case, reserved subtrees, and actual artifact ownership. Lexical
584 planning neither performs those checks nor authorizes filesystem writes.
585*/
586
587/*!
588 \typealias OutputConfiguration::Mode
589 \internal
590 \brief Uses the same interpretation modes as OutputSelection.
591*/
592
593/*!
594 \typealias OutputConfiguration::Diagnostic
595 \internal
596 \brief Uses the same diagnostic data and severity contract as OutputSelection.
597*/
598
599/*!
600 \struct OutputConfiguration::FormatPlan
601 \internal
602 \inmodule QDoc
603 \brief Extends a format selection with its publication directory and layout.
604
605 The inherited request and ownership fields retain their OutputSelection
606 meaning. A non-requested entry preserves configured assignment but is not
607 another publication. Check the containing configuration's errors before
608 using a requested plan.
609*/
610
611/*!
612 \variable OutputConfiguration::FormatPlan::formatDir
613 \brief The literal or default format directory relative to the publication root.
614
615 Empty means the root. Parent components are deliberate, not an instruction
616 to rewrite the destination to remain under the root.
617*/
618
619/*!
620 \variable OutputConfiguration::FormatPlan::formatDirLocation
621 \brief The directory declaration, or the format-list origin for a default directory.
622
623 CLI-only defaults and programmatic declarations can have an empty location.
624*/
625
626/*!
627 \variable OutputConfiguration::FormatPlan::layout
628 \brief The resolved policy for adding a module directory.
629*/
630
631/*!
632 \variable OutputConfiguration::FormatPlan::layoutLocation
633 \brief The effective layout or deprecated-alias declaration, if one applies.
634
635 This is empty for the implicit Flat default or absent source provenance.
636*/
637
638/*!
639 \variable OutputConfiguration::FormatPlan::moduleDir
640 \brief The lower-case project directory for PerModule, or empty for Flat.
641
642 An invalid PerModule identity leaves this empty and produces an error for
643 a requested format. It must not be interpreted as a valid Flat fallback.
644*/
645
646/*!
647 \variable OutputConfiguration::mode
648 \brief The interpretation mode inherited from output selection.
649*/
650
651/*!
652 \variable OutputConfiguration::pipelines
653 \brief The available enabled pipelines inherited from output selection.
654*/
655
656/*!
657 \variable OutputConfiguration::root
658 \brief The publication root before complete-path normalization.
659
660 The invocation's output-directory override wins over configured
661 \c{outputdir}. Empty means the current directory. The override replaces only
662 the root, not the format or module layout.
663*/
664
665/*!
666 \variable OutputConfiguration::formats
667 \brief The configured and CLI-only format plans in selection order.
668
669 Only entries whose inherited \c{requested} value is true claim destinations.
670*/
671
672/*!
673 \variable OutputConfiguration::diagnostics
674 \brief The combined, deduplicated selection and layout diagnostics.
675
676 These records have no emission or warning-budget side effects.
677*/
678
679/*!
680 Resolves selection and destination layout from \a config and \a input.
681
682 Also reads the invocation's output-directory override from Config. Returns
683 a compatibility marker without destinations when the new model is not
684 selected. Errors remain data; the caller must reject an invalid plan before
685 any publication writes.
686*/
688 const OutputConfigurationInput &input)
689{
690 auto selection = OutputSelection::resolve(config, input);
691 OutputConfiguration result;
692 result.mode = selection.mode;
693 result.pipelines = std::move(selection.pipelines);
694 result.diagnostics = std::move(selection.diagnostics);
695 if (result.mode == Mode::Compatibility)
696 return result;
697
698 DiagnosticReporter reporter(result.diagnostics);
699 result.root = Config::overrideOutputDir.isNull() ? config.get(CONFIG_OUTPUTDIR).asString()
700 : Config::overrideOutputDir;
701 const auto &project = config.get(CONFIG_PROJECT);
702 const QString moduleDir = project.asString().toLower();
703 for (qsizetype i = 0; i < selection.formats.size(); ++i) {
704 FormatPlan plan;
705 static_cast<OutputSelection::Format &>(plan) = std::move(selection.formats[i]);
706 const QString subKey = configKey(plan.format, u"outputsubdir"_s);
707 if (config.contains(subKey)) {
708 const auto &sub = config.get(subKey);
709 const auto values = sub.asStringList();
710 if (values.size() > 1)
711 reporter.add(Diagnostic::Kind::Error, sub.location(),
712 "%1 must contain a single value."_L1.arg(subKey),
713 u"Use one path per format."_s);
714 plan.formatDir = values.value(0);
715 plan.formatDirLocation = sub.location();
716 } else {
717 plan.formatDir = plan.configured && i == 0 ? QString() : plan.format.toLower();
718 plan.formatDirLocation = plan.location;
719 }
720
721 const QString perKey = configKey(plan.format, CONFIG_PUBLICATIONLAYOUT);
722 const QString layoutKey = config.contains(perKey) ? perKey : CONFIG_PUBLICATIONLAYOUT;
723 if (config.contains(layoutKey)) {
724 const auto &value = config.get(layoutKey);
725 plan.layoutLocation = value.location();
726 if (const auto layout = parsePublicationLayout(value.asString())) {
727 plan.layout = *layout;
728 } else {
729 reporter.add(Diagnostic::Kind::Error, value.location(),
730 "Invalid %1 '%2'."_L1.arg(layoutKey, value.asString()),
731 u"Expected 'flat' or 'per-module'."_s);
732 }
733 } else {
734 const QString aliasKey = configKey(plan.format, u"nosubdirs"_s);
735 if (config.contains(aliasKey)) {
736 const auto &alias = config.get(aliasKey);
738 plan.layoutLocation = alias.location();
739 reporter.add(Diagnostic::Kind::Notice, alias.location(),
740 "%1 is deprecated; use %2 or publicationlayout instead."_L1
741 .arg(aliasKey, perKey));
742 }
743 }
745 if (isValidModuleDir(moduleDir)) {
746 plan.moduleDir = moduleDir;
747 } else if (plan.requested) {
748 reporter.add(Diagnostic::Kind::Error, project.location(),
749 "Invalid project identity '%1' for per-module publication."_L1
750 .arg(project.asString()),
751 u"Project must be a safe directory name."_s);
752 }
753 }
754 result.formats.push_back(std::move(plan));
755 }
756
757 QHash<QString, const FormatPlan *> destinations;
758 for (const auto &plan : result.formats) {
759 if (!plan.requested)
760 continue;
761 const QString dir = result.destination(plan);
762 const auto it = destinations.constFind(dir);
763 if (it == destinations.constEnd()) {
764 destinations.insert(dir, &plan);
765 } else {
766 const auto &otherLocation = it.value()->formatDirLocation;
767 reporter.add(Diagnostic::Kind::Error, plan.formatDirLocation,
768 "Conflicting output destinations for '%1' and '%2': %3"_L1
769 .arg(it.value()->format, plan.format, dir),
770 otherLocation.isEmpty() ? QString()
771 : "Other destination declared at %1."_L1.arg(otherLocation.toString()));
772 }
773 }
774 return result;
775}
776
777/*!
778 Returns \c true if a selection or layout diagnostic blocks publication.
779 Migration notices alone do not invalidate the configuration.
780*/
782{
783 for (const auto &diagnostic : diagnostics) {
784 if (diagnostic.kind == Diagnostic::Kind::Error)
785 return true;
786 }
787 return false;
788}
789
790/*!
791 Returns the plan for the case-sensitive identity \a format, or \c{nullptr}
792 if absent. A configured entry can be present without being requested.
793
794 The pointer borrows storage from this configuration and remains valid only
795 while that storage is alive and unchanged. It does not certify plan validity.
796*/
798{
799 for (const auto &plan : formats) {
800 if (plan.format == format)
801 return &plan;
802 }
803 return nullptr;
804}
805
806/*!
807 Returns the normalized root, format directory, and module directory for
808 \a plan. Use an entry from this configuration after checking hasErrors().
809
810 A root-only path is normalized too; \c{.} denotes the current directory.
811 This query does not create directories, require their existence, resolve
812 filesystem aliases, or check whether the entry is requested.
813*/
815{
816 return joinPath(root, joinPath(plan.formatDir, plan.moduleDir));
817}
818
819QT_END_NAMESPACE
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition config.h:95
The Location class provides a way to mark a location in a file.
Definition location.h:20
Location()
Constructs an empty location.
Definition location.cpp:50
#define CONFIG_PIPELINE
Definition config.h:441
#define CONFIG_OUTPUTDIR
Definition config.h:436
#define CONFIG_TEMPLATEPACKAGE
Definition config.h:464
#define CONFIG_PROJECT
Definition config.h:444
#define CONFIG_PUBLICATIONLAYOUT
Definition config.h:446
#define CONFIG_OUTPUTFORMATS
Definition config.h:437
PublicationLayout
\variable PipelineCapabilities::pipeline
\typealias OutputConfiguration::Mode
Adds publication destinations to a resolved output selection.
OutputSelection::Diagnostic Diagnostic
const FormatPlan * findFormat(const QString &format) const
Returns the plan for the case-sensitive identity format, or {nullptr} if absent.
bool hasErrors() const
Returns true if a selection or layout diagnostic blocks publication.
static OutputConfiguration resolve(const Config &config, const OutputConfigurationInput &input={})
\variable OutputConfiguration::FormatPlan::formatDir
QString destination(const FormatPlan &plan) const
Returns the normalized root, format directory, and module directory for plan.
OutputSelection::Mode Mode
Carries a source-positioned publication diagnostic without emitting it.
Kind
Distinguishes blocking errors from migration advice.
\variable OutputSelection::Diagnostic::kind
\variable OutputConfigurationInput::cliPipelines
bool hasErrors() const
Returns true if any diagnostic blocks publication.
Mode
Identifies which configuration interpretation controls publication.
static OutputSelection resolve(const Config &config, const OutputConfigurationInput &input={})
Resolves publication requests from config and the explicit input.
const Format * findFormat(const QString &format) const
Returns the entry for the case-sensitive identity format, or {nullptr} if it is absent.
Describes a pipeline without constructing generators or loading packages.