Skip to content

Commit

Permalink
gccgo fixes. Make basedir work with GoPackages. Other tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
alberts committed Dec 16, 2010
1 parent 2f6b826 commit 016d86f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -29,7 +29,7 @@ To get started, do the following:
6. Set PYTHONPATH in your environment to point to the top-level
goscons directory.

7. Look in test.sh and the prj[1234] directories for some examples.
7. Look in test.sh and the prj[12345] directories for some examples.

If PYTHONPATH is set, the following SConstruct should work to build a
simple Go project:
Expand Down
22 changes: 3 additions & 19 deletions goscons/gccgo.py
Expand Up @@ -13,36 +13,20 @@ def find_package(env, pkg, path):
return pkgpath
return None

def _go_prefix(source, env):
prefix = env.subst('${GOPREFIX}') + goutils.package_name(source[0], env)
if len(prefix) > 0:
return '-fgo-prefix=' + prefix
return ''

def _go_rpath(lst, env, f=lambda x: x, target=None, source=None):
if not lst: return lst
l = f(SCons.PathList.PathList(lst).subst_path(env, target, source))
if l is not None: lst = l
return ' '.join(['-Wl,-rpath,' + p.abspath for p in lst])

def generate(env):
env['_go_prefix'] = _go_prefix
env['_go_rpath'] = _go_rpath
env['GCCGOPREFIX'] = '/usr/local'
env['GOC'] = 'gccgo'
env['GOLINK'] = 'gccgo'
env['GOOBJSUFFIX'] = '.o'
env['GOLIBPREFIX'] = 'lib'
env['GOLIBSUFFIX'] = '.a'
env['GOCCOM'] = '$GOC ${_go_prefix(SOURCES, __env__)} -pipe $GOCFLAGS ${_concat("-I ", GOPKGPATH, "", __env__)} -c -o $TARGET $SOURCES'
#env['GOLINKCOM'] = '$GOC -pipe -static -pthread $GOLINKFLAGS ${_concat("-I ", GOPKGPATH, "", __env__)} ${_go_rpath(GORPATH, __env__)} -o $TARGET $SOURCES -lgobegin -lgo'
env['GOLINKCOM'] = '$GOC -pipe -static -pthread $GOLINKFLAGS ${_go_rpath(GORPATH, __env__)} -o $TARGET $SOURCES -lgobegin -lgo'
env['GOCCOM'] = '$GOC $FGOPREFIX -pipe $GOCFLAGS ${_concat("-I ", GOPKGPATH, "", __env__)} -c -o $TARGET $SOURCES'
env['GOLINKCOM'] = '$GOC -pipe -static -pthread $GOLINKFLAGS -o $TARGET $SOURCES -lgobegin -lgo'
env['GOPACK'] = 'ar'
env['GOPACKFLAGS'] = SCons.Util.CLVar('cru')
env['GOPACKCOM'] = '$GOPACK $GOPACKFLAGS $TARGET $SOURCES'
# TODO pkgpath depends on arch
env['GOPKGPATH'] = ['$GOPROJPKGPATH', '$GCCGOPREFIX/lib64']
env['GORPATH'] = ['$GOPROJPKGPATH']
env['GOPKGPATH'] = ['$GOPROJPKGPATH', '$GODEPPKGPATH', '$GCCGOPREFIX/lib64']
env.AddMethod(find_package, 'FindGoPackage')

def exists(env):
Expand Down
1 change: 0 additions & 1 deletion goscons/gocmd.py
Expand Up @@ -3,7 +3,6 @@
import goutils
import os.path

# TODO need to propogate args, kw into env
def gocommand(env, srcdir, *args, **kw):
fs = SCons.Node.FS.get_default_fs()
srcdir = fs.Dir(srcdir)
Expand Down
18 changes: 9 additions & 9 deletions goscons/gopkg.py
Expand Up @@ -19,7 +19,6 @@ def gotest(env, pkg, srcdir, gofiles, cgo_obj, *args, **kw):
bin = env.Golink(srcdir.File(env.subst('$GOTESTBIN')), testmain_obj, GOPKGPATH=gopkgpath)
return bin

# TODO need to propogate args, kw into env
def gopackage(env, srcdir, basedir=None, *args, **kw):
fs = SCons.Node.FS.get_default_fs()
srcdir = fs.Dir(srcdir)
Expand All @@ -39,14 +38,16 @@ def gopackage(env, srcdir, basedir=None, *args, **kw):
cgo_out = env.Cgo(cgofiles, CGOPKGPATH=os.sep.join(pkgparts[:-1]), *args, **kw)
gofiles += filter(lambda x: x.name.endswith('.go'), cgo_out)

gofiles = unique_files(gofiles)
pkg_path = basedir.rel_path(srcdir)
pkgname_ = pkg_path.replace(os.sep, '_')

gofiles = unique_files(gofiles)
objfiles = []
obj = env.subst('_go_$GOOBJSUFFIX')
# calculate a prefix for gccgo
projprefix = os.path.split(fs.Dir('#').abspath)[-1] + '_'
if len(gofiles) > 0:
objfiles += env.Goc(srcdir.File(obj), gofiles, GOPREFIX=projprefix, *args, **kw)
projprefix = os.path.split(fs.Dir('#').abspath)[-1]
fgoprefix = '-fgo-prefix=' + projprefix + '_' + pkgname_
objfiles += env.Goc(srcdir.File(obj), gofiles, FGOPREFIX=fgoprefix, *args, **kw)

if len(cgofiles)>0:
cflags = '-FVw -I"$GOROOT/src/pkg/runtime"'
Expand All @@ -64,11 +65,9 @@ def gopackage(env, srcdir, basedir=None, *args, **kw):
else:
cgo_obj = []

pkg_path = basedir.rel_path(srcdir)
test = gotest(env, pkg_path, srcdir, gofiles, cgo_obj)
if env['GODEP_BUILD']: test = []
for t in test:
pkgname_ = basedir.rel_path(srcdir).replace(os.sep, '_')
alias = 'test_%s' % pkgname_
a = env.Alias(alias, t, '${SOURCES.abspath} $GOTESTARGS')
env.AlwaysBuild(a)
Expand All @@ -91,10 +90,11 @@ def gopackage(env, srcdir, basedir=None, *args, **kw):
env.Alias('goinstall', env.InstallAs(goroot_path, pkg[0], *args, **kw))
return installed_pkg

def gopackages(env, basedir, *args, **kw):
def gopackages(env, topdir, basedir=None, *args, **kw):
if not basedir: basedir = topdir
fs = SCons.Node.FS.get_default_fs()
pkgdirs = []
for root, dirs, files in os.walk(basedir, True):
for root, dirs, files in os.walk(topdir, True):
alldirs = set(dirs)
skipdirs = set()
for d in dirs:
Expand Down
2 changes: 2 additions & 0 deletions goscons/goscanner.py
Expand Up @@ -11,6 +11,8 @@ def resolve_pkg(pkg, env, path, node):
pkgpath = env.FindGoPackage(pkg, path)
if pkgpath is None:
if goutils.scons_clean: return []
# TODO workaround until we have a proper scanner
if 'GCCGOPREFIX' in env: return []
raise SCons.Errors.UserError, 'Package "%s" not found while scanning %s' % (pkg, node)
return [pkgpath]

Expand Down
6 changes: 4 additions & 2 deletions test.sh
@@ -1,8 +1,10 @@
#!/bin/bash
set -xe

rm -rf prj[1234]/bin
rm -rf prj[1234]/pkg
rm -rf prj[12345]/bin
rm -rf prj[12345]/pkg

scons

scons -C prj1 -f SConstruct -c
scons -C prj1 -f SConstruct --random -j16
Expand Down

0 comments on commit 016d86f

Please sign in to comment.