Skip to content

Commit 7b9dcea

Browse files
committed
Merge pull request #792 from modocache/sr-237-build-script-host-cmake
[SR-237][build-script] Determine CMake in Python
2 parents af8cfbf + c65c91d commit 7b9dcea

File tree

4 files changed

+91
-18
lines changed

4 files changed

+91
-18
lines changed

utils/build-script

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from SwiftBuildSupport import (
3636

3737
sys.path.append(os.path.join(os.path.dirname(__file__), 'swift_build_support'))
3838
import swift_build_support.clang
39+
import swift_build_support.cmake
3940
from swift_build_support.migration import migrate_impl_args
4041

4142

@@ -506,6 +507,9 @@ the number of parallel build jobs to use""",
506507
parser.add_argument("--darwin-xcrun-toolchain",
507508
help="the name of the toolchain to use on Darwin",
508509
default="default")
510+
parser.add_argument("--cmake",
511+
help="the path to a CMake executable that will be "
512+
"used to build Swift")
509513

510514
parser.add_argument("--extra-swift-args", help=textwrap.dedent("""
511515
Pass through extra flags to swift in the form of a cmake list 'module_regexp;flag'. Can
@@ -518,7 +522,9 @@ the number of parallel build jobs to use""",
518522
nargs="*")
519523

520524
args = parser.parse_args(migrate_impl_args(sys.argv[1:], [
521-
'--darwin-xcrun-toolchain']))
525+
'--darwin-xcrun-toolchain',
526+
'--cmake',
527+
]))
522528

523529
# Build cmark if any cmark-related options were specified.
524530
if (args.cmark_build_variant is not None):
@@ -728,12 +734,21 @@ the number of parallel build jobs to use""",
728734
print_with_argv0(
729735
"Can't find clang. Please install clang-3.5 or a later version.")
730736
return 1
737+
738+
host_cmake = args.cmake
739+
if not host_cmake:
740+
host_cmake = swift_build_support.cmake.host_cmake(
741+
args.darwin_xcrun_toolchain)
742+
if not host_cmake:
743+
print_with_argv0("Can't find CMake. Please install CMake.")
744+
return 1
731745
build_script_impl_args = [
732746
os.path.join(SWIFT_SOURCE_ROOT, "swift", "utils", "build-script-impl"),
733747
"--build-dir", build_dir,
734748
"--host-cc", host_clang.cc,
735749
"--host-cxx", host_clang.cxx,
736750
"--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain,
751+
"--cmake", host_cmake,
737752
"--cmark-build-type", args.cmark_build_variant,
738753
"--llvm-build-type", args.llvm_build_variant,
739754
"--swift-build-type", args.swift_build_variant,

utils/build-script-impl

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,19 @@ if [ ! -e "${WORKSPACE}" ] ; then
672672
exit 1
673673
fi
674674

675+
# FIXME: HOST_CC and CMAKE are set, and their presence is validated by,
676+
# utils/build-script. These checks are redundant, but must remain until
677+
# build-script-impl is merged completely with utils/build-script.
678+
# For additional information, see: https://bugs.swift.org/browse/SR-237
679+
if [ -z "${HOST_CC}" ] ; then
680+
echo "Can't find clang. Please install clang-3.5 or a later version."
681+
exit 1
682+
fi
683+
if [ -z "${CMAKE}" ] ; then
684+
echo "Environment variable CMAKE must be specified."
685+
exit 1
686+
fi
687+
675688
function xcrun_find_tool() {
676689
xcrun --sdk macosx --toolchain "${DARWIN_XCRUN_TOOLCHAIN}" --find "$@"
677690
}
@@ -701,14 +714,6 @@ function true_false() {
701714
# Set default values for command-line parameters.
702715
#
703716

704-
if [[ "${CMAKE}" == "" ]] ; then
705-
if [[ "$(uname -s)" == "Darwin" ]] ; then
706-
CMAKE="$(xcrun_find_tool cmake)"
707-
else
708-
CMAKE="$(which cmake || echo /usr/local/bin/cmake)"
709-
fi
710-
fi
711-
712717
if [[ "${INSTALL_PREFIX}" == "" ]] ; then
713718
if [[ "$(uname -s)" == "Darwin" ]] ; then
714719
INSTALL_PREFIX="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr"
@@ -1039,15 +1044,6 @@ if [[ "${EXPORT_COMPILE_COMMANDS}" ]] ; then
10391044
)
10401045
fi
10411046

1042-
# FIXME: HOST_CC is set and its presence is validated by utils/build-script.
1043-
# This check is redundant, but must remain until build-script-impl
1044-
# is merged completely with utils/build-script.
1045-
# For additional information, see: https://bugs.swift.org/browse/SR-237
1046-
if [ -z "${HOST_CC}" ] ; then
1047-
echo "Can't find clang. Please install clang-3.5 or a later version."
1048-
exit 1
1049-
fi
1050-
10511047
if [[ "${DISTCC}" ]] ; then
10521048
# On some platforms, 'pump' may be unrelated to distcc, in which case it's
10531049
# called 'distcc-pump'.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# swift_build_support/cmake.py - Detect host machine's CMake -*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
#
13+
# Find the path to a CMake executable on the host machine.
14+
#
15+
# ----------------------------------------------------------------------------
16+
17+
import platform
18+
19+
from . import xcrun
20+
from .which import which
21+
22+
23+
def host_cmake(xcrun_toolchain):
24+
"""
25+
Return the path to `cmake`, using tools provided by the host platform.
26+
If `cmake` cannot be found on OS X, return None.
27+
If `cmake` cannot be found on Linux, return a probable path.
28+
"""
29+
if platform.system() == 'Darwin':
30+
return xcrun.find(xcrun_toolchain, 'cmake')
31+
else:
32+
cmake = which('cmake')
33+
if cmake:
34+
return cmake
35+
else:
36+
return '/usr/local/bin/cmake'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# test_cmake.py - Unit tests for swift_build_support.cmake -*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
11+
import os
12+
import unittest
13+
14+
from swift_build_support.cmake import host_cmake
15+
16+
17+
class HostCMakeTestCase(unittest.TestCase):
18+
def test_cmake_available_on_this_platform(self):
19+
# Test that CMake is installed on this platform, as a means of
20+
# testing host_cmake().
21+
cmake = host_cmake(xcrun_toolchain='default')
22+
self.assertEqual(os.path.split(cmake)[-1], 'cmake')
23+
24+
25+
if __name__ == '__main__':
26+
unittest.main()

0 commit comments

Comments
 (0)