def main(): parser = argparse.ArgumentParser(description='cross compile build for golang') parser.add_argument('--repo', dest='repo', required=True) parser.add_argument('--tag', dest='tag', default='branch:master') args = parser.parse_args() global reponame reponame = args.repo tag = args.tag outjson['repo'] = reponame outjson['tag'] = tag outjson['created'] = int(time.time()) outjson['version'] = '%s%s' %(sh.go.version(), sh.gopm('-v')) outjson['files'] = {} print 'Fetching', reponame fetch(reponame, tag) rdir = pathjoin(os.getenv('GOPATH'), 'src', args.repo) os.chdir(rdir) # change directory outjson['gobuildrc'] = open('.gobuild.yml').read() if os.path.exists('.gobuild.yml') else '# nothing' os_archs = [('linux','amd64'), ('linux','386'), ('linux','arm'), ('windows','amd64'), ('windows','386'), ('darwin','amd64'), ('darwin','386')] for goos, arch in os_archs: print '\033[92mBuilding for %s,%s\033[0m' %(goos, arch) # green color env = {} if goos == 'darwin': exportenv = str(sh.bash('-c', osxenv)) for (key, value) in re.findall(r'export\s+([\w_]+)=([^\s]+)', exportenv): env[key] = value build(goos, arch, env=env) outjson['time_used'] = int(time.time())-outjson['created'] print 'Saving state to out.json' print '------------ out.json -------------' with open(pathjoin(OUTDIR, 'out.json'), 'w') as f: json.dump(outjson, f) print json.dumps(outjson, indent=4)
def fetch(reponame, tag): print BASHPS1+'gopm --strict get -v -d %s@%s' %(reponame, tag) sh.gopm('--strict', 'get', '-v', '-d', reponame+'@'+tag, _err_to_out=True, _out=sys.stdout) print BASHPS1+'go get -v -d %s' %(reponame) sh.go.get('-v', '-d', reponame, _err_to_out=True, _out=sys.stdout)