go rework

This commit includes:
* a new go package that uses gccgo to bootstrap the go toolchain
* env support added to Executable
* a new Go fetch strategy that uses `go get` to fetch a package and all
  of its deps
* A platinum searcher package that leverages the new go package and
  fetch strategy
This commit is contained in:
Tom Scogland
2016-05-14 22:35:55 -07:00
parent 0816e9554d
commit 577657b3f7
5 changed files with 159 additions and 81 deletions

View File

@@ -1,6 +1,9 @@
import os
import shutil
import glob
from spack import *
class Go(Package):
"""The golang compiler and build environment"""
homepage = "https://golang.org"
@@ -10,43 +13,65 @@ class Go(Package):
# temporary fix until tags are pulled correctly
version('1.4.2', git='https://go.googlesource.com/go', tag='go1.4.2')
version('1.5.0', git='https://go.googlesource.com/go', tag='go1.5.0')
version('1.5.4', git='https://go.googlesource.com/go', tag='go1.5.4')
version('1.6.2', git='https://go.googlesource.com/go', tag='go1.6.2')
variant('test',
default=True,
description="Run tests as part of build, a good idea but quite"
" time consuming")
provides('go_compiler')
# to-do, make non-c self-hosting compilers possible
provides('golang')
# to-do, make non-c self-hosting compilers feasible without backflips
# should be go_compiler, but that creates an infinite loop
depends_on('gcc', when='@1.5:')
depends_on('gcc@5:', when='@1.5:')
depends_on('git')
def install(self, spec, prefix):
os.environ['GOROOT'] = os.getcwd()
os.environ['GOROOT_FINAL'] = prefix
bash = which('bash')
bash('-c', 'env')
bash('-c', 'pwd')
with working_dir('src'):
#TODO: crutch until the read-only-filesystem bug is fixed upstream
bash('all.bash', fail_on_error=False)
cp = which('cp')
bash('-c', 'cp -r ./* "{}"'.format(prefix))
bash = which('bash')
with working_dir('src'):
if '+test' in spec:
bash('all.bash')
else:
bash('make.bash')
def setup_dependent_environment(self, module, spec, ext_spec):
try:
os.makedirs(prefix)
except OSError:
pass
for f in glob.glob('*'):
if os.path.isdir(f):
shutil.copytree(f, os.path.join(prefix, f))
else:
shutil.copy2(f, os.path.join(prefix, f))
def setup_environment(self, spack_env, run_env):
# spack_env.set("GOROOT", self.spec.prefix)
# run_env.set("GOROOT", self.spec.prefix)
spack_env.set('GOROOT_FINAL', self.spec.prefix)
spack_env.set('GOROOT_BOOTSTRAP', self.spec['gcc'].prefix)
def setup_dependent_package(self, module, ext_spec):
# Add a go command/compiler for extensions
module.go = Executable(join_path(self.spec.prefix.bin, 'go'))
def setup_dependent_environment(self, spack_env, run_env, ext_spec):
"""Called before go modules' install() methods.
In most cases, extensions will only need to have one line::
go('get', '<package>')
go('get', '<package>')
"""
# Add a go command for extensions
module.go = Executable(join_path(spec.prefix.bin, 'go'))
os.environ['GOROOT'] = spec.prefix
stage_path = os.path.realpath(ext_spec.package.stage.source_path)
print "PREFIX: {}".format(stage_path)
go_paths = [stage_path]
for d in ext_spec.traverse():
if d.package.extends(self.spec):
go_paths.append(d.prefix)
os.environ['GOPATH'] = ':'.join(go_paths)
# spack_env.set("GOROOT", self.spec.prefix)
# run_env.set("GOROOT", self.spec.prefix)
# stage_path = os.path.realpath(ext_spec.package.stage.source_path)
# print "PREFIX: {}".format(stage_path)
# go_paths = [stage_path]
# for d in ext_spec.traverse():
# if d.package.extends(self.spec):
# go_paths.append(d.prefix)
# spack_env.prepend_path('GOPATH', ':'.join(go_paths))
spack_env.set('GOPATH', ext_spec.package.stage.source_path)