Skip to content

[BuildScript] Add products for Swift-DocC and Swift-DocC-Render #39723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ install-libicu
install-prefix=/usr
install-libcxx
install-sourcekit-lsp
install-swiftdocc
build-swift-static-stdlib
build-swift-static-sdk-overlay
build-swift-stdlib-unittest-extra
Expand Down Expand Up @@ -854,6 +855,7 @@ foundation
libdispatch
indexstore-db
sourcekit-lsp
swiftdocc
lit-args=-v --time-tests

# rdar://problem/31454823
Expand All @@ -877,6 +879,7 @@ skip-test-playgroundsupport
skip-test-libicu
skip-test-indexstore-db
skip-test-sourcekit-lsp
skip-test-swiftdocc

# Linux package with out test
[preset: buildbot_linux,no_test]
Expand Down Expand Up @@ -1221,6 +1224,7 @@ playgroundsupport
libcxx
indexstore-db
sourcekit-lsp
swiftdocc

# Build concurrency back-deployment binaries
back-deploy-concurrency
Expand Down Expand Up @@ -1270,6 +1274,7 @@ install-playgroundsupport
install-libcxx
install-sourcekit-lsp
install-back-deploy-concurrency
install-swiftdocc

install-destdir=%(install_destdir)s

Expand Down Expand Up @@ -1377,6 +1382,7 @@ skip-test-playgroundsupport
skip-test-swiftsyntax
skip-test-skstresstester
skip-test-swiftevolve
skip-test-swiftdocc

[preset: buildbot_osx_package,no_assertions,no_test,use_os_runtime]
mixin-preset=
Expand Down Expand Up @@ -1411,6 +1417,7 @@ skip-test-playgroundsupport
skip-test-swiftsyntax
skip-test-skstresstester
skip-test-swiftevolve
skip-test-swiftdocc

# macOS package with out test
[preset: buildbot_osx_package,no_test]
Expand Down Expand Up @@ -1555,6 +1562,7 @@ swiftpm
# swift-inspect
swift-driver
swiftsyntax
swiftdocc

# Don't generate the SwiftSyntax gyb files. Instead verify that up-to-date ones
# are checked in.
Expand All @@ -1569,6 +1577,7 @@ install-llbuild
install-swiftpm
install-swift-driver
install-libcxx
install-swiftdocc

# Build the stress tester and SwiftEvolve
skstresstester
Expand Down
7 changes: 7 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def _apply_default_arguments(args):
args.test_swiftformat = False
args.test_swiftevolve = False
args.test_toolchainbenchmarks = False
args.test_swiftdocc = False

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

option(['--swift-driver'], toggle_true('build_swift_driver'),
help='build swift-driver')
option(['--swiftdocc'], toggle_true('build_swiftdocc'),
help='build Swift DocC')

option(['--skip-early-swift-driver'], toggle_false('build_early_swift_driver'),
help='skip building the early swift-driver')
Expand Down Expand Up @@ -660,6 +663,8 @@ def create_argument_parser():
help='install new Swift driver')
option(['--install-swiftevolve'], toggle_true('install_swiftevolve'),
help='install SwiftEvolve')
option(['--install-swiftdocc'], toggle_true('install_swiftdocc'),
help='install Swift DocC')
option(['--toolchain-benchmarks'],
toggle_true('build_toolchainbenchmarks'),
help='build Swift Benchmarks using swiftpm against the just built '
Expand Down Expand Up @@ -1119,6 +1124,8 @@ def create_argument_parser():
option('--skip-test-swift-inspect',
toggle_false('test_swift_inspect'),
help='skip testing swift_inspect')
option('--skip-test-swiftdocc', toggle_false('test_swiftdocc'),
help='skip testing swift-docc')

# -------------------------------------------------------------------------
in_group('Build settings specific for LLVM')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@
'build_skstresstester': False,
'build_swiftformat': False,
'build_swiftevolve': False,
'build_swiftdocc': False,
'build_indexstoredb': False,
'test_indexstoredb_sanitize_all': False,
'test_sourcekitlsp_sanitize_all': False,
'build_sourcekitlsp': False,
'install_swiftpm': False,
'install_swiftsyntax': False,
'install_swift_driver': False,
'install_swiftdocc': False,
'swiftsyntax_verify_generated_files': False,
'install_playgroundsupport': False,
'install_sourcekitlsp': False,
Expand Down Expand Up @@ -262,6 +264,7 @@
'test_skstresstester': False,
'test_swiftformat': False,
'test_swiftevolve': False,
'test_swiftdocc': False,
'test_toolchainbenchmarks': False,
'tvos': False,
'tvos_all': False,
Expand Down Expand Up @@ -509,6 +512,7 @@ class BuildScriptImplOption(_BaseOption):
SetTrueOption('--skstresstester', dest='build_skstresstester'),
SetTrueOption('--swiftformat', dest='build_swiftformat'),
SetTrueOption('--swiftevolve', dest='build_swiftevolve'),
SetTrueOption('--swiftdocc', dest='build_swiftdocc'),
SetTrueOption('-B', dest='benchmark'),
SetTrueOption('-S', dest='skip_build'),
SetTrueOption('-b', dest='build_llbuild'),
Expand Down Expand Up @@ -563,6 +567,7 @@ class BuildScriptImplOption(_BaseOption):
EnableOption('--install-sourcekit-lsp', dest='install_sourcekitlsp'),
EnableOption('--install-skstresstester', dest='install_skstresstester'),
EnableOption('--install-swiftevolve', dest='install_swiftevolve'),
EnableOption('--install-swiftdocc', dest='install_swiftdocc'),
EnableOption('--toolchain-benchmarks', dest='build_toolchainbenchmarks'),
EnableOption('--swift-inspect', dest='build_swift_inspect'),
EnableOption('--tsan-libdispatch-test'),
Expand Down Expand Up @@ -644,6 +649,7 @@ class BuildScriptImplOption(_BaseOption):
DisableOption('--skip-test-skstresstester', dest='test_skstresstester'),
DisableOption('--skip-test-swiftformat', dest='test_swiftformat'),
DisableOption('--skip-test-swiftevolve', dest='test_swiftevolve'),
DisableOption('--skip-test-swiftdocc', dest='test_swiftdocc'),
DisableOption('--skip-test-toolchain-benchmarks',
dest='test_toolchainbenchmarks'),
DisableOption('--skip-test-swift-inspect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ def compute_product_pipelines(self):
is_enabled=self.args.build_swift_inspect)
builder.add_product(products.TSanLibDispatch,
is_enabled=self.args.tsan_libdispatch_test)
builder.add_product(products.SwiftDocC,
is_enabled=self.args.build_swiftdocc)
builder.add_product(products.SwiftDocCRender,
is_enabled=self.args.install_swiftdocc)

# Keep SwiftDriver at last.
# swift-driver's integration with the build scripts is not fully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from .skstresstester import SKStressTester
from .sourcekitlsp import SourceKitLSP
from .swift import Swift
from .swiftdocc import SwiftDocC
from .swiftdoccrender import SwiftDocCRender
from .swiftdriver import SwiftDriver
from .swiftevolve import SwiftEvolve
from .swiftformat import SwiftFormat
Expand Down Expand Up @@ -63,4 +65,6 @@
'SourceKitLSP',
'Benchmarks',
'TSanLibDispatch',
'SwiftDocC',
'SwiftDocCRender'
]
116 changes: 116 additions & 0 deletions utils/swift_build_support/swift_build_support/products/swiftdocc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# swift_build_support/products/swiftdocc.py ---------------------*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ----------------------------------------------------------------------------

import os

from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH

from . import cmark
from . import foundation
from . import libcxx
from . import libdispatch
from . import libicu
from . import llbuild
from . import llvm
from . import product
from . import swift
from . import swiftpm
from . import swiftsyntax
from . import xctest
from .. import shell


class SwiftDocC(product.Product):
@classmethod
def product_source_name(cls):
"""product_source_name() -> str

The name of the source code directory of this product.
"""
return "swift-docc"

@classmethod
def is_build_script_impl_product(cls):
return False

@classmethod
def is_before_build_script_impl_product(cls):
return False

@classmethod
def is_swiftpm_unified_build_product(cls):
return True

def run_build_script_helper(self, action, host_target, additional_params=[]):
script_path = os.path.join(
self.source_dir, 'build-script-helper.py')

configuration = 'release' if self.is_release() else 'debug'

helper_cmd = [
script_path,
action,
'--toolchain', self.install_toolchain_path(host_target),
'--configuration', configuration,
'--build-dir', self.build_dir,
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
]
if action != 'install':
helper_cmd.extend([
# There might have been a Package.resolved created by other builds
# or by the package being opened using Xcode. Discard that and
# reset the dependencies to be local.
'--update'
])
if self.args.verbose_build:
helper_cmd.append('--verbose')
helper_cmd.extend(additional_params)

shell.call(helper_cmd)

def should_build(self, host_target):
return True

def build(self, host_target):
self.run_build_script_helper('build', host_target)

def should_test(self, host_target):
return self.args.test_swiftdocc

def test(self, host_target):
self.run_build_script_helper('test', host_target)

def should_install(self, host_target):
return self.args.install_swiftdocc

def install(self, host_target):
# swift-docc is installed at '/usr/bin/docc' in the built toolchain.
install_toolchain_path = self.install_toolchain_path(host_target)
install_dir = os.path.join(install_toolchain_path, 'bin')

additional_params = ['--install-dir', install_dir]

self.run_build_script_helper('install', host_target, additional_params)

@classmethod
def get_dependencies(cls):
return [cmark.CMark,
llvm.LLVM,
libcxx.LibCXX,
libicu.LibICU,
swift.Swift,
libdispatch.LibDispatch,
foundation.Foundation,
xctest.XCTest,
llbuild.LLBuild,
swiftpm.SwiftPM,
swiftsyntax.SwiftSyntax]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# swift_build_support/products/swiftdoccrender.py ---------------*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ----------------------------------------------------------------------------

import os

from . import product
from .. import shell


class SwiftDocCRender(product.Product):
@classmethod
def product_source_name(cls):
"""product_source_name() -> str

The name of the source code directory of this product.
"""
return "swift-docc-render-artifact"

@classmethod
def is_build_script_impl_product(cls):
return False

@classmethod
def is_before_build_script_impl_product(cls):
return False

@classmethod
def is_swiftpm_unified_build_product(cls):
return False

def should_build(self, host_target):
# Swift-DocC-Render is a pre-built, installable artifact.
return False

def should_test(self, host_target):
# Swift-DocC-Render is a pre-built, installable artifact.
return False

def should_install(self, host_target):
# Swift-DocC-Render should always be installed if Swift-DocC is being installed
return self.args.install_swiftdocc

def install(self, host_target):
# Swift-DocC-Render is installed at '/usr/share/docc/render' in the built
# toolchain.
install_toolchain_path = self.install_toolchain_path(host_target)
install_path = os.path.join(install_toolchain_path, 'share', 'docc', 'render')

# The pre-built version of Swift-DocC-Render is distributed in the 'dist'
# folder at the root of the swift-docc-render-artifact repository
artifact_dist_path = os.path.join(self.source_dir, 'dist')

# Add a trailing slash so that we copy the contents of the 'dist' directory
# instead of the 'dist' directory itself.
artifact_dist_path_with_trailing_slash = os.path.join(artifact_dist_path, '')

shell.call(["mkdir", "-p", install_path])
shell.call(
["rsync", "-a", artifact_dist_path_with_trailing_slash, install_path])

@classmethod
def get_dependencies(cls):
return []
Loading