vcproj_gen.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 #
00004 #  @file vcproj_gen.py
00005 #  @brief rtc-template VC++ project/solution file generator class
00006 #  @date $Date$
00007 #  @author Noriaki Ando <n-ando@aist.go.jp>
00008 # 
00009 #  Copyright (C) 2008
00010 #      Task-intelligence Research Group,
00011 #      Intelligent Systems Research Institute,
00012 #      National Institute of
00013 #          Advanced Industrial Science and Technology (AIST), Japan
00014 #      All rights reserved.
00015 # 
00016 #  $Id: vcproj_gen.py 775 2008-07-28 16:14:45Z n-ando $
00017 # 
00018 
00019 import os
00020 import yat
00021 import gen_base
00022 
00023 copyprops = """
00024 copy "%OPENHRP_SDK_ROOT%\\etc\\rtm_config.vsprops" .
00025 """
00026 
00027 userprops = """<?xml version="1.0" encoding="shift_jis"?>
00028 <VisualStudioPropertySheet
00029         ProjectType="Visual C++"
00030         Version="8.00"
00031         Name="User property"
00032         >
00033         <UserMacro
00034                 Name="user_lib"
00035                 Value=""
00036         />
00037         <UserMacro
00038                 Name="user_libd"
00039                 Value=""
00040         />
00041 </VisualStudioPropertySheet>
00042 """
00043 
00044 
00045 class vcproj_gen(gen_base.gen_base):
00046         """
00047         VC++ project-file generator
00048         """
00049         _fname_space = 16
00050         def __init__(self, data, opts):
00051                 self.vcvers = {
00052                         "VC8": {
00053                                 "proj_ver": "8.00",
00054                                 "sln_ver": "9.00",
00055                                 "suffix": "_vc8",
00056                                 "sln_fname": "",
00057                                 "exeproj_fname": "",
00058                                 "dllproj_fname": ""
00059                                 },
00060                         "VC9": {
00061                                 "proj_ver": "9.00",
00062                                 "sln_ver": "10.00",
00063                                 "suffix": "_vc9",
00064                                 "sln_fname": "",
00065                                 "exeproj_fname": "",
00066                                 "dllproj_fname": ""
00067                                 }
00068                         }
00069 
00070                 self.data = data
00071                 base = self.data["basicInfo"]["name"]
00072                 for key in self.vcvers.keys():
00073                         v = self.vcvers[key]
00074                         suffix = v["suffix"]
00075                         v["sln_fname"]     = base + suffix + ".sln"
00076                         v["exeproj_fname"] = base + "Comp" + suffix + ".vcproj"
00077                         v["dllproj_fname"] = base + suffix + ".vcproj"
00078                 self.CreateSourceList()
00079 
00080                 self.tags = {}
00081                 self.gen_tags(self.tags)
00082 
00083                 return
00084 
00085         def CreateSourceList(self):
00086                 name = self.data["basicInfo"]["name"]
00087                 es = self.data["exesources"] = []
00088                 eh = self.data["exeheaders"] = []
00089                 ds = self.data["dllsources"] = []
00090                 dh = self.data["dllheaders"] = []
00091 
00092                 es += [name + ".cpp", name + "Comp.cpp"]
00093                 eh += [name + ".h"]
00094                 ds += [name + ".cpp"]
00095                 dh += [name + ".h"]
00096 
00097                 slist = [es, ds]
00098                 hlist = [eh, dh]
00099                 nlist = ["skel_basename", "impl_basename"]
00100                 for sidl in self.data["service_idl"]:
00101                         for l in slist:
00102                                 l += [(sidl[key] + ".cpp") for key in nlist]
00103                         for l in hlist:
00104                                 l += [(sidl[key] + ".h") for key in nlist]
00105                 nlist = ["stub_basename"]
00106                 for sidl in self.data["consumer_idl"]:
00107                         for l in slist:
00108                                 l += [(sidl[key] + ".cpp") for key in nlist if sidl.has_key(key)]
00109                         for l in hlist:
00110                                 l += [(sidl[key] + ".h") for key in nlist if sidl.has_key(key)]
00111                 
00112 
00113         def check_overwrite(self, fname, wmode="wb"):
00114                 """
00115                 Check file exist or not.
00116                 """
00117                 msg = " already exists. Overwrite? (y/n)"
00118                 if (os.access(fname, os.F_OK)):
00119                         ans = raw_input("\"" + fname + "\"" + msg)
00120                         if (ans == "y" or ans == "Y"):
00121                                 return file(fname, "wb")
00122                         else:
00123                                 return None
00124                 else:
00125                         return file(fname, "wb")
00126                 return None, None
00127 
00128         def print_vcproject(self):
00129                 """
00130                 Generate VC++ project-file
00131                 """
00132                 import vcprojtool
00133                 proj_name = self.data["basicInfo"]["name"]
00134                 version   = self.data["basicInfo"]["version"]
00135                 exefiles = {"source": self.data["exesources"],
00136                             "header": self.data["exeheaders"],
00137                             "resource": [],
00138                             "yaml": []}
00139                 dllfiles = {"source": self.data["dllsources"],
00140                             "header": self.data["dllheaders"],
00141                             "resource": [],
00142                             "yaml": []}
00143                 for key in self.vcvers.keys():
00144                         v = self.vcvers[key]
00145                         # Create vcproj for EXE
00146                         y = vcprojtool.YamlConfig("RTCEXE", v["proj_ver"],
00147                                                   proj_name+"Comp", version,
00148                                                   exefiles).generate()
00149                         t = vcprojtool.VCProject("RTCEXE", y).generate()
00150                         fname = v["exeproj_fname"]
00151                         fd = self.check_overwrite(fname)
00152                         if fd != None:
00153                                 fd.write(t)
00154                                 print "  File \"" + fname + "\" was generated."
00155                                 fd.close()
00156                         # Create vcproj for DLL
00157                         y = vcprojtool.YamlConfig("RTCDLL", v["proj_ver"],
00158                                                   proj_name, version,
00159                                                   dllfiles).generate()
00160                         t = vcprojtool.VCProject("RTCDLL", y).generate()
00161                         fname = v["dllproj_fname"]
00162                         fd = self.check_overwrite(fname)
00163                         if fd != None:
00164                                 fd.write(t)
00165                                 print "  File \"" + fname + "\" was generated."
00166                                 fd.close()
00167                 return
00168 
00169         def print_solution(self):
00170                 """
00171                 Generate VC++ solution-file
00172                 """
00173                 import slntool
00174                 for key in self.vcvers.keys():
00175                         v = self.vcvers[key]
00176                         fname = v["sln_fname"]
00177                         fd = self.check_overwrite(fname)
00178                         if fd != None:
00179                                 flist = [v["exeproj_fname"], v["dllproj_fname"]]
00180                                 yamltxt = slntool.get_slnyaml(None,  flist)
00181                                 sln = slntool.gen_solution(key, yamltxt)
00182                                 fd.write(sln)
00183                                 print "  File \"" + fname + "\" was generated."
00184                                 fd.close()
00185                 return
00186 
00187         def print_copybat(self):
00188                 fname = "copyprops.bat"
00189                 fd = self.check_overwrite(fname)
00190                 if fd != None:
00191                         o = copyprops.replace("\r\n","\n").replace("\n", "\r\n")
00192                         fd.write(o)
00193                         print "  File \"" + fname + "\" was generated."
00194                         fd.close()
00195 
00196         def print_userprops(self):
00197                 fname = "user_config.vsprops"
00198                 fd = self.check_overwrite(fname)
00199                 if fd != None:
00200                         o = userprops.replace("\r\n","\n").replace("\n", "\r\n")
00201                         fd.write(o)
00202                         print "  File \"" + fname + "\" was generated."
00203                         fd.close()
00204 
00205         def print_all(self):
00206                 self.print_vcproject()
00207                 self.print_solution()
00208                 self.print_copybat()
00209                 self.print_userprops()
00210 


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57