origin/vcproj_gen.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 #
4 # @file vcproj_gen.py
5 # @brief rtc-template VC++ project/solution file generator class
6 # @date $Date$
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2008
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id: vcproj_gen.py 775 2008-07-28 16:14:45Z n-ando $
17 #
18 
19 import os
20 import yat
21 import gen_base
22 
23 copyprops = """
24 copy "%RTM_ROOT%\\etc\\rtm_config.vsprops" .
25 """
26 
27 userprops = """<?xml version="1.0" encoding="shift_jis"?>
28 <VisualStudioPropertySheet
29  ProjectType="Visual C++"
30  Version="8.00"
31  Name="User property"
32  >
33  <UserMacro
34  Name="user_lib"
35  Value=""
36  />
37  <UserMacro
38  Name="user_libd"
39  Value=""
40  />
41 </VisualStudioPropertySheet>
42 """
43 
44 
46  """
47  VC++ project-file generator
48  """
49  _fname_space = 16
50  def __init__(self, data, opts):
51  self.vcvers = {
52  "VC8": {
53  "proj_ver": "8.00",
54  "sln_ver": "9.00",
55  "suffix": "_vc8",
56  "sln_fname": "",
57  "exeproj_fname": "",
58  "dllproj_fname": ""
59  },
60  "VC9": {
61  "proj_ver": "9.00",
62  "sln_ver": "10.00",
63  "suffix": "_vc9",
64  "sln_fname": "",
65  "exeproj_fname": "",
66  "dllproj_fname": ""
67  }
68  }
69 
70  self.data = data
71  base = self.data["basicInfo"]["name"]
72  for key in self.vcvers.keys():
73  v = self.vcvers[key]
74  suffix = v["suffix"]
75  v["sln_fname"] = base + suffix + ".sln"
76  v["exeproj_fname"] = base + "Comp" + suffix + ".vcproj"
77  v["dllproj_fname"] = base + suffix + ".vcproj"
78  self.CreateSourceList()
79 
80  self.tags = {}
81  self.gen_tags(self.tags)
82 
83  return
84 
85  def CreateSourceList(self):
86  name = self.data["basicInfo"]["name"]
87  es = self.data["exesources"] = []
88  eh = self.data["exeheaders"] = []
89  ds = self.data["dllsources"] = []
90  dh = self.data["dllheaders"] = []
91 
92  es += [name + ".cpp", name + "Comp.cpp"]
93  eh += [name + ".h"]
94  ds += [name + ".cpp"]
95  dh += [name + ".h"]
96 
97  slist = [es, ds]
98  hlist = [eh, dh]
99  nlist = ["skel_basename", "impl_basename"]
100  for sidl in self.data["service_idl"]:
101  for l in slist:
102  l += [(sidl[key] + ".cpp") for key in nlist]
103  for l in hlist:
104  l += [(sidl[key] + ".h") for key in nlist]
105  nlist = ["stub_basename"]
106  for sidl in self.data["consumer_idl"]:
107  for l in slist:
108  l += [(sidl[key] + ".cpp") for key in nlist if sidl.has_key(key)]
109  for l in hlist:
110  l += [(sidl[key] + ".h") for key in nlist if sidl.has_key(key)]
111 
112 
113  def check_overwrite(self, fname, wmode="wb"):
114  """
115  Check file exist or not.
116  """
117  msg = " already exists. Overwrite? (y/n)"
118  if (os.access(fname, os.F_OK)):
119  ans = raw_input("\"" + fname + "\"" + msg)
120  if (ans == "y" or ans == "Y"):
121  return file(fname, "wb")
122  else:
123  return None
124  else:
125  return file(fname, "wb")
126  return None, None
127 
128  def print_vcproject(self):
129  """
130  Generate VC++ project-file
131  """
132  import vcprojtool
133  proj_name = self.data["basicInfo"]["name"]
134  version = self.data["basicInfo"]["version"]
135  exefiles = {"source": self.data["exesources"],
136  "header": self.data["exeheaders"],
137  "resource": [],
138  "yaml": []}
139  dllfiles = {"source": self.data["dllsources"],
140  "header": self.data["dllheaders"],
141  "resource": [],
142  "yaml": []}
143  for key in self.vcvers.keys():
144  v = self.vcvers[key]
145  # Create vcproj for EXE
146  y = vcprojtool.YamlConfig("RTCEXE", v["proj_ver"],
147  proj_name+"Comp", version,
148  exefiles).generate()
149  t = vcprojtool.VCProject("RTCEXE", y).generate()
150  fname = v["exeproj_fname"]
151  fd = self.check_overwrite(fname)
152  if fd != None:
153  fd.write(t)
154  print " File \"" + fname + "\" was generated."
155  fd.close()
156  # Create vcproj for DLL
157  y = vcprojtool.YamlConfig("RTCDLL", v["proj_ver"],
158  proj_name, version,
159  dllfiles).generate()
160  t = vcprojtool.VCProject("RTCDLL", y).generate()
161  fname = v["dllproj_fname"]
162  fd = self.check_overwrite(fname)
163  if fd != None:
164  fd.write(t)
165  print " File \"" + fname + "\" was generated."
166  fd.close()
167  return
168 
169  def print_solution(self):
170  """
171  Generate VC++ solution-file
172  """
173  import slntool
174  for key in self.vcvers.keys():
175  v = self.vcvers[key]
176  fname = v["sln_fname"]
177  fd = self.check_overwrite(fname)
178  if fd != None:
179  flist = [v["exeproj_fname"], v["dllproj_fname"]]
180  yamltxt = slntool.get_slnyaml(None, flist)
181  sln = slntool.gen_solution(key, yamltxt)
182  fd.write(sln)
183  print " File \"" + fname + "\" was generated."
184  fd.close()
185  return
186 
187  def print_copybat(self):
188  fname = "copyprops.bat"
189  fd = self.check_overwrite(fname)
190  if fd != None:
191  o = copyprops.replace("\r\n","\n").replace("\n", "\r\n")
192  fd.write(o)
193  print " File \"" + fname + "\" was generated."
194  fd.close()
195 
196  def print_userprops(self):
197  fname = "user_config.vsprops"
198  fd = self.check_overwrite(fname)
199  if fd != None:
200  o = userprops.replace("\r\n","\n").replace("\n", "\r\n")
201  fd.write(o)
202  print " File \"" + fname + "\" was generated."
203  fd.close()
204 
205  def print_all(self):
206  self.print_vcproject()
207  self.print_solution()
208  self.print_copybat()
209  self.print_userprops()
210 
def get_slnyaml(depfile, projfiles, vcversion)
def gen_solution(version, yaml_text)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:26