Project/Project.py

branch
make_support
changeset 6248
9458a3d45f27
parent 6244
233eea858c32
child 6251
02afc7d22c41
--- a/Project/Project.py	Fri Apr 13 19:57:02 2018 +0200
+++ b/Project/Project.py	Sat Apr 14 18:48:38 2018 +0200
@@ -148,6 +148,9 @@
     
     eols = [os.linesep, "\n", "\r", "\r\n"]
     
+    DefaultMake = "make"
+    DefaultMakefile = "makefile"
+    
     def __init__(self, parent=None, filename=None):
         """
         Constructor
@@ -431,7 +434,6 @@
         self.dbgTracePython = False
         self.dbgAutoContinue = True
         
-        # TODO: add 'make' support
         self.pdata = {
             "DESCRIPTION": "",
             "VERSION": "",
@@ -466,6 +468,14 @@
             "PACKAGERSPARMS": {},
             "DOCUMENTATIONPARMS": {},
             "OTHERTOOLSPARMS": {},
+            "MAKEPARAMS": {
+                "MakeEnabled": False,
+                "MakeExecutable": "",
+                "MakeFile": "",
+                "MakeTarget": "",
+                "MakeParameters": "",
+                "MakeTestOnly": True,
+            },
             "EOL": -1,
         }
         
@@ -2254,6 +2264,7 @@
                         .format(self.ppath))
                     self.vcs = self.initVCS()
                     return
+                
                 # create an empty __init__.py file to make it a Python package
                 # (only for Python and Python3)
                 if self.pdata["PROGLANGUAGE"] in \
@@ -2262,6 +2273,7 @@
                     f = open(fn, "w", encoding="utf-8")
                     f.close()
                     self.appendFile(fn, True)
+                
                 # create an empty main script file, if a name was given
                 if self.pdata["MAINSCRIPT"]:
                     if not os.path.isabs(self.pdata["MAINSCRIPT"]):
@@ -2272,6 +2284,18 @@
                     f = open(ms, "w")
                     f.close()
                     self.appendFile(ms, True)
+                
+                if self.pdata["MAKEPARAMS"]["MakeEnabled"]:
+                    mf = self.pdata["MAKEPARAMS"]["MakeFile"]
+                    if mf:
+                        if not os.path.isabs(mf):
+                            mf = os.path.join(self.ppath, mf)
+                    else:
+                        mf = os.path.join(self.ppath, Project.DefaultMakefile)
+                    f = open(mf, "w")
+                    f.close()
+                    self.appendFile(mf)
+                
                 tpd = os.path.join(self.ppath, self.translationsRoot)
                 if not self.translationsRoot.endswith(os.sep):
                     tpd = os.path.dirname(tpd)
@@ -2318,11 +2342,32 @@
                                 self.tr(
                                     "<p>The mainscript <b>{0}</b> could not"
                                     " be created.<br/>Reason: {1}</p>")
-                                .format(self.ppath, str(err)))
-                    self.appendFile(ms)
+                                .format(ms, str(err)))
+                    self.appendFile(ms, True)
                 else:
                     ms = ""
                 
+                if self.pdata["MAKEPARAMS"]["MakeEnabled"]:
+                    mf = self.pdata["MAKEPARAMS"]["MakeFile"]
+                    if mf:
+                        if not os.path.isabs(mf):
+                            mf = os.path.join(self.ppath, mf)
+                    else:
+                        mf = os.path.join(self.ppath, Project.DefaultMakefile)
+                    if not os.path.exists(mf):
+                        try:
+                            f = open(mf, "w")
+                            f.close()
+                        except EnvironmentError as err:
+                            E5MessageBox.critical(
+                                self.ui,
+                                self.tr("Create Makefile"),
+                                self.tr(
+                                    "<p>The makefile <b>{0}</b> could not"
+                                    " be created.<br/>Reason: {1}</p>")
+                                .format(mf, str(err)))
+                    self.appendFile(mf)
+                
                 # add existing files to the project
                 res = E5MessageBox.yesNo(
                     self.ui,
@@ -2580,6 +2625,27 @@
                 if os.path.exists(ms):
                     self.appendFile(ms)
             
+            if self.pdata["MAKEPARAMS"]["MakeEnabled"]:
+                mf = self.pdata["MAKEPARAMS"]["MakeFile"]
+                if mf:
+                    if not os.path.isabs(mf):
+                        mf = os.path.join(self.ppath, mf)
+                else:
+                    mf = os.path.join(self.ppath, Project.DefaultMakefile)
+                if not os.path.exists(mf):
+                    try:
+                        f = open(mf, "w")
+                        f.close()
+                    except EnvironmentError as err:
+                        E5MessageBox.critical(
+                            self.ui,
+                            self.tr("Create Makefile"),
+                            self.tr(
+                                "<p>The makefile <b>{0}</b> could not"
+                                " be created.<br/>Reason: {1}</p>")
+                            .format(mf, str(err)))
+                self.appendFile(mf)
+            
             if self.pdata["PROJECTTYPE"] != projectType:
                 # reinitialize filetype associations
                 self.initFileTypes()

eric ide

mercurial