Skip to content

Commit 0a04cce

Browse files
authored
Merge pull request #39723 from d-ronnqvist/add-docc-in-build-script
[BuildScript] Add products for Swift-DocC and Swift-DocC-Render
2 parents 2ad0eb7 + 4d73833 commit 0a04cce

File tree

9 files changed

+264
-3
lines changed

9 files changed

+264
-3
lines changed

utils/build-presets.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ install-libicu
818818
install-prefix=/usr
819819
install-libcxx
820820
install-sourcekit-lsp
821+
install-swiftdocc
821822
build-swift-static-stdlib
822823
build-swift-static-sdk-overlay
823824
build-swift-stdlib-unittest-extra
@@ -857,6 +858,7 @@ foundation
857858
libdispatch
858859
indexstore-db
859860
sourcekit-lsp
861+
swiftdocc
860862
lit-args=-v --time-tests
861863

862864
# rdar://problem/31454823
@@ -880,6 +882,7 @@ skip-test-playgroundsupport
880882
skip-test-libicu
881883
skip-test-indexstore-db
882884
skip-test-sourcekit-lsp
885+
skip-test-swiftdocc
883886

884887
# Linux package with out test
885888
[preset: buildbot_linux,no_test]
@@ -1224,6 +1227,7 @@ playgroundsupport
12241227
libcxx
12251228
indexstore-db
12261229
sourcekit-lsp
1230+
swiftdocc
12271231

12281232
# Build concurrency back-deployment binaries
12291233
back-deploy-concurrency
@@ -1273,6 +1277,7 @@ install-playgroundsupport
12731277
install-libcxx
12741278
install-sourcekit-lsp
12751279
install-back-deploy-concurrency
1280+
install-swiftdocc
12761281

12771282
install-destdir=%(install_destdir)s
12781283

@@ -1380,6 +1385,7 @@ skip-test-playgroundsupport
13801385
skip-test-swiftsyntax
13811386
skip-test-skstresstester
13821387
skip-test-swiftevolve
1388+
skip-test-swiftdocc
13831389

13841390
[preset: buildbot_osx_package,no_assertions,no_test,use_os_runtime]
13851391
mixin-preset=
@@ -1414,6 +1420,7 @@ skip-test-playgroundsupport
14141420
skip-test-swiftsyntax
14151421
skip-test-skstresstester
14161422
skip-test-swiftevolve
1423+
skip-test-swiftdocc
14171424

14181425
# macOS package with out test
14191426
[preset: buildbot_osx_package,no_test]
@@ -1558,6 +1565,7 @@ swiftpm
15581565
# swift-inspect
15591566
swift-driver
15601567
swiftsyntax
1568+
swiftdocc
15611569

15621570
# Don't generate the SwiftSyntax gyb files. Instead verify that up-to-date ones
15631571
# are checked in.
@@ -1572,6 +1580,7 @@ install-llbuild
15721580
install-swiftpm
15731581
install-swift-driver
15741582
install-libcxx
1583+
install-swiftdocc
15751584

15761585
# Build the stress tester and SwiftEvolve
15771586
skstresstester

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def _apply_default_arguments(args):
193193
args.test_swiftformat = False
194194
args.test_swiftevolve = False
195195
args.test_toolchainbenchmarks = False
196+
args.test_swiftdocc = False
196197

197198
# --test implies --test-early-swift-driver
198199
# (unless explicitly skipped with `--skip-test-early-swift-driver`)
@@ -632,6 +633,8 @@ def create_argument_parser():
632633

633634
option(['--swift-driver'], toggle_true('build_swift_driver'),
634635
help='build swift-driver')
636+
option(['--swiftdocc'], toggle_true('build_swiftdocc'),
637+
help='build Swift DocC')
635638

636639
option(['--skip-early-swift-driver'], toggle_false('build_early_swift_driver'),
637640
help='skip building the early swift-driver')
@@ -660,6 +663,8 @@ def create_argument_parser():
660663
help='install new Swift driver')
661664
option(['--install-swiftevolve'], toggle_true('install_swiftevolve'),
662665
help='install SwiftEvolve')
666+
option(['--install-swiftdocc'], toggle_true('install_swiftdocc'),
667+
help='install Swift DocC')
663668
option(['--toolchain-benchmarks'],
664669
toggle_true('build_toolchainbenchmarks'),
665670
help='build Swift Benchmarks using swiftpm against the just built '
@@ -1119,6 +1124,8 @@ def create_argument_parser():
11191124
option('--skip-test-swift-inspect',
11201125
toggle_false('test_swift_inspect'),
11211126
help='skip testing swift_inspect')
1127+
option('--skip-test-swiftdocc', toggle_false('test_swiftdocc'),
1128+
help='skip testing swift-docc')
11221129

11231130
# -------------------------------------------------------------------------
11241131
in_group('Build settings specific for LLVM')

utils/build_swift/resources/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/build_swift/tests/expected_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@
9696
'build_skstresstester': False,
9797
'build_swiftformat': False,
9898
'build_swiftevolve': False,
99+
'build_swiftdocc': False,
99100
'build_indexstoredb': False,
100101
'test_indexstoredb_sanitize_all': False,
101102
'test_sourcekitlsp_sanitize_all': False,
102103
'build_sourcekitlsp': False,
103104
'install_swiftpm': False,
104105
'install_swiftsyntax': False,
105106
'install_swift_driver': False,
107+
'install_swiftdocc': False,
106108
'swiftsyntax_verify_generated_files': False,
107109
'install_playgroundsupport': False,
108110
'install_sourcekitlsp': False,
@@ -262,6 +264,7 @@
262264
'test_skstresstester': False,
263265
'test_swiftformat': False,
264266
'test_swiftevolve': False,
267+
'test_swiftdocc': False,
265268
'test_toolchainbenchmarks': False,
266269
'tvos': False,
267270
'tvos_all': False,
@@ -509,6 +512,7 @@ class BuildScriptImplOption(_BaseOption):
509512
SetTrueOption('--skstresstester', dest='build_skstresstester'),
510513
SetTrueOption('--swiftformat', dest='build_swiftformat'),
511514
SetTrueOption('--swiftevolve', dest='build_swiftevolve'),
515+
SetTrueOption('--swiftdocc', dest='build_swiftdocc'),
512516
SetTrueOption('-B', dest='benchmark'),
513517
SetTrueOption('-S', dest='skip_build'),
514518
SetTrueOption('-b', dest='build_llbuild'),
@@ -563,6 +567,7 @@ class BuildScriptImplOption(_BaseOption):
563567
EnableOption('--install-sourcekit-lsp', dest='install_sourcekitlsp'),
564568
EnableOption('--install-skstresstester', dest='install_skstresstester'),
565569
EnableOption('--install-swiftevolve', dest='install_swiftevolve'),
570+
EnableOption('--install-swiftdocc', dest='install_swiftdocc'),
566571
EnableOption('--toolchain-benchmarks', dest='build_toolchainbenchmarks'),
567572
EnableOption('--swift-inspect', dest='build_swift_inspect'),
568573
EnableOption('--tsan-libdispatch-test'),
@@ -644,6 +649,7 @@ class BuildScriptImplOption(_BaseOption):
644649
DisableOption('--skip-test-skstresstester', dest='test_skstresstester'),
645650
DisableOption('--skip-test-swiftformat', dest='test_swiftformat'),
646651
DisableOption('--skip-test-swiftevolve', dest='test_swiftevolve'),
652+
DisableOption('--skip-test-swiftdocc', dest='test_swiftdocc'),
647653
DisableOption('--skip-test-toolchain-benchmarks',
648654
dest='test_toolchainbenchmarks'),
649655
DisableOption('--skip-test-swift-inspect',

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ def compute_product_pipelines(self):
605605
is_enabled=self.args.build_swift_inspect)
606606
builder.add_product(products.TSanLibDispatch,
607607
is_enabled=self.args.tsan_libdispatch_test)
608+
builder.add_product(products.SwiftDocC,
609+
is_enabled=self.args.build_swiftdocc)
610+
builder.add_product(products.SwiftDocCRender,
611+
is_enabled=self.args.install_swiftdocc)
608612

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

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from .skstresstester import SKStressTester
2828
from .sourcekitlsp import SourceKitLSP
2929
from .swift import Swift
30+
from .swiftdocc import SwiftDocC
31+
from .swiftdoccrender import SwiftDocCRender
3032
from .swiftdriver import SwiftDriver
3133
from .swiftevolve import SwiftEvolve
3234
from .swiftformat import SwiftFormat
@@ -63,4 +65,6 @@
6365
'SourceKitLSP',
6466
'Benchmarks',
6567
'TSanLibDispatch',
68+
'SwiftDocC',
69+
'SwiftDocCRender'
6670
]
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# swift_build_support/products/swiftdocc.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 build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH
16+
17+
from . import cmark
18+
from . import foundation
19+
from . import libcxx
20+
from . import libdispatch
21+
from . import libicu
22+
from . import llbuild
23+
from . import llvm
24+
from . import product
25+
from . import swift
26+
from . import swiftpm
27+
from . import swiftsyntax
28+
from . import xctest
29+
from .. import shell
30+
31+
32+
class SwiftDocC(product.Product):
33+
@classmethod
34+
def product_source_name(cls):
35+
"""product_source_name() -> str
36+
37+
The name of the source code directory of this product.
38+
"""
39+
return "swift-docc"
40+
41+
@classmethod
42+
def is_build_script_impl_product(cls):
43+
return False
44+
45+
@classmethod
46+
def is_before_build_script_impl_product(cls):
47+
return False
48+
49+
@classmethod
50+
def is_swiftpm_unified_build_product(cls):
51+
return True
52+
53+
def run_build_script_helper(self, action, host_target, additional_params=[]):
54+
script_path = os.path.join(
55+
self.source_dir, 'build-script-helper.py')
56+
57+
configuration = 'release' if self.is_release() else 'debug'
58+
59+
helper_cmd = [
60+
script_path,
61+
action,
62+
'--toolchain', self.install_toolchain_path(host_target),
63+
'--configuration', configuration,
64+
'--build-dir', self.build_dir,
65+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
66+
]
67+
if action != 'install':
68+
helper_cmd.extend([
69+
# There might have been a Package.resolved created by other builds
70+
# or by the package being opened using Xcode. Discard that and
71+
# reset the dependencies to be local.
72+
'--update'
73+
])
74+
if self.args.verbose_build:
75+
helper_cmd.append('--verbose')
76+
helper_cmd.extend(additional_params)
77+
78+
shell.call(helper_cmd)
79+
80+
def should_build(self, host_target):
81+
return True
82+
83+
def build(self, host_target):
84+
self.run_build_script_helper('build', host_target)
85+
86+
def should_test(self, host_target):
87+
return self.args.test_swiftdocc
88+
89+
def test(self, host_target):
90+
self.run_build_script_helper('test', host_target)
91+
92+
def should_install(self, host_target):
93+
return self.args.install_swiftdocc
94+
95+
def install(self, host_target):
96+
# swift-docc is installed at '/usr/bin/docc' in the built toolchain.
97+
install_toolchain_path = self.install_toolchain_path(host_target)
98+
install_dir = os.path.join(install_toolchain_path, 'bin')
99+
100+
additional_params = ['--install-dir', install_dir]
101+
102+
self.run_build_script_helper('install', host_target, additional_params)
103+
104+
@classmethod
105+
def get_dependencies(cls):
106+
return [cmark.CMark,
107+
llvm.LLVM,
108+
libcxx.LibCXX,
109+
libicu.LibICU,
110+
swift.Swift,
111+
libdispatch.LibDispatch,
112+
foundation.Foundation,
113+
xctest.XCTest,
114+
llbuild.LLBuild,
115+
swiftpm.SwiftPM,
116+
swiftsyntax.SwiftSyntax]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# swift_build_support/products/swiftdoccrender.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 shell
17+
18+
19+
class SwiftDocCRender(product.Product):
20+
@classmethod
21+
def product_source_name(cls):
22+
"""product_source_name() -> str
23+
24+
The name of the source code directory of this product.
25+
"""
26+
return "swift-docc-render-artifact"
27+
28+
@classmethod
29+
def is_build_script_impl_product(cls):
30+
return False
31+
32+
@classmethod
33+
def is_before_build_script_impl_product(cls):
34+
return False
35+
36+
@classmethod
37+
def is_swiftpm_unified_build_product(cls):
38+
return False
39+
40+
def should_build(self, host_target):
41+
# Swift-DocC-Render is a pre-built, installable artifact.
42+
return False
43+
44+
def should_test(self, host_target):
45+
# Swift-DocC-Render is a pre-built, installable artifact.
46+
return False
47+
48+
def should_install(self, host_target):
49+
# Swift-DocC-Render should always be installed if Swift-DocC is being installed
50+
return self.args.install_swiftdocc
51+
52+
def install(self, host_target):
53+
# Swift-DocC-Render is installed at '/usr/share/docc/render' in the built
54+
# toolchain.
55+
install_toolchain_path = self.install_toolchain_path(host_target)
56+
install_path = os.path.join(install_toolchain_path, 'share', 'docc', 'render')
57+
58+
# The pre-built version of Swift-DocC-Render is distributed in the 'dist'
59+
# folder at the root of the swift-docc-render-artifact repository
60+
artifact_dist_path = os.path.join(self.source_dir, 'dist')
61+
62+
# Add a trailing slash so that we copy the contents of the 'dist' directory
63+
# instead of the 'dist' directory itself.
64+
artifact_dist_path_with_trailing_slash = os.path.join(artifact_dist_path, '')
65+
66+
shell.call(["mkdir", "-p", install_path])
67+
shell.call(
68+
["rsync", "-a", artifact_dist_path_with_trailing_slash, install_path])
69+
70+
@classmethod
71+
def get_dependencies(cls):
72+
return []

0 commit comments

Comments
 (0)