File: build-swift-repl.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (134 lines) | stat: -rw-r--r-- 2,952 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/env python

# build-swift-repl.py
#
# The Swift REPL must be built using the newly-built
# Swift compiler or we can't debug it.

import os
import re
import shutil
import sys

import lldbbuild

# Command-line interface


def check_args():
    if len(sys.argv) != 3:
        print "usage: " + sys.argv[0] + " REPL_EXECUTABLE REPL_SOURCE_FILE"
        sys.exit(1)


def repl_executable():
    return sys.argv[1]


def repl_source_file():
    return sys.argv[2]

# Xcode interface


def lldb_build_path():
    return os.environ.get('CONFIGURATION_BUILD_DIR')


def arch():
    return os.environ.get("ARCHS").split()[0]


def macosx_deployment_target():
    return os.environ.get("MACOSX_DEPLOYMENT_TARGET")


def repl_rpaths():
    return os.environ.get("REPL_SWIFT_RPATH").split()

# Arguments to swiftc


def module_cache_path():
    return os.path.join(lldb_build_path(), "repl_swift_module_cache")


def inhibit_repl():
    return False
   
def swiftc_path():
    ret = ""
    if os.environ.get("CONFIGURATION") == "BuildAndIntegration":
        ret = os.path.join(os.environ.get("TOOLCHAIN_DIR"), "usr", "bin", "swiftc")
    else:
        ret = os.path.join(
            lldbbuild.expected_package_build_path_for("swift"),
            "bin",
            "swiftc")
    print "swiftc is at " + ret
    return ret


def swift_target():
    deployment_target = macosx_deployment_target()
    if deployment_target is not None:
        return arch() + "-apple-macosx" + deployment_target
    else:
        return None


def target_arg_for_repl():
    target = swift_target()
    if target is not None:
        return ["-target", target]
    else:
        return []


def linker_args_for_rpath(rpath):
    return ["-Xlinker", "-rpath", "-Xlinker", rpath]


def linker_args_for_repl():
    return [
        arg for args in map(
            linker_args_for_rpath,
            repl_rpaths()) for arg in args]


def do_maybe_recursive_delete(path):
    if os.path.isdir(path):
        shutil.rmtree(path)
    assert (not os.path.exists(path))


def do_create_folder(path):
    os.makedirs(path)


def module_cache_args_for_repl():
    cache = module_cache_path()
    do_maybe_recursive_delete(cache)
    do_create_folder(cache)
    return ["-module-cache-path", cache]


def swiftc_args_for_repl():
    return [swiftc_path(),
            "-DXCODE_BUILD_ME"] + target_arg_for_repl() + ["-g",
                                                           "-o",
                                                           repl_executable(),
                                                           repl_source_file()] + module_cache_args_for_repl() + linker_args_for_repl()


def strip_args_for_repl():
    return ["strip", "-S", repl_executable()]

# Core logic

if not inhibit_repl():
	check_args()
	lldbbuild.run_in_directory(swiftc_args_for_repl(), lldb_build_path())
	lldbbuild.run_in_directory(strip_args_for_repl(), lldb_build_path())

sys.exit(0)