ghc: Remove warning of StaticPointers not being supported by GHCi
[ghc.git] / boot
1 #!/usr/bin/env python3
2
3 import glob
4 import os
5 import os.path
6 import sys
7 import argparse
8 from textwrap import dedent
9 import subprocess
10 import re
11
12 cwd = os.getcwd()
13
14 parser = argparse.ArgumentParser()
15 parser.add_argument('--validate', action='store_true', help='Run in validate mode')
16 parser.add_argument('--required-tag', type=str, action='append', default=set())
17 parser.add_argument('--hadrian', action='store_true', help='Do not assume the make base build system')
18 args = parser.parse_args()
19
20 def print_err(s):
21     print(dedent(s), file=sys.stderr)
22
23 def die(mesg):
24     print_err(mesg)
25     sys.exit(1)
26
27 def check_for_url_rewrites():
28     if os.path.isdir('.git') and \
29        subprocess.check_output('git config remote.origin.url'.split()).find(b'github.com') != -1 and \
30        subprocess.call(['git', 'config', '--get-regexp', '^url.*github.com/.*/packages-.insteadOf']) != 0:
31         # If we cloned from github, make sure the url rewrites are set.
32         # Otherwise 'git submodule update --init' prints confusing errors.
33         die("""\
34             It seems you cloned this repository from GitHub. But your git config files
35             don't contain the url rewrites that are needed to make this work (GitHub
36             doesn't support '/' in repository names, so we use a different naming scheme
37             for the submodule repositories there).
38
39             Please run the following commands first:
40
41               git config --global url."git://github.com/ghc/packages-".insteadOf     git://github.com/ghc/packages/
42               git config --global url."http://github.com/ghc/packages-".insteadOf    http://github.com/ghc/packages/
43               git config --global url."https://github.com/ghc/packages-".insteadOf   https://github.com/ghc/packages/
44               git config --global url."ssh://git\@github.com/ghc/packages-".insteadOf ssh://git\@github.com/ghc/packages/
45               git config --global url."git\@github.com:/ghc/packages-".insteadOf      git\@github.com:/ghc/packages/
46
47             And then:
48
49               git submodule update --init
50               ./boot
51
52             Or start over, and clone the GHC repository from the haskell server:
53
54               git clone --recursive git://git.haskell.org/ghc.git
55
56             For more information, see:
57               * https://ghc.haskell.org/trac/ghc/wiki/Newcomers or
58               * https://ghc.haskell.org/trac/ghc/wiki/Building/GettingTheSources#CloningfromGitHub
59         """)
60
61 def check_boot_packages():
62     # Check that we have all boot packages.
63     import re
64     for l in open('packages', 'r'):
65         if l.startswith('#'):
66             continue
67
68         parts = l.split(' ')
69         if len(parts) != 4:
70             die("Error: Bad line in packages file: " + l)
71
72         dir_ = parts[0]
73         tag = parts[1]
74
75         # If $tag is not "-" then it is an optional repository, so its
76         # absence isn't an error.
77         if tag in args.required_tag:
78             # We would like to just check for a .git directory here,
79             # but in an lndir tree we avoid making .git directories,
80             # so it doesn't exist. We therefore require that every repo
81             # has a LICENSE file instead.
82             license_path = os.path.join(dir_, 'LICENSE')
83             if not os.path.isfile(license_path):
84                 die("""\
85                     Error: %s doesn't exist" % license_path)
86                     Maybe you haven't run 'git submodule update --init'?
87                     """)
88
89 # Create libraries/*/{ghc.mk,GNUmakefile}
90 def boot_pkgs():
91     library_dirs = []
92
93     for package in glob.glob("libraries/*/"):
94         packages_file = os.path.join(package, 'ghc-packages')
95         if os.path.isfile(packages_file):
96             for subpkg in open(packages_file, 'r'):
97                 library_dirs.append(os.path.join(package, subpkg.strip()))
98         else:
99             library_dirs.append(package)
100
101     for package in library_dirs:
102         if package[-1] == '/':
103             # drop trailing '/'
104             package = package[:-1]
105
106         dir_ = os.path.relpath(package, 'libraries')
107         cabals = glob.glob(os.path.join(package, '*.cabal.in'))
108         if len(cabals) == 0:
109             cabals = glob.glob(os.path.join(package, '*.cabal'))
110
111         if len(cabals) > 1:
112             die('Too many .cabal files in %s' % package)
113         elif len(cabals) == 1:
114             cabal = cabals[0]
115
116             if os.path.isfile(cabal):
117                 # strip both .cabal and .in
118                 pkg = os.path.splitext(os.path.splitext(os.path.basename(cabal))[0])[0]
119                 top = os.path.join(*['..'] * len(os.path.normpath(package).split(os.path.sep)))
120
121                 ghc_mk = os.path.join(package, 'ghc.mk')
122                 print('Creating %s' % ghc_mk)
123                 with open(ghc_mk, 'w') as f:
124                     f.write(dedent(
125                         """\
126                         {package}_PACKAGE = {pkg}
127                         {package}_dist-install_GROUP = libraries
128                         $(if $(filter {dir},$(PACKAGES_STAGE0)),$(eval $(call build-package,{package},dist-boot,0)))
129                         $(if $(filter {dir},$(PACKAGES_STAGE1)),$(eval $(call build-package,{package},dist-install,1)))
130                         $(if $(filter {dir},$(PACKAGES_STAGE2)),$(eval $(call build-package,{package},dist-install,2)))
131                         """.format(package = package,
132                                 pkg = pkg,
133                                 dir = dir_)))
134
135                 makefile = os.path.join(package, 'GNUmakefile')
136                 with open(makefile, 'w') as f:
137                     f.write(dedent(
138                         """\
139                         dir = {package}
140                         TOP = {top}
141                         include $(TOP)/mk/sub-makefile.mk
142                         FAST_MAKE_OPTS += stage=0
143                         """.format(package = package, top = top)
144                     ))
145
146
147 def autoreconf():
148     # Run autoreconf on everything that needs it.
149     processes = {}
150     if os.name == 'nt':
151         # Get the normalized ACLOCAL_PATH for Windows
152         # This is necessary since on Windows this will be a Windows
153         # path, which autoreconf doesn't know doesn't know how to handle.
154         ac_local = os.getenv('ACLOCAL_PATH', '')
155         ac_local_arg = re.sub(r';', r':', ac_local)
156         ac_local_arg = re.sub(r'\\', r'/', ac_local_arg)
157         ac_local_arg = re.sub(r'(\w):/', r'/\1/', ac_local_arg)
158         reconf_cmd = 'ACLOCAL_PATH=%s autoreconf' % ac_local_arg
159     else:
160         reconf_cmd = 'autoreconf'
161
162     for dir_ in ['.'] + glob.glob('libraries/*/'):
163         if os.path.isfile(os.path.join(dir_, 'configure.ac')):
164             print("Booting %s" % dir_)
165             processes[dir_] = subprocess.Popen(['sh', '-c', reconf_cmd], cwd=dir_)
166
167     # Wait for all child processes to finish.
168     fail = False
169     for k,v in processes.items():
170         code = v.wait()
171         if code != 0:
172             print_err('autoreconf in %s failed with exit code %d' % (k, code))
173             fail = True
174
175     if fail:
176         sys.exit(1)
177
178 def check_build_mk():
179     if not args.validate and not os.path.isfile("mk/build.mk"):
180         print(dedent(
181             """
182             WARNING: You don't have a mk/build.mk file.
183
184             By default a standard GHC build will be done, which uses optimisation
185             and builds the profiling libraries. This will take a long time, so may
186             not be what you want if you are developing GHC or the libraries, rather
187             than simply building it to use it.
188
189             For information on creating a mk/build.mk file, please see:
190                 http://ghc.haskell.org/trac/ghc/wiki/Building/Using#Buildconfiguration
191             """))
192
193 check_for_url_rewrites()
194 if not args.hadrian:
195     boot_pkgs()
196 autoreconf()
197 if not args.hadrian:
198     check_build_mk()