bin/synchb.py
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    87         file.close()
    87         file.close()
    88     except IOError, e:
    88     except IOError, e:
    89         print(e)
    89         print(e)
    90 
    90 
    91 def include_directive(header):
    91 def include_directive(header):
    92     return "#include \"%s\"\n" % header
    92     return "#include \"%s\"\n" % header.replace("\\", "/")
    93 
    93 
    94 def write_header(header, include, path):
    94 def write_header(header, include, path):
    95     filename = os.path.basename(header)
    95     filename = os.path.basename(header)
    96     filepath = os.path.join(path, filename)
    96     filepath = os.path.join(path, filename)
    97     relpath = os.path.relpath(header, path).replace("\\", "/")
       
    98     skip = False
    97     skip = False
    99     if os.path.exists(filepath):
    98     if os.path.exists(filepath):
   100         directive = include_directive(include)
    99         directive = include_directive(include)
   101         oldsize = os.path.getsize(filepath)
   100         oldsize = os.path.getsize(filepath)
   102         newsize = len(directive)
   101         newsize = len(directive)
   113 class Component:
   112 class Component:
   114     def __init__(self, name):
   113     def __init__(self, name):
   115         self.name = name
   114         self.name = name
   116         self.headers = []
   115         self.headers = []
   117         self.privates = []
   116         self.privates = []
       
   117         self.restricted = []
   118 
   118 
   119     def read(self, path):
   119     def read(self, path):
   120         entries = os.listdir(path)
   120         entries = os.listdir(path)
   121         for entry in entries:
   121         for entry in entries:
   122             entrypath = os.path.join(path, entry)
   122             entrypath = os.path.join(path, entry)
   123             if os.path.isdir(entrypath):
   123             if os.path.isdir(entrypath):
   124                 self.read(entrypath)
   124                 self.read(entrypath)
   125             elif os.path.isfile(entrypath):
   125             elif os.path.isfile(entrypath):
   126                 if entry.endswith("_p_p.h"):
   126                 if re.match(entry, ".*?_[pr]_[pr]\.h"):
   127                     continue
   127                     continue
   128                 elif entry.endswith("_p.h"):
   128                 elif entry.endswith("_p.h"):
   129                     self.privates.append(entrypath)
   129                     self.privates.append(entrypath)
       
   130                 elif entry.endswith("_r.h"):
       
   131                     self.restricted.append(entrypath)
   130                 elif entry.endswith(".h"):
   132                 elif entry.endswith(".h"):
   131                     self.headers.append(entrypath)
   133                     self.headers.append(entrypath)
   132 
   134 
   133     def write(self, path):
   135     def write(self, path):
   134         written = []
   136         written = []
   135         if len(self.headers) > 0:
   137         if len(self.headers) > 0:
   136             self._makedirs(path)
   138             self._makedirs(path)
   137             written += self._write(path, self.headers, True)
   139             written += self._write(path, self.headers, True)
   138 
   140 
       
   141         if len(self.restricted) > 0:
       
   142             restpath = os.path.join(path, "restricted")
       
   143             self._makedirs(restpath)
       
   144             written += self._write(restpath, self.restricted, True)
       
   145 
   139         if len(self.privates) > 0:
   146         if len(self.privates) > 0:
   140             privpath = os.path.join(path, "private")
   147             privpath = os.path.join(path, "private")
   141             self._makedirs(privpath)
   148             self._makedirs(privpath)
   142             written += self._write(privpath, self.privates, False)
   149             written += self._write(privpath, self.privates, False)
   143         return written
   150         return written
   144 
   151 
   145     def _write(self, path, headers, convenience):
   152     def _write(self, path, headers, convenience):
   146         written = []
   153         written = []
   147         for header in headers:
   154         for header in headers:
   148             write_header(header, header, path)
   155             write_header(header, os.path.relpath(header, path), path)
   149             written.append(os.path.join(path, os.path.basename(header)))
   156             written.append(os.path.join(path, os.path.basename(header)))
   150             if convenience:
   157             if convenience:
   151                 classes = []
   158                 classes = []
   152                 content = read_file(header)
   159                 content = read_file(header)
   153                 for match in re.finditer("(?:class|namespace)\s+(?:HB_[^_]+_EXPORT\s+)?(Hb\w*)(\s*;)?", content):
   160                 for match in re.finditer("(?:class|namespace)\s+(?:HB_[^_]+(?:_RESTRICTED)?_EXPORT\s+)?(Hb\w*)(\s*;)?", content):
   154                     if not match.group(2):
   161                     if not match.group(2):
   155                         classes.append(match.group(1))
   162                         classes.append(match.group(1))
   156                 for match in re.finditer("#pragma hb_header\((\w+)\)", content):
   163                 for match in re.finditer("#pragma hb_header\((\w+)\)", content):
   157                     classes.append(match.group(1))
   164                     classes.append(match.group(1))
   158                 for cls in classes:
   165                 for cls in classes: