-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[build-script] Transform IndexStoreDB and SorcekitLSP to use ProductBuilder #24854
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# swift_build_support/product_builders/build_script_helper_b... -*- python -*- | ||
# | ||
# This source file is part of the Swift.org open source project | ||
# | ||
# Copyright (c) 2014 - 2019 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 abc | ||
import os | ||
import platform | ||
|
||
from . import product | ||
from .. import shell, targets | ||
|
||
|
||
class BuildScriptHelperBuilder(product.ProductBuilder): | ||
def __init__(self, product_class, args, toolchain, workspace, host): | ||
self.__source_dir = workspace.source_dir( | ||
product_class.product_source_name()) | ||
self.__build_dir = workspace.build_dir(host.name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why double underscores? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python performs name mangling when you use two underscores as a prefix. It is useful for private variables that cannot be accessed from other classes (including subclasses of this one). https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references |
||
product_class.product_name()) | ||
self.__args = args | ||
|
||
def build(self): | ||
self.__run_build_script_helper('build') | ||
|
||
def test(self): | ||
if self._should_test(): | ||
self.__run_build_script_helper('test') | ||
|
||
@abc.abstractmethod | ||
def _should_test(self): | ||
pass | ||
|
||
def __run_build_script_helper(self, action): | ||
script_path = os.path.join( | ||
self.__source_dir, 'Utilities', 'build-script-helper.py') | ||
toolchain_path = self.__args.install_destdir | ||
if platform.system() == 'Darwin': | ||
# The prefix is an absolute path, so concatenate without os.path. | ||
toolchain_path += \ | ||
targets.darwin_toolchain_prefix(self.__args.install_prefix) | ||
if self.__args.build_variant == 'Debug': | ||
configuration = 'debug' | ||
else: | ||
configuration = 'release' | ||
helper_cmd = [ | ||
script_path, | ||
action, | ||
'--verbose', | ||
'--package-path', self.__source_dir, | ||
'--build-path', self.__build_dir, | ||
'--configuration', configuration, | ||
'--toolchain', toolchain_path, | ||
] | ||
shell.call(helper_cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why leave the list if its a single element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are asking why have a
for ... in
for a known one element list, right? I think the reason is future-proofing, because the comment says that the products only support building for the host, but they might some day support building for more targets, and that change will be easy having this in place. Ben might know the real reason, since he wrote the original code.