aboutsummaryrefslogtreecommitdiff
path: root/llvm_extra/create_ebuild_file.py
blob: 459e702aa57b8dfe8e3f4c74d238e684a0fde968 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python2

# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function

import os
import sys

# This script takes an existing host llvm compiler ebuild and
# creates another build that should be installable in a prefixed location.
# The script patches a few lines in the llvm ebuild to make that happen.
#
# Since the script is based on the current llvm ebuild patterns,
# it may need to be updated if those patterns change.
#
# This script should normally be invoked by the shell script
# create_llvm_extra.sh .

"""
Below is an example of the expected diff of the newly generated ebuild with
some explanation of the diffs.

diff -Nuar llvm-pre7.0_pre335547_p20180529.ebuild newly-created-file.ebuild
--- llvm-7.0_pre331547_p20180529-r8.ebuild
+++ newly-created-file.ebuild

@@ -60,9 +60,9 @@ EGIT_REPO_URIS=(
 fi

 LICENSE="UoI-NCSA"
-SLOT="0/${PV%%_*}"
+SLOT="${PV%%_p[[:digit:]]*}" # Creates a unique slot so that multiple copies
                                of the new build can be installed.

 KEYWORDS="-* amd64"

 # Change USE flags to match llvm ebuild installtion. To see the set of flags
 enabled in llvm compiler ebuild, run $ sudo emerge -pv llvm

-IUSE="debug +default-compiler-rt +default-libcxx doc libedit +libffi multitarget
+IUSE="debug +default-compiler-rt +default-libcxx doc libedit +libffi +multitarget
        ncurses ocaml python llvm-next llvm-tot test xml video_cards_radeon"

 COMMON_DEPEND="
@@ -145,6 +145,7 @@ pkg_pretend() {
 }

 pkg_setup() {
 # This Change is to install the files in $PREFIX.
+       export PREFIX="/usr/${PN}/${SLOT}"
        pkg_pretend
 }

@@ -272,13 +273,13 @@
        sed -e "/RUN/s/-warn-error A//" -i test/Bindings/OCaml/*ml  || die

        # Allow custom cmake build types (like 'Gentoo')
 # Convert use of PN to llvm in epatch commands.
-       epatch "${FILESDIR}"/cmake/${PN}-3.8-allow_custom_cmake_build_types.patch
+       epatch "${FILESDIR}"/cmake/llvm-3.8-allow_custom_cmake_build_types.patch

        # crbug/591436
        epatch "${FILESDIR}"/clang-executable-detection.patch

        # crbug/606391
-       epatch "${FILESDIR}"/${PN}-3.8-invocation.patch
+       epatch "${FILESDIR}"/llvm-3.8-invocation.patch

@@ -411,11 +412,14 @@ src_install() {
                /usr/include/llvm/Config/llvm-config.h
        )

+       MULTILIB_CHOST_TOOLS=() # No need to install any multilib tools/headers.
+       MULTILIB_WRAPPED_HEADERS=()
        multilib-minimal_src_install
 }

 multilib_src_install() {
        cmake-utils_src_install
+       return # No need to install any wrappers.

        local wrapper_script=clang_host_wrapper
        cat "${FILESDIR}/clang_host_wrapper.header" \
@@ -434,6 +438,7 @@ multilib_src_install() {
 }

 multilib_src_install_all() {
+       return # No need to install common multilib files.
        insinto /usr/share/vim/vimfiles
        doins -r utils/vim/*/.
        # some users may find it useful
"""

def process_line(line, text):
  # Process the line and append to the text we want to generate.
  # Check if line has any patterns that we want to handle.
  newline = line.strip()
  if newline.startswith('#'):
    # Do not process comment lines.
    text.append(line)
  elif line.startswith('SLOT='):
    # Change SLOT to "${PV%%_p[[:digit:]]*}"
    SLOT_STRING='SLOT="${PV%%_p[[:digit:]]*}"\n'
    text.append(SLOT_STRING)
  elif line.startswith('IUSE') and 'multitarget' in line:
    # Enable multitarget USE flag.
    newline = line.replace('multitarget', '+multitarget')
    text.append(newline)
  elif line.startswith('pkg_setup()'):
    # Setup PREFIX.
    text.append(line)
    text.append('\texport PREFIX="/usr/${PN}/${SLOT}"\n')
  elif line.startswith('multilib_src_install_all()'):
    text.append(line)
    # Do not install any common files.
    text.append('\treturn\n')
  elif 'epatch ' in line:
    # Convert any $PN or ${PN} in epatch files to llvm.
    newline = line.replace('$PN', 'llvm')
    newline = newline.replace('${PN}', 'llvm')
    text.append(newline)
  elif 'multilib-minimal_src_install' in line:
    # Disable MULTILIB_CHOST_TOOLS and MULTILIB_WRAPPED_HEADERS
    text.append('\tMULTILIB_CHOST_TOOLS=()\n')
    text.append('\tMULTILIB_WRAPPED_HEADERS=()\n')
    text.append(line)
  elif 'cmake-utils_src_install' in line:
    text.append(line)
    # Do not install any wrappers.
    text.append('\treturn\n')
  else:
    text.append(line)


def main():
  if len(sys.argv) != 3:
     filename = os.path.basename(__file__)
     print ('Usage: ', filename,' <input.ebuild> <output.ebuild>')
     return 1

  text = []
  with open(sys.argv[1], 'r') as infile:
    for line in infile:
      process_line(line, text)

  with open(sys.argv[2], 'w') as outfile:
    outfile.write("".join(text))

  return 0


if __name__== "__main__":
  sys.exit(main())