Skip to content

Commit bcd2042

Browse files
committed
[build-script] Transform IndexStoreDB and SourcekitLSP to use ProductBuilders.
Create a new helper for IndexStoreDB and SourcekitLSP called BuildScriptHelperBuilder. Move most of the code that existed in a function in indexstoredb.py into that helper object. Create small builders for IndexStoreDB and SourcekitLSP which use this helper object as their base. Modify the main build-script to invoke the new builder instead of the specific do_build/do_test. This way, all products are using the same system to be build, but some use build-script-impl, and others use build-script-helper.py.
1 parent 36058be commit bcd2042

File tree

5 files changed

+92
-65
lines changed

5 files changed

+92
-65
lines changed

utils/build-script

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,14 @@ class BuildScriptInvocation(object):
321321

322322
# Non-build-script-impl products...
323323
# Note: currently only supports building for the host.
324-
for host_target in [self.args.host_target]:
324+
for host_target in [
325+
StdlibDeploymentTarget.get_target_for_name(
326+
self.args.host_target)]:
325327
for product_class in product_classes:
326328
if product_class.is_build_script_impl_product():
327329
continue
328-
product_source = product_class.product_source_name()
329-
product_name = product_class.product_name()
330-
product = product_class(
331-
args=self.args,
332-
toolchain=self.toolchain,
333-
source_dir=self.workspace.source_dir(product_source),
334-
build_dir=self.workspace.build_dir(
335-
host_target, product_name))
336-
product.do_build(host_target)
337-
product.do_test(host_target)
330+
self.__execute_build_action(host_target, product_class)
331+
self.__execute_test_action(host_target, product_class)
338332

339333
# Extract symbols...
340334
for host_target in all_hosts:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# swift_build_support/product_builders/build_script_helper_b... -*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2019 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+
from . import product_builder
14+
from .. import shell, targets
15+
16+
import os
17+
import platform
18+
19+
20+
class BuildScriptHelperBuilder(product_builder.ProductBuilder):
21+
def __init__(self, product_class, args, toolchain, workspace, host):
22+
self.__source_dir = workspace.source_dir(
23+
product_class.product_source_name())
24+
self.__build_dir = workspace.build_dir(host.name,
25+
product_class.product_name())
26+
self.__args = args
27+
28+
def do_build(self):
29+
self.__run_build_script_helper('build')
30+
31+
def do_test(self):
32+
if self._should_test():
33+
self.__run_build_script_helper('test')
34+
35+
def _should_test(self):
36+
raise NotImplementedError("_should_test should be overriden by "
37+
"subclass {}.".format(self.__class__))
38+
39+
def __run_build_script_helper(self, action):
40+
script_path = os.path.join(
41+
self.__source_dir, 'Utilities', 'build-script-helper.py')
42+
toolchain_path = self.__args.install_destdir
43+
if platform.system() == 'Darwin':
44+
# The prefix is an absolute path, so concatenate without os.path.
45+
toolchain_path += \
46+
targets.darwin_toolchain_prefix(self.__args.install_prefix)
47+
if self.__args.build_variant == 'Debug':
48+
configuration = 'debug'
49+
else:
50+
configuration = 'release'
51+
helper_cmd = [
52+
script_path,
53+
action,
54+
'--verbose',
55+
'--package-path', self.__source_dir,
56+
'--build-path', self.__build_dir,
57+
'--configuration', configuration,
58+
'--toolchain', toolchain_path,
59+
]
60+
shell.call(helper_cmd)

utils/swift_build_support/swift_build_support/products/indexstoredb.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13-
import os
14-
import platform
15-
1613
from . import product
17-
from .. import shell
18-
from .. import targets
14+
from .build_script_helper_builder import BuildScriptHelperBuilder
1915

2016

2117
class IndexStoreDB(product.Product):
@@ -27,30 +23,16 @@ def product_source_name(cls):
2723
def is_build_script_impl_product(cls):
2824
return False
2925

30-
def do_build(self, host_target):
31-
run_build_script_helper('build', host_target, self, self.args)
32-
33-
def do_test(self, host_target):
34-
if self.args.test and self.args.test_indexstoredb:
35-
run_build_script_helper('test', host_target, self, self.args)
36-
37-
38-
def run_build_script_helper(action, host_target, product, args):
39-
script_path = os.path.join(
40-
product.source_dir, 'Utilities', 'build-script-helper.py')
41-
toolchain_path = args.install_destdir
42-
if platform.system() == 'Darwin':
43-
# The prefix is an absolute path, so concatenate without os.path.
44-
toolchain_path += \
45-
targets.darwin_toolchain_prefix(args.install_prefix)
46-
configuration = 'debug' if args.build_variant == 'Debug' else 'release'
47-
helper_cmd = [
48-
script_path,
49-
action,
50-
'--verbose',
51-
'--package-path', product.source_dir,
52-
'--build-path', product.build_dir,
53-
'--configuration', configuration,
54-
'--toolchain', toolchain_path,
55-
]
56-
shell.call(helper_cmd)
26+
@classmethod
27+
def make_builder(cls, args, toolchain, workspace, host):
28+
return IndexStoreDBBuilder(args, toolchain, workspace, host)
29+
30+
31+
class IndexStoreDBBuilder(BuildScriptHelperBuilder):
32+
def __init__(self, args, toolchain, workspace, host):
33+
BuildScriptHelperBuilder.__init__(self, IndexStoreDB, args, toolchain,
34+
workspace, host)
35+
self.__args = args
36+
37+
def _should_test(self):
38+
return self.__args.test and self.__args.test_indexstoredb

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ def is_build_script_impl_product(cls):
4040
"""
4141
return True
4242

43-
def do_build(self, host_target):
44-
"""do_build() -> void
45-
46-
Perform the build, for a non-build-script-impl product.
47-
"""
48-
raise NotImplementedError
49-
50-
def do_test(self, host_target):
51-
"""do_build() -> void
52-
53-
Run the tests, for a non-build-script-impl product.
54-
"""
55-
raise NotImplementedError
56-
5743
@classmethod
5844
def make_builder(cls, args, toolchain, workspace, host):
5945
return BuildScriptImplBuilder(cls, args, toolchain, workspace, host)

utils/swift_build_support/swift_build_support/products/sourcekitlsp.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13-
from . import indexstoredb
1413
from . import product
14+
from .build_script_helper_builder import BuildScriptHelperBuilder
1515

1616

1717
class SourceKitLSP(product.Product):
@@ -23,11 +23,16 @@ def product_source_name(cls):
2323
def is_build_script_impl_product(cls):
2424
return False
2525

26-
def do_build(self, host_target):
27-
indexstoredb.run_build_script_helper(
28-
'build', host_target, self, self.args)
26+
@classmethod
27+
def make_builder(cls, args, toolchain, workspace, host):
28+
return SourceKitLSPBuilder(args, toolchain, workspace, host)
29+
30+
31+
class SourceKitLSPBuilder(BuildScriptHelperBuilder):
32+
def __init__(self, args, toolchain, workspace, host):
33+
BuildScriptHelperBuilder.__init__(self, SourceKitLSP, args, toolchain,
34+
workspace, host)
35+
self.__args = args
2936

30-
def do_test(self, host_target):
31-
if self.args.test and self.args.test_sourcekitlsp:
32-
indexstoredb.run_build_script_helper(
33-
'test', host_target, self, self.args)
37+
def _should_test(self):
38+
return self.__args.test and self.__args.test_sourcekitlsp

0 commit comments

Comments
 (0)