1. Alex Chi
  2. nacl automake

Commits

Alex Chi  committed e3f08ce

[TASK] declare the relationship between project and solution

  • Participants
  • Parent commits b7c418e
  • Branches master

Comments (0)

Files changed (7)

File naclautomake/__init__.py

View file
 
 __all__ += ['automake']
 
-def CreateAutoMake(solutionpath, outputpath, naclsdkpath, chromepath, toolchains, maketypes):
-    return NaClAutoMake(solutionpath, outputpath, naclsdkpath, chromepath, toolchains, maketypes)
+def CreateAutoMake(solutionname, solutionpath, outputpath, naclsdkpath, chromepath, toolchains, maketypes):
+    return NaClAutoMake(solutionname, solutionpath, outputpath, naclsdkpath, chromepath, toolchains, maketypes)

File naclautomake/common.py

View file
     '''
 remove repeated item in list
     '''
-    return list(UniqueSet(alist))
+    return list(UniqueSet(alist))

File naclautomake/define.py

View file
 
 @author: Alex
 '''
-from common import EToolChain
 from common import EMakeType
 from setting import NaClSetting
 from makefile import NaClMakefile

File naclautomake/main.py

View file
     '''
 AutoMake
     '''
-    def __init__(self, solutionpath, outputpath, naclsdkpath, chromepath, toolchains, maketypes):
+    def __init__(self, solutionname, solutionpath, outputpath, naclsdkpath, chromepath, toolchains, maketypes):
         self.__setting__ = NaClSetting(solutionpath, outputpath, naclsdkpath, chromepath, toolchains, maketypes)
         self.__define__ = NaClDefine(self.__setting__)
-        self.__solution__ = NaClSolution()
+        self.__solution__ = NaClSolution(solutionname)
+
+    @property
+    def solution(self):
+        return self.__solution__
 
     def mfLicense(self):
         # output the copyright information
 #\n'
         return res
 
+    def mfAll(self):
+        res = '# Declare all'
+        res = '\n'.join([res, 'all: ' + self.__solution__.name])
+        return res
+
+    def mfClean(self):
+        res = '# Declare clean'
+        res = '\n'.join([res, 'clean:'])
+        return res
+
     def makefile(self):
         res = self.mfLicense()
         res = '\n'.join([res, self.__define__.makefile()])
+        res = '\n'.join([res, ''])
+        res = '\n'.join([res, self.mfAll()])
+        res = '\n'.join([res, ''])
+        res = '\n'.join([res, self.__solution__.makefile()])
+        res = '\n'.join([res, ''])
+        res = '\n'.join([res, self.mfClean()])
         return res
 
     def write(self, makefilename):

File naclautomake/project.py

View file
 @author: Alex Chi
 '''
 from common import EProjectType
+from common import UniqueList
 from makefile import NaClMakefile
 
 class NaClProject(NaClMakefile):
 a project that contain all code files
     '''
 
-    def __init__(self, projecttype = EProjectType.NEXE):
+    def __init__(self, name, projecttype = EProjectType.NEXE):
+        self.__name__ = name
         self.__type__ = projecttype
+        self.__depends__ = []
+        self.__bedepends__ = []
+
+    @property
+    def name(self):
+        return self.__name__
 
     @property
     def type(self):
     @type.setter
     def type(self, value):
         self.__type__ = value
+
+    @property
+    def depends(self):
+        return self.__depends__
+
+    @depends.setter
+    def depends(self, value):
+        self.__depends__ += value
+        self.__depends__ = UniqueList(self.__depends__)
+
+    @property
+    def bedepends(self):
+        return self.__bedepends__
+
+    @bedepends.setter
+    def bedepends(self, value):
+        self.__bedepends__ += value
+        self.__bedepends__ = UniqueList(self.__bedepends__)
+
+    def makefile(self):
+        res = '# Project: ' + self.__name__ + ' | Type: ' + self.__type__
+        res = '\n'.join([res, self.__name__ + ':'])
+        for dependname in self.__depends__:
+            res = ' '.join([res, dependname]) 
+        return res

File naclautomake/solution.py

View file
 
 @author: Alex Chi
 '''
+from common import EProjectType
 from makefile import NaClMakefile
 from project import NaClProject
 
 a solution that contain all projects
     '''
 
-    def __init__(self):
-        self.__projects__ = []
+    def __init__(self, name):
+        self.__name__ = name
+        self.__projects__ = {}
 
-    def newProject(self):
-        tmp = NaClProject()
-        self.__projects__.append(tmp)
-        return tmp
+    @property
+    def name(self):
+        return self.__name__
+
+    def newProject(self, name, projecttype = EProjectType.NEXE):
+        self.__projects__[name] = NaClProject(name, projecttype)
+        return self.__projects__[name]
+
+    def depend(self, dependname, bedependname):
+        if dependname not in self.__projects__ and bedependname not in self.__projects__:
+            raise Exception('can\'t find the ' + dependname + ' or ' + bedependname + ' from projects')
+        # TODO: need to check the relationship between dependname and bedependname
+        self.__projects__[dependname].depends = [bedependname]
+        self.__projects__[bedependname].bedepends = [dependname]
+
+    def mfSolution(self):
+        res = '# Solution: ' + self.__name__
+        res = '\n'.join([res, self.__name__ + ':'])
+        for key in self.__projects__:
+            if len(self.__projects__[key].bedepends) <= 0:
+                res = ' '.join([res, key])
+        return res
+
+    def mfProjects(self):
+        res = '# List all projects'
+        for key in self.__projects__:
+            res = '\n'.join([res, ''])
+            res = '\n'.join([res, self.__projects__[key].makefile()])
+        return res
 
     def makefile(self):
-        pass
+        res = self.mfSolution()
+        res = '\n'.join([res, ''])
+        res = '\n'.join([res, self.mfProjects()])
+        return res

File nacltest.py

View file
 from naclautomake import CreateAutoMake
 from naclautomake.common import EToolChain
 from naclautomake.common import EMakeType
+from naclautomake.common import EProjectType
 
 if __name__ == '__main__':
-    am = CreateAutoMake('solutionpath', 'outputpath', 'naclsdkpath', 'chromepath', [EToolChain.NEWLIB], [EMakeType.DEBUG, EMakeType.DEPLOY])
+    am = CreateAutoMake('nacltest', 'solutionpath', 'outputpath', 'naclsdkpath', 'chromepath', [EToolChain.NEWLIB], [EMakeType.DEBUG, EMakeType.DEPLOY])
+    ncp0 = am.solution.newProject('slib', EProjectType.SLIB)
+    ncp1 = am.solution.newProject('test')
+    am.solution.depend('test', 'slib')
     print am.makefile()
     am.write('nacltest/Makefile')