Skip to content

Commit db8c618

Browse files
pipcl.py: swig_get(): also download/build/install bison if required.
1 parent d350c64 commit db8c618

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

pipcl.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,48 @@ def swig_get(swig, quick, swig_local='pipcl-swig-git'):
33483348
if quick and os.path.isfile(swig_binary):
33493349
log1(f'{quick=} and {swig_binary=} already exists, so not downloading/building.')
33503350
else:
3351+
# Building swig requires bison>=3.5.
3352+
bison_ok = 0
3353+
e, text = run(f'bison --version', capture=1, check=0)
3354+
if not e:
3355+
log(textwrap.indent(text, ' '))
3356+
m = re.search('bison (GNU Bison) ([0-9]+)[.]([0-9]+)', text)
3357+
if m:
3358+
assert m, f'Unexpected output from `bison --version`: {text!r}'
3359+
version_tuple = int(m.group(1)), int(m.group2())
3360+
if version_tuple >= (3, 5):
3361+
bison_ok = 1
3362+
if not bison_ok:
3363+
if 0:
3364+
# Use git checkout. Fails to find scan-code.c. Presumably
3365+
# something wrong with ./bootstrap?
3366+
log(f'Cloning/fetching/build/installing bison.')
3367+
bison_git = git_get(
3368+
'pipcl-bison-git',
3369+
remote='https://git.savannah.gnu.org/git/bison.git',
3370+
#branch='master',
3371+
tag='v3.5.4',
3372+
submodules=0, # recursive update fails.
3373+
)
3374+
run(f'cd {bison_git} && git submodule update --init', prefix='bison git submodule update --init: ')
3375+
run(f'cd {bison_git} && ./bootstrap', prefix='bison bootstrap: ')
3376+
run(f'cd {bison_git} && ./configure', prefix='bison configure: ')
3377+
run(f'cd {bison_git} && make', prefix='bison make: ')
3378+
run(f'cd {bison_git} && sudo make install', prefix='bison make install: ')
3379+
else:
3380+
bison_version = 'bison-3.5.4'
3381+
if not os.path.exists(f'{bison_version}.tar.gz'):
3382+
run(
3383+
f'wget -O {bison_version}.tar.gz-0 http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/bison/{bison_version}.tar.gz',
3384+
prefix='bison wget: ',
3385+
)
3386+
os.rename(f'{bison_version}.tar.gz-0', f'{bison_version}.tar.gz')
3387+
if not os.path.exists(f'{bison_version}'):
3388+
run(f'tar -xzf {bison_version}.tar.gz', prefix='bison extract: ')
3389+
run(f'cd {bison_version} && ./configure', prefix='bison configure: ')
3390+
run(f'cd {bison_version} && make', prefix='bison make: ')
3391+
run(f'cd {bison_version} && sudo make install', prefix='bison make install: ')
3392+
33513393
# Clone swig.
33523394
swig_env_extra = None
33533395
swig_local = git_get(
@@ -3373,6 +3415,7 @@ def swig_get(swig, quick, swig_local='pipcl-swig-git'):
33733415
macos_add_brew_path('bison', swig_env_extra)
33743416
run(f'which bison')
33753417
run(f'which bison', env_extra=swig_env_extra)
3418+
33763419
# Build swig.
33773420
run(f'cd {swig_local} && ./autogen.sh', env_extra=swig_env_extra)
33783421
run(f'cd {swig_local} && ./configure --prefix={swig_local}/install-dir', env_extra=swig_env_extra)

0 commit comments

Comments
 (0)