[gps-users] Small script to enable call to Makefiles from GPS.
Per Sandberg
per.sandberg at bredband.net
Wed Dec 28 11:15:34 CET 2005
This small script will enable calling to makefiles from the menus in GPS.
To enable just copy the file to a GPS plug-in directory.
/Per
-------------- next part --------------
"""
Makefile support
The intent of this package is to integrate calling to makefiles
in GPS.
there is two new Project-Attributes added in package "make"
make identifies the make command to use
Makefile identifies the Makefile to use.
Switches Extra switche to make.
Enhancents:
Add switches to the make.
The syntax in the make file is the folowig
{target}: # {menue entry}
sample makefile:
all: # Make all
How to make all.
clean: # clean all
How to clean all.
"""
import GPS
from os.path import *
import re
import sets
import os
class Console_Process (GPS.Console, GPS.Process):
def on_output (self, unmatched, matched):
self.write ("<" + unmatched+matched + ">")
GPS.Locations.parse(output= unmatched+matched,
category = "make results",
regexp="^([^:]:?[^:]*):(\d+):((\d+):)? ((warning)?(\(style)?.*)",
file_index =1,
line_index =2,
column_index=4,
style_index=7,
warning_index=6,
highlight_category="make results")
def on_exit (self, status, remaining_output):
# self.write (remaining_output)
# print "status:" + str(status)
# self.destroy ()
pass
def on_input (self, input):
self.send (input)
def on_destroy (self):
self.kill ()
def __init__ (self, process, args=""):
GPS.Locations.remove_category("make results")
GPS.Editor.register_highlighting("make results","#FF0000")
GPS.Console.__init__ (self, "",
on_input=Console_Process.on_input,
# on_destroy=Console_Process.on_destroy,
force=True)
GPS.Process.__init__ (self, process + ' ' + args, "^.+$",
on_exit=Console_Process.on_exit,
on_match=Console_Process.on_output)
def on_activate (self):
os.chdir(dirname(GPS.Project.root().file().name()))
Switches=GPS.Project.root().get_attribute_as_string("switches","make")
if len(Switches) <> 0:
args=Switches + " "
else:
args=""
args += "-f " + self.file + " " + self.target
make_command=GPS.Project.root().get_attribute_as_string("make","make")
Console_Process (make_command, args)
def EditFile (self):
GPS.Editor.edit(self.file)
menues=sets.Set()
def finalize():
"""Removes all current settings"""
global menues
for i in menues:
i.destroy()
def checkMakefile(self):
"""Tries to read the make file assiciated with the current project
and will append the tagged targets to the menue"""
global menues
finalize()
try:
Makefile=GPS.Project.root().get_attribute_as_string("makefile","make")
Makefile=join (dirname(GPS.Project.root().file().name()),Makefile)
if isfile(Makefile):
menues=sets.Set()
M=GPS.Menu.create("/Build/Makefile support/Edit Makefile",
on_activate=EditFile)
M.file=Makefile
menues.add(M)
f=file(Makefile)
matcher=re.compile("^(.+?):.+?#(.+)")
for i in f:
matches=matcher.match(i)
if matches:
M=GPS.Menu.create("/Build/Makefile support/" + matches.group(2),
on_activate=on_activate)
M.file=Makefile
M.target=matches.group(1)
menues.add(M)
f.close()
except:
pass
def initialize():
finalize()
GPS.parse_xml("""<project_attribute
name="makefile"
package="Make"
editor_section="Make"
description="Makefile to use for this project">
<string type="file"/>
</project_attribute>
<project_attribute
name="Make"
package="Make"
editor_section="Make"
description="Make command to use when parsing Makefile">
<string type="" default="make"/>
</project_attribute>
<project_attribute
name="Switches"
package="Make"
editor_section="Make"
description="Switches for the make command">
<string type="" default="-k"/>
</project_attribute>""")
GPS.Hook ("project_view_changed").add (checkMakefile)
initialize()
More information about the gps-users
mailing list