Skip to content

Commit

Permalink
Build settings done
Browse files Browse the repository at this point in the history
  • Loading branch information
amirgeva committed Sep 30, 2014
1 parent 1bc6eee commit b3c2aa1
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 23 deletions.
38 changes: 34 additions & 4 deletions buildsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,54 @@ def setCombo(cb,value):
return

class BuildSettingsDialog(QtGui.QDialog):
def __init__(self,mainwin,parent=None):
def __init__(self,mainwin,startPath,parent=None):
super(BuildSettingsDialog,self).__init__(parent)
self.mainWindow=mainwin
uis.loadDialog('build_settings',self)
self.settingsGroup.setDisabled(True)
self.defaults.stateChanged.connect(self.defaultsToggled)
self.workspaceItem=QtGui.QTreeWidgetItem(['Workspace'])
self.mainWindow.workspaceTree.addProjectsToTree(self.workspaceItem)
self.workspaceDir=self.workspaceItem.data(0,DirectoryRole).toString()
self.projTree.addTopLevelItem(self.workspaceItem)
self.workspaceItem.setExpanded(True)
self.projTree.itemSelectionChanged.connect(self.selectionChanged)
self.closeButton.clicked.connect(self.closeClicked)
self.prevPath=''
self.projTree.setCurrentItem(self.workspaceItem)
wsdir=self.workspaceItem.data(0,DirectoryRole).toString()
self.prevPath=os.path.join(wsdir,'mk.cfg')
firstItem=None
if startPath==self.workspaceDir:
firstItem=self.workspaceItem
else:
firstItem=self.findItem(self.workspaceItem,startPath)
if not firstItem:
firstItem=self.workspaceItem
self.projTree.setCurrentItem(firstItem)
self.projTree.scrollToItem(firstItem)
dir=firstItem.data(0,DirectoryRole).toString()
self.prevPath=os.path.join(dir,'mk.cfg')

def findItem(self,parent,path):
n=parent.childCount()
for i in xrange(0,n):
item=parent.child(i)
dir=item.data(0,DirectoryRole).toString()
if dir==path:
return item
res=self.findItem(item,path)
if res:
return res
return None

def closeClicked(self):
self.save(self.prevPath)
self.close()

def defaultsToggled(self,state):
if state==QtCore.Qt.Checked:
self.settingsGroup.setDisabled(True)
else:
self.settingsGroup.setEnabled(True)

def selectionChanged(self):
if self.prevPath:
self.save(self.prevPath)
Expand All @@ -80,6 +108,7 @@ def load(self,path):
setCombo(self.optCB,getStr(props,'OPT','-O2'))
setCombo(self.warnCB,getStr(props,'WARN','Default'))
check(self.pedantic,getBool(props,'PEDANTIC',False))
check(self.warnErrors,getBool(props,'WARNERR',False))
self.customFlags.setPlainText(getStr(props,'CUSTOM',''))

def save(self,path):
Expand All @@ -88,6 +117,7 @@ def save(self,path):
setStr(props,'OPT',self.optCB.currentText())
setStr(props,'WARN',self.warnCB.currentText())
setBool(props,'PEDANTIC',getCheck(self.pedantic))
setBool(props,'WARNERR',getCheck(self.warnErrors))
setStr(props,'CUSTOM',self.customFlags.toPlainText())
props.save(path)

10 changes: 5 additions & 5 deletions gen/build_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'uis/build_settings.ui'
#
# Created: Tue Sep 30 15:04:51 2014
# Created: Tue Sep 30 19:39:29 2014
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -62,9 +62,9 @@ def setupUi(self, BuildSettingsDialog):
BuildSettingsDialog.pedantic = QtGui.QCheckBox(BuildSettingsDialog.settingsGroup)
BuildSettingsDialog.pedantic.setGeometry(QtCore.QRect(16, 80, 161, 22))
BuildSettingsDialog.pedantic.setObjectName(_fromUtf8("pedantic"))
BuildSettingsDialog.checkBox = QtGui.QCheckBox(BuildSettingsDialog.settingsGroup)
BuildSettingsDialog.checkBox.setGeometry(QtCore.QRect(16, 112, 201, 22))
BuildSettingsDialog.checkBox.setObjectName(_fromUtf8("checkBox"))
BuildSettingsDialog.warnErrors = QtGui.QCheckBox(BuildSettingsDialog.settingsGroup)
BuildSettingsDialog.warnErrors.setGeometry(QtCore.QRect(16, 112, 201, 22))
BuildSettingsDialog.warnErrors.setObjectName(_fromUtf8("warnErrors"))
BuildSettingsDialog.customFlags = QtGui.QPlainTextEdit(BuildSettingsDialog.settingsGroup)
BuildSettingsDialog.customFlags.setGeometry(QtCore.QRect(16, 208, 257, 91))
BuildSettingsDialog.customFlags.setObjectName(_fromUtf8("customFlags"))
Expand Down Expand Up @@ -92,7 +92,7 @@ def retranslateUi(self, BuildSettingsDialog):
BuildSettingsDialog.warnCB.setItemText(1, _translate("BuildSettingsDialog", "None (-w)", None))
BuildSettingsDialog.warnCB.setItemText(2, _translate("BuildSettingsDialog", "All (-Wall)", None))
BuildSettingsDialog.pedantic.setText(_translate("BuildSettingsDialog", "Pedantic", None))
BuildSettingsDialog.checkBox.setText(_translate("BuildSettingsDialog", "Warnings as errors", None))
BuildSettingsDialog.warnErrors.setText(_translate("BuildSettingsDialog", "Warnings as errors", None))
BuildSettingsDialog.label_3.setText(_translate("BuildSettingsDialog", "Custom Flags", None))
BuildSettingsDialog.closeButton.setText(_translate("BuildSettingsDialog", "Close", None))

2 changes: 1 addition & 1 deletion gen/debug_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'uis/debug_settings.ui'
#
# Created: Tue Sep 30 15:04:51 2014
# Created: Tue Sep 30 19:39:29 2014
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion gen/libsuggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'uis/libsuggest.ui'
#
# Created: Tue Sep 30 15:04:51 2014
# Created: Tue Sep 30 19:39:29 2014
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
Expand Down
55 changes: 49 additions & 6 deletions genmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
root=os.path.abspath('.')
#print ("ROOT={}".format(root))

def mkProps(props, dir):
path=os.path.join(dir,'mk.cfg')
if os.path.exists(path):
p=Properties(path)
if p.get("BUILD_DEFAULTS")!="True":
names=p.search('BUILD_.+')
for name in names:
if name!="BUILD_DEFAULTS":
props.assign(name,p.get(name))
return props

packages=listAllPackages()

class C:
Expand Down Expand Up @@ -71,7 +82,14 @@ def findMain(dir):
if re.search(pat,line):
return True
return False


flagsPat=re.compile('\((.+)\)')
def extractFlags(s):
m=re.search(flagsPat,s)
if m:
g=m.groups()
return g[0]
return ""

class Generator:
def __init__(self,root):
Expand Down Expand Up @@ -102,7 +120,7 @@ def scanWorkspace(self):
self.wsLibs[dirname]=os.path.relpath(dir,self.srcDir)


def generateConfig(self,dir,files,cfg,o):
def generateConfig(self,dir,files,cfg,o,props):
name=os.path.basename(dir)
absdir=os.path.abspath(dir)
pb=Properties(os.path.join(dir,"mk.cfg"))
Expand Down Expand Up @@ -130,7 +148,15 @@ def generateConfig(self,dir,files,cfg,o):
#o = open(output,'w')
o.write('CPP_{}=g++\n'.format(cfg))
o.write('INC_{}=-I{} {}\n'.format(cfg,self.globalInc,cfgInclude))
cflags='-c -std=c++11 $(OPT_{}) $(INC_{}) '.format(cfg,cfg)
warn=extractFlags(props.get("BUILD_WARN",""))
cflags='-c {} -std=c++11 $(OPT_{}) $(INC_{}) '.format(warn,cfg,cfg)
if props.get("BUILD_PEDANTIC")=="True":
cflags=cflags+" -pedantic-errors "
if props.get("BUILD_WARNERR")=="True":
cflags=cflags+" -Werror "
custom=props.get("BUILD_CUSTOM")
if custom:
cflags=cflags+" "+custom
lflags='$(OPT_{}) $(OBJS_{}) '.format(cfg,cfg)
libdeps={}
for lib in libs:
Expand Down Expand Up @@ -191,12 +217,29 @@ def generateConfig(self,dir,files,cfg,o):
return True

def generate(self,dir,files):
#props=mkProps(Properties(),root)
stack=[]
curdir=dir
while True:
stack.append(curdir)
if curdir==self.root:
break
curdir=os.path.abspath(os.path.join(curdir,'..'))
props=Properties()
while len(stack)>0:
props=mkProps(props,stack[-1])
del stack[-1]
output=os.path.join(dir,"Makefile")
o=open(output,"w")
o.write('OPT_Release=-O2\n')
opt=props.get("BUILD_OPT")
if len(opt)==0:
opt="-O2"
if opt=="Custom":
opt=""
o.write('OPT_Release={}\n'.format(opt))
o.write('OPT_Debug=-g\n')
self.generateConfig(dir,files,"Release",o)
if self.generateConfig(dir,files,"Debug",o):
self.generateConfig(dir,files,"Release",o,props)
if self.generateConfig(dir,files,"Debug",o,props):
pass


Expand Down
10 changes: 6 additions & 4 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,13 @@ def attemptUndefResolution(self,undefs):
self.workspaceTree.addLibrariesToProject(self.added)


def buildSettings(self):
def buildSettings(self,path=''):
from buildsettings import BuildSettingsDialog
d=BuildSettingsDialog(self)
if d.exec_():
pass
if not path:
path=self.workspaceTree.root
d=BuildSettingsDialog(self,path)
d.exec_()
self.generateAll()

def buildSpecific(self,path):
self.saveAll()
Expand Down
14 changes: 14 additions & 0 deletions properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re

class Properties:
def __init__(self,path=''):
Expand All @@ -10,6 +11,9 @@ def __init__(self,path=''):
if len(parts)==2:
self.props[parts[0]]=parts[1]

def copyFrom(self,props):
self.props=props.props.copy()

def has(self,name):
return name in self.props

Expand All @@ -20,6 +24,16 @@ def get(self,name,default=''):

def assign(self,name,value):
self.props[name]=value

def search(self,exp):
'''
Returns a list of name that match the regular expression
'''
res=[]
for name in self.props:
if re.match(exp,name):
res.append(name)
return res

def save(self,path):
f=open(path,"w")
Expand Down
2 changes: 1 addition & 1 deletion uis/build_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<string>Pedantic</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="warnErrors">
<property name="geometry">
<rect>
<x>16</x>
Expand Down
9 changes: 8 additions & 1 deletion workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self,pane,mainwin):
self.actBuild = QtGui.QAction('Build',self,triggered=self.buildCurrent)
self.actClean = QtGui.QAction('Clean',self,triggered=self.cleanCurrent)
self.actRebuild = QtGui.QAction('Rebuild',self,triggered=self.rebuildCurrent)
self.actBuildSettings = QtGui.QAction('Build Settings',self,triggered=self.buildSettings)
self.actSetMain = QtGui.QAction('Set Main Project',self,triggered=self.setMain)
self.actEditDependencies = QtGui.QAction('Dependencies',self,triggered=self.editDependencies)
self.actDebugSettings = QtGui.QAction('Debug Settings',self,triggered=self.editDebugSettings)
Expand Down Expand Up @@ -50,6 +51,7 @@ def contextMenuEvent(self,event):
menu.addAction(self.actBuild)
menu.addAction(self.actRebuild)
menu.addAction(self.actClean)
menu.addAction(self.actBuildSettings)
menu.addSeparator()
menu.addAction(self.actSetMain)
menu.addAction(self.actEditDependencies)
Expand Down Expand Up @@ -137,7 +139,12 @@ def mainPath(self):
if self.main:
return self.main.data(0,DirectoryRole).toString()
return ""


def buildSettings(self):
item=self.currentItem()
path=item.data(0,DirectoryRole).toString()
self.mainWindow.buildSettings(path)

def buildCurrent(self):
item=self.currentItem()
path=item.data(0,DirectoryRole).toString()
Expand Down

0 comments on commit b3c2aa1

Please sign in to comment.