Ejemplo n.º 1
0
	def run(self, save = True):
		view = self.window.active_view()

		if save:
			view.run_command("save")

		if active_valid_go_view(self.window) is None:
			return

		from GoSublime.gosubl import gs, mg9
		from GoSublime.gs9o import active_wd

		wd = active_wd()

		env = get_goenv()

		cmd = ['install']
		if is_go_test_view(view):
			cmd = ['test', '-c', '-o', '/tmp/null']

		a = {
			'cid': '9go-%s' % wd,
			'env': env,
			'cwd': wd,
			'cmd': {
				'name': 'go',
				'args': cmd,
			}
		}

		win = sublime.active_window()
		panel = stash.get(self.panel_name)
		if not panel:
			panel = stash[self.panel_name] = win.get_output_panel(self.panel_name)

		def focus(out):
			lines = self.reg_lines.findall(out)
			if len(lines) > 0:
				f, n = lines[0]
				from os import path
				if not path.isabs(f):
					f = path.join(wd, f)
					sublime.set_timeout(lambda: win.open_file('%s:%s' % (f, n), sublime.ENCODED_POSITION), 0)

		def cb(res, err):
			out = res.get('err', '').strip()
			if out:
				gs.show_output('GoInstall', out, False, gs.tm_path('go'))
				focus(out)
			else:
				if panel is not None:
					sublime.set_timeout(lambda: win.run_command('hide_panel'), 0)
		sublime.set_timeout(lambda: mg9.acall('sh', a, cb), 0)
Ejemplo n.º 2
0
def get_goenv(setting = None):
	from GoSublime.gs9o import active_wd

	if not setting:
		setting = get_setting()
	senv = setting.get('env', {})

	wd = active_wd()

	gopath = [os.path.normpath(p) for p in os.environ.get('GOPATH', '').split(os.path.pathsep) if p]

	gsPath = senv.get('GOPATH', '')
	if gsPath.find('$GS_GOPATH') != -1:
		p = wd + os.path.sep
		i = p.find(os.path.sep + "src" + os.path.sep)
		if i != -1:
			gsPath = gsPath.replace('$GS_GOPATH', wd[:i])

	_p = gopath
	gopath = [os.path.normpath(p) for p in gsPath.split(os.path.pathsep)]
	gopath.extend(_p)

	GOPATH = []
	for p in gopath:
		if p and p != '.' and p not in GOPATH:
			GOPATH.append(p)

	env = os.environ.copy()
	env['GOPATH'] = os.path.pathsep.join(GOPATH)
	goos = senv.get('GOOS')
	goarch = senv.get('GOARCH')
	goroot = senv.get('GOROOT')
	if goos: env['GOOS'] = goos.lower()
	if goarch: env['GOARCH'] = goarch.lower()
	if goroot: env['GOROOT'] = goroot.lower()

	return env