|
| 1 | +# swift_build_support/products/earlyswiftsyntax.py --------------*- python -*- |
| 2 | +# |
| 3 | +# This source file is part of the Swift.org open source project |
| 4 | +# |
| 5 | +# Copyright (c) 2014 - 2022 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 cmake_product |
| 16 | +from . import product |
| 17 | +from .. import shell |
| 18 | +from .. import toolchain |
| 19 | + |
| 20 | + |
| 21 | +# SwiftSyntax is a Swift module used to parse and manipulate Swift syntax. This |
| 22 | +# build product is a "Special" SwiftSyntax that gets built with the host |
| 23 | +# toolchain that can be linked into the Swift compiler itself, hence it does not |
| 24 | +# depend on any other build product of `build-script`. |
| 25 | +class EarlySwiftSyntax(cmake_product.CMakeProduct): |
| 26 | + @classmethod |
| 27 | + def product_source_name(cls): |
| 28 | + return "swift-syntax" |
| 29 | + |
| 30 | + @classmethod |
| 31 | + def is_build_script_impl_product(cls): |
| 32 | + return False |
| 33 | + |
| 34 | + @classmethod |
| 35 | + def is_before_build_script_impl_product(cls): |
| 36 | + return True |
| 37 | + |
| 38 | + def should_build(self, host_target): |
| 39 | + if self.args.build_early_swiftsyntax: |
| 40 | + if toolchain.host_toolchain().find_tool("swift") is None: |
| 41 | + warn_msg = 'Host toolchain could not locate a '\ |
| 42 | + 'compiler to build early swift-syntax.' |
| 43 | + print('-- Warning: {}', warn_msg) |
| 44 | + return False |
| 45 | + else: |
| 46 | + return True |
| 47 | + return False |
| 48 | + |
| 49 | + @classmethod |
| 50 | + def get_dependencies(cls): |
| 51 | + return [] |
| 52 | + |
| 53 | + def build(self, host_target): |
| 54 | + self.cmake_options.define('CMAKE_BUILD_TYPE:STRING', |
| 55 | + self.args.swift_build_variant) |
| 56 | + self.cmake_options.define('BUILD_SHARED_LIBS:STRING', 'NO') |
| 57 | + |
| 58 | + (platform, arch) = host_target.split('-') |
| 59 | + |
| 60 | + common_c_flags = ' '.join(self.common_cross_c_flags(platform, arch)) |
| 61 | + self.cmake_options.define('CMAKE_C_FLAGS', common_c_flags) |
| 62 | + self.cmake_options.define('CMAKE_CXX_FLAGS', common_c_flags) |
| 63 | + |
| 64 | + if host_target.startswith("macosx") or \ |
| 65 | + host_target.startswith("iphone") or \ |
| 66 | + host_target.startswith("appletv") or \ |
| 67 | + host_target.startswith("watch"): |
| 68 | + toolchain_file = self.generate_darwin_toolchain_file(platform, arch) |
| 69 | + self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file) |
| 70 | + elif platform == "linux": |
| 71 | + toolchain_file = self.generate_linux_toolchain_file(platform, arch) |
| 72 | + self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file) |
| 73 | + |
| 74 | + self.build_with_cmake(["all"], self.args.swift_build_variant, []) |
| 75 | + |
| 76 | + def should_test(self, host_target): |
| 77 | + # The normal SwiftSyntax target runs tests through SwiftPM. |
| 78 | + return False |
| 79 | + |
| 80 | + def test(self, host_target): |
| 81 | + pass |
| 82 | + |
| 83 | + def should_install(self, host_target): |
| 84 | + # This product is for the swift-syntax used with the build-directory compiler. |
| 85 | + # If a toolchain install is required, please use the SwiftSyntax (no 'Early') |
| 86 | + # product with `--swift-syntax --install-swift-syntax`. |
| 87 | + return False |
| 88 | + |
| 89 | + @classmethod |
| 90 | + def is_ignore_install_all_product(cls): |
| 91 | + # Ensures that `install_all` setting triggered by `--infer` does not |
| 92 | + # affect products which specify `is_ignore_install_all_product` as |
| 93 | + # True. This is useful for products which should not be installed into the |
| 94 | + # toolchain (corresponding build products that use the just-built |
| 95 | + # toolchain are the products that get installed, e.g. `swiftsyntax` to |
| 96 | + # `earlyswiftsyntax`). |
| 97 | + return True |
0 commit comments