Commits

Alex Chi committed 85a633b

[TASK] update compiler.py, ready for compile part of Makefile.
[TASK] add some common functions - to get the code type, to get the file type, etc.
[TASK] add a code file for demo.

Comments (0)

Files changed (6)

+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// C headers
+#include <cassert>
+#include <cstdio>
+
+// C++ headers
+#include <sstream>
+#include <string>
+
+// NaCl
+#include "ppapi/cpp/input_event.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/point.h"
+#include "ppapi/cpp/var.h"
+
+namespace NaClAutomake{
+
+    const char* const kDidChangeView = "DidChangeView";
+    const char* const kDidChangeFocus = "DidChangeFocus";
+    const char* const kHaveFocus = "HaveFocus";
+    const char* const kDontHaveFocus = "DontHaveFocus";
+
+    class DemoInstance : public pp::Instance
+    {
+    public:
+        explicit DemoInstance(PP_Instance instance) : pp::Instance(instance) { ; }
+        virtual ~DemoInstance() { ; }
+
+        void DidChangeView(const pp::View& view)
+        {
+            PostMessage(pp::Var(kDidChangeView));
+        }
+
+        void DidChangeFocus(bool focus)
+        {
+            PostMessage(pp::Var(kDidChangeFocus));
+            if (focus == true)
+            {
+                PostMessage(pp::Var(kHaveFocus));
+            }
+            else
+            {
+                PostMessage(pp::Var(kDontHaveFocus));
+            }
+        }
+    };
+
+    class DemoModule : public pp::Module
+    {
+    public:
+        DemoModule() : pp::Module() {}
+        virtual ~EventModule() {}
+
+        virtual pp::Instance* CreateInstance(PP_Instance instance)
+        {
+            return new DemoInstance(instance);
+        }
+    };
+
+}
+
+namespace pp{
+
+    Module* CreateModule()
+    {
+        return new NaClAutomake::DemoModule();
+    }
+
+}

naclautomake/codefile.py

-from common import GetExtFromFullName
+from common import ECodeFileType
+from common import SplitFullName
+from common import GetCodeFileType
 
 __author__ = 'alex'
 
 class NaClCodeFile(object):
     def __init__(self, fullname, path = ''):
-        splitres = GetExtFromFullName(fullname)
+        splitres = SplitFullName(fullname)
         self.__name__ = splitres[0]
         self.__ext__ = splitres[1]
         self.__path__ = path
+        self.__filetype__ = GetCodeFileType(self.__ext__)
         if not self.isInc() and not self.isSrc():
             raise Exception(fullname + ' is not a code file.')
 
     def fullname(self):
         return self.__path__ + '/' + self.__name__ + '.' + self.__ext__
 
+    @property
+    def filetype(self):
+        return self.__filetype__
+
     def isInc(self):
-        if self.__ext__ in ['h', 'hh', 'hpp']:
+        if self.__filetype__ is ECodeFileType.INC:
             return True
         return False
 
     def isSrc(self):
-        if self.__ext__ in ['c', 'cc', 'cpp']:
+        if self.__filetype__ is ECodeFileType.SRC:
             return True
         return False

naclautomake/common.py

 EMakeType = Enum(DEBUG = 'debug', PROFILE = 'profile', DEPLOY = 'deploy')
 EProjectType = Enum(SLIB = 'a', DLIB = 'so', EXE = 'exe')
 ECodeFileExt = Enum(C = 'c', CPP = 'cpp', CC = 'cc', H = 'h', HPP = 'hpp', HH = 'hh', INC = 'inc', INL = 'inl')
-ECodeFileType = Enum(INC = 'inc', SRC = 'src')
+ECodeFileType = Enum(INC = 'inc', SRC = 'src', NONE='none')
 ECodeType = Enum(C = 'c', CC = 'cc')
 
 def UniqueSet(aset):
     else:
         raise Exception('error, can\'t find EProjectType.' + projecttype)
 
-def GetExtFromFullName(fullname):
+def SplitFullName(fullname):
     '''
-split the
+split the full name to string array
     '''
     fnlist = fullname.split('.')
     name = ''
         name = fnlist[0]
         for index in range(1, len(fnlist) - 1):
             name = '.'.join([name, fnlist[index]])
-    return (name, ext)
+    return (name, ext)
+
+def GetCodeFileType(ext):
+    if ext in ['h', 'hh', 'hpp']:
+        return ECodeFileType.INC
+    if ext in ['c', 'cc', 'cpp']:
+        return ECodeFileType.SRC
+    return ECodeFileType.NONE

naclautomake/compiler.py

     '''
 a compiler for native client
     '''
-    def __init__(self, toolchain):
+    def __init__(self, outputpath, toolchain, maketype, ostypes, projecttype):
         '''
 the compiler must known what kind of toolchain
         '''
+        self.__outputpath__ = outputpath
         self.__toolchain__ = toolchain
+        self.__maketype__ = maketype
+        self.__ostypes__ = ostypes
+        self.__projecttype__ = projecttype
 
-    def isInclude(self, codefileext):
-        if codefileext is ECodeFileExt.H \
-            or codefileext is ECodeFileExt.HH \
-            or codefileext is ECodeFileExt.HPP \
-            or codefileext is ECodeFileExt.INC \
-            or codefileext is ECodeFileExt.INL:
-            return True
-        return False
-
-    def isSource(self, codefileext):
-        if codefileext is ECodeFileExt.C \
-            or codefileext is ECodeFileExt.CC \
-            or codefileext is ECodeFileExt.CPP:
-            return True
-        return False
-
-    def getCodeFileType(self, codefileext):
-        if self.isInclude(codefileext):
-            return ECodeFileType.INC
-        elif self.isSource(codefileext):
-            return ECodeFileType.SRC
-        else:
-            raise Exception('can\'t get the code file type by file extension, can\'t recognize the .' + codefileext)
-
-    def getCodeType(self, codefileext):
-        if codefileext is ECodeFileExt.C:
-            return ECodeType.C
-        elif codefileext is ECodeFileExt.CC \
-            or codefileext is ECodeFileExt.CPP:
-            return ECodeType.CC
-        else:
-            raise Exception('can\'t get the code type by file extension, can\'t recognize the .' + codefileext)
+    def makefile(self, project):
+        res = ''
+        return res

naclautomake/project.py

 
     def mfBuildWithToolChainAndMakeType(self, toolchain, maketype):
         res = '# build ' + self.name + ' with ' + toolchain + '|' + maketype
+        compiler = NaClCompiler(self.makeoutputdirKey(toolchain, maketype)
+            , toolchain, maketype, self.__setting__.ostypes, self.__type__)
+        res = '\n'.join([res, compiler.makefile(self)])
         if self.__type__ == EProjectType.EXE:
             res = '\n'.join([res, ''])
             res = '\n'.join([res, self.mfGenerateNMF(toolchain, maketype)])

naclautomake/setting.py

         return self.__toolchains__
 
     @property
-    def ostypes(self):
-        return self.__ostypes__
-
-    @property
     def maketypes(self):
         return self.__maketypes__
+
+    @property
+    def ostypes(self):
+        return self.__ostypes__
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.