Skip to content

Commit b83c91a

Browse files
build stdlib docs with docc
1 parent b4529a6 commit b83c91a

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ def compute_product_pipelines(self):
710710
)
711711
builder.add_product(products.SwiftDocCRender,
712712
is_enabled=install_doccrender)
713+
builder.add_product(products.StdlibDocs,
714+
is_enabled=self.args.build_stdlib_docs)
713715

714716
# Keep SwiftDriver at last.
715717
# swift-driver's integration with the build scripts is not fully

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .skstresstester import SKStressTester
3030
from .sourcekitlsp import SourceKitLSP
3131
from .staticswiftlinux import StaticSwiftLinuxConfig
32+
from .stdlib_docs import StdlibDocs
3233
from .swift import Swift
3334
from .swift_testing import SwiftTesting
3435
from .swift_testing_macros import SwiftTestingMacros
@@ -65,6 +66,7 @@
6566
'Ninja',
6667
'PlaygroundSupport',
6768
'StaticSwiftLinuxConfig',
69+
'StdlibDocs',
6870
'Swift',
6971
'SwiftFormat',
7072
'SwiftInspect',
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# swift_build_support/products/stdlib_docs.py -------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
15+
from . import product
16+
from . import swiftdocc
17+
from . import swiftdoccrender
18+
from .. import shell
19+
20+
21+
class StdlibDocs(product.Product):
22+
@classmethod
23+
def is_build_script_impl_product(cls):
24+
return False
25+
26+
@classmethod
27+
def is_before_build_script_impl_product(cls):
28+
return False
29+
30+
@classmethod
31+
def is_swiftpm_unified_build_product(cls):
32+
return False
33+
34+
def should_build(self, host_target):
35+
return self.args.build_stdlib_docs
36+
37+
def build(self, host_target):
38+
toolchain_path = self.install_toolchain_path(host_target)
39+
docc_path = os.path.join(toolchain_path, "bin", "docc")
40+
41+
swift_build_dir = os.path.join(
42+
os.path.dirname(self.build_dir),
43+
f'swift-{host_target}'
44+
)
45+
symbol_graph_dir = os.path.join(swift_build_dir, "lib", "symbol-graph")
46+
output_path = os.path.join(swift_build_dir, "Swift.doccarchive")
47+
48+
docc_cmd = [
49+
docc_path,
50+
"convert", # TODO: give people the option to preview instead
51+
"--additional-symbol-graph-dir",
52+
symbol_graph_dir,
53+
"--output-path",
54+
output_path,
55+
"--default-code-listing-language",
56+
"swift",
57+
"--fallback-display-name",
58+
"Swift",
59+
"--fallback-bundle-identifier",
60+
"org.swift.swift",
61+
]
62+
63+
shell.call(docc_cmd)
64+
65+
def should_test(self, host_target):
66+
return False
67+
68+
def should_install(self, host_target):
69+
return False
70+
71+
@classmethod
72+
def get_dependencies(cls):
73+
"""Return a list of products that this product depends upon"""
74+
return [
75+
swiftdocc.SwiftDocC,
76+
swiftdoccrender.SwiftDocCRender
77+
]

0 commit comments

Comments
 (0)