On both macOS and Linux `python` is not symlinked to `python3` by default. To avoid confusion, we should update our documentation that instructs users to run scripts with `python` to use `python3` instead.
Without this dependency, passing both `--swiftdocc` and `--install-swiftdocc` to `build-script` causes it to crash with this stack trace:
```
Traceback (most recent call last):
File "./swift/utils/build-script", line 789, in <module>
exit_code = main()
File "./swift/utils/build-script", line 784, in main
return main_normal()
File "./swift/utils/build-script", line 740, in main_normal
invocation.execute()
File "./swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 670, in execute
(self.impl_env, self.impl_args) = self.convert_to_impl_arguments()
File "./swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 147, in convert_to_impl_arguments
for product_class in sum(list(self.compute_product_pipelines()[0]), []):
File "./swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 664, in compute_product_pipelines
return builder.finalize(shouldInfer=self.args.infer_dependencies)
File "./swift/utils/swift_build_support/swift_build_support/productpipeline_list_builder.py", line 198, in finalize
result = self.infer()
File "./swift/utils/swift_build_support/swift_build_support/productpipeline_list_builder.py", line 157, in infer
build_graph.produce_scheduled_build(enabled_pipeline)[0]
File "./swift/utils/swift_build_support/swift_build_support/build_graph.py", line 150, in produce_scheduled_build
dag.set_root(entry)
File "./swift/utils/swift_build_support/swift_build_support/build_graph.py", line 95, in set_root
assert self.root is None
AssertionError
```
Apparently, the absence of this explicit dependency makes `build_graph.py` code think that `SwiftDocCRender` and `SwiftDocC` are independent root targets, which it can't handle. Making one a dependency of the other resolves the issue.
Cross-compilation of the host depends on iteration over all of the host
architectures within build-script-impl itself, so the computation of
the build directory must occur in build-script-impl. Sink it down there
to fix builds for multiple host architectures.
Replace the correct Swift -> EarlySwiftSyntax dependency with an
EarlySwiftDriver -> EarlySwiftSyntax dependency, to keep a linear
dependency order in this part of the build graph.
When enabled, compile in support for round-trip testing the new
SwiftSyntax-provided Swift parser alongside the existing parser. Right
now, this means parsing every source file with the new parser and
ensuring that the resulting syntax tree can reproduce the input source
precisely. Over time, this is expected to grow.
Opt in to this behavior by passing the following to build-script:
build-script --early-swiftsyntax --extra-cmake-options=-DSWIFT_SWIFT_PARSER_MODE:STRING=ROUNDTRIP
With a properly prepared sysroot and toolchain file, these changes permit
cross-compilation of Swift as well as LLVM, CMark, and Dispatch (picking,
as usual, apple/swift-corelibs-libdispatch#556) from a Linux host
generating OpenBSD binaries.
The toolchain file must be specified as an environment variable to
`build-script` and discussion on how to properly set up the sysroot and
toolchain file will be handled later.
Similar to the way the early Swift Driver is built, introduce a
build-script option `--early-swiftsyntax` that uses the host Swift and
CMake to build the parts of the swift-syntax package that are expected
to become be used in the compiler.
Note that this does not obviate the need for the `--swiftsyntax`
option, because that build product uses the just-built Swift compiler
and SwiftPM to build, test, and install everything from the
swift-syntax package.
Running swift test with `--test-product SourceKitLSPPackageTest` fails when cross-compiling with an error message like the following (rdar://97876450)
```
error: Could not find target named 'SourceKitLSPPackageTests_-6F17C3BE20775DA1_PackageProduct'
```
Since we don’t run the test on the cross-compile host anyway, just disable cross-compilation during testing.
As part of the build the entire ninja source dir is copied to the build
dir and then built. When using git's fsmonitor feature the .git
directory contains a socket which causes the copytree to fail. With this
change .git is ignored entirely instead. Error:
```
Traceback (most recent call last):
...
File "/Users/ksmiley/dev/oss-swift/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 69, in build_ninja
ninja_build.build()
File "/Users/ksmiley/dev/oss-swift/swift/utils/swift_build_support/swift_build_support/products/ninja.py", line 80, in build
shell.copytree(self.source_dir, self.build_dir)
File "/Users/ksmiley/dev/oss-swift/swift/utils/swift_build_support/swift_build_support/shell.py", line 193, in copytree
shutil.copytree(src, dest)
File "/Users/ksmiley/.pyenv/versions/3.10.2/lib/python3.10/shutil.py", line 556, in copytree
return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
File "/Users/ksmiley/.pyenv/versions/3.10.2/lib/python3.10/shutil.py", line 512, in _copytree
raise Error(errors)
shutil.Error: [('/Users/ksmiley/dev/oss-swift/ninja/.git/fsmonitor--daemon.ipc', '/Users/ksmiley/dev/oss-swift/build/buildbot_osx/ninja-build/.git/fsmonitor--daemon.ipc', "[Errno 102] Operation not supported on socket: '/Users/ksmiley/dev/oss-swift/ninja/.git/fsmonitor--daemon.ipc'")]
```
Currently, when building an open source toolchain, SourceKit-LSP is only built for x86_64. Copy the cross-compilation config from swiftpm.py to also produce a fat sourcekit-lsp executable for both x86_64 and arm64.
rdar://78039145
Previously, we were always cleaning the sourcekit-lsp build directory prior to running tests and installing. That’s a waste of time. Only clean prior to the first build.
The `__future__` we relied on is now, where the 3 specific things are
all included [since Python 3.0](https://docs.python.org/3/library/__future__.html):
* absolute_import
* print_function
* unicode_literals
* division
These import statements are no-ops and are no longer necessary.
This patch adds a zlib and static-zlib build product, respectively
producing a dynamic and static zlib library. This is a dependency of
building Foundation.
The library `six` provides compatibility between Python 2, and 3. It's no
longer necessary once we migrate of Python 2 completely.
Also remove any custom logic for Python 2 (the ones referenced by
a commentanyways).
https://bugs.swift.org/browse/SR-16025