root / trunk / extensions / ext3Dgui / buildman / bin / bmplugins / CompileSolutionPlugIn.py @ 26254
History | View | Annotate | Download (5.19 KB)
1 | 26254 | rgaitan | from bmbase.IPlugIn import IPlugIn |
---|---|---|---|
2 | from bmbase.PlugInManager import PlugInManager |
||
3 | from bmcore.BMUtil import BMUtil |
||
4 | import os |
||
5 | import sys |
||
6 | |||
7 | class CompileSolutionPlugIn(IPlugIn): |
||
8 | def __init__(self): |
||
9 | IPlugIn.__init__(self)
|
||
10 | self._targetType = "Release" # only vs7/vs8 compilers |
||
11 | self._projectPath = "" |
||
12 | self._install = False |
||
13 | self._projectName = "" |
||
14 | self._projectGenerationPath = "" |
||
15 | self._supportedCompilers = dict() |
||
16 | self._supportedCompilers["vs8"]="devenv.exe" |
||
17 | self._supportedCompilers["vs7"]="devenv.exe" |
||
18 | self._supportedCompilers["gcc4"]="make" |
||
19 | self._supportedCompilers["gcc3"]="make" |
||
20 | self._compiler = "" |
||
21 | |||
22 | |||
23 | def init(self): |
||
24 | self.addGoal("compile-solution", "Compiles the solution based on Makefiles or VisualStudio for Win/Linux/Mac") |
||
25 | self.addGoalOption("compile-solution", "--project-path", "sets the path of the project.") |
||
26 | self.addGoalOption("compile-solution", "--project-gen-path", "sets the path of the Makefiles/VS build files. Default: ${project-path}/BMCMake") |
||
27 | self.addGoalOption("compile-solution", "--project-name", "sets the name of the project. If not given it uses the name of the project directory.") |
||
28 | self.addGoalOption("compile-solution", "--install", "Executes target install after compilation.") |
||
29 | self.addGoalOption("compile-solution", "--compiler", "Forces the compiler. If not try to determine using current platform\n" + |
||
30 | "Supported Compilers:\n" +
|
||
31 | str(self._supportedCompilers)) |
||
32 | execute = False
|
||
33 | if self._arguments.read("compile-solution"): |
||
34 | execute = True
|
||
35 | if execute:
|
||
36 | args = [""]
|
||
37 | if self._arguments.read("--project-path", args): |
||
38 | self._projectPath=args[0] |
||
39 | |||
40 | args = [""]
|
||
41 | if self._arguments.read("--project-gen-path", args): |
||
42 | self._projectGenerationPath=args[0] |
||
43 | |||
44 | args = [""]
|
||
45 | if self._arguments.read("--project-name", args): |
||
46 | self._projectName=args[0] |
||
47 | |||
48 | args = [""]
|
||
49 | if self._arguments.read("--compiler", args): |
||
50 | if args[0] in self._supportedCompilers: |
||
51 | self._compiler=args[0] |
||
52 | |||
53 | if self._arguments.read("--install"): |
||
54 | self._install=True |
||
55 | |||
56 | self.setExecute(True) |
||
57 | |||
58 | def initFromXML(self, node): |
||
59 | if node.localName=="compile-solution": |
||
60 | if node.hasAttributes():
|
||
61 | if node.attributes.has_key("project-path"): |
||
62 | self._projectPath = node.attributes.get("project-path").value |
||
63 | if node.attributes.has_key("project-gen-path"): |
||
64 | self._projectGenerationPath = node.attributes.get("project-gen-path").value |
||
65 | if node.attributes.has_key("project-name"): |
||
66 | self._projectName = node.attributes.get("project-name").value |
||
67 | if node.attributes.has_key("compiler"): |
||
68 | value = node.attributes.get("compiler").value
|
||
69 | if args[0] in self._supportedCompilers: |
||
70 | self._compiler = value
|
||
71 | if node.attributes.has_key("install"): |
||
72 | value = node.attributes.get("install").value
|
||
73 | if value == "True" or value == "true": |
||
74 | self._install = True |
||
75 | |||
76 | def execute(self): |
||
77 | dmplugin = PlugInManager().getPlugInInstance("DepManPlugIn")
|
||
78 | if dmplugin == None: |
||
79 | self.reportError("DepMan PlugIn not found") |
||
80 | return False |
||
81 | if self._projectPath=="": |
||
82 | self.reportError("Missing required project path option") |
||
83 | return False |
||
84 | |||
85 | self._projectPath = os.path.abspath(self._projectPath) |
||
86 | if self._compiler=="": |
||
87 | self._compiler = dmplugin.getOSCompiler()
|
||
88 | |||
89 | if self._projectName == "": |
||
90 | self._projectName = os.path.basename(self._projectPath) |
||
91 | |||
92 | if self._projectGenerationPath == "": |
||
93 | self._projectGenerationPath = os.path.join(self._projectPath, "BMCMake") |
||
94 | else:
|
||
95 | self._projectGenerationPath = os.path.abspath(self._projectGenerationPath) |
||
96 | |||
97 | print "Executing Plugin:" + str(self.__class__) |
||
98 | platform = dmplugin.getOSPlatform() |
||
99 | if platform == "linux" or platform == "mac": |
||
100 | self.__executeUnix()
|
||
101 | else:
|
||
102 | self.__executeVS()
|
||
103 | return True |
||
104 | |||
105 | def __executeUnix(self): |
||
106 | #make install
|
||
107 | print "CPUs Detected:" + str(self.__cpuCount()) |
||
108 | cmdCompiler = self._supportedCompilers[self._compiler] + " -j"+str(self.__cpuCount()) |
||
109 | if self._install: |
||
110 | cmdCompiler += " install"
|
||
111 | olddir = os.getcwd() |
||
112 | os.chdir(self._projectGenerationPath)
|
||
113 | os.system(cmdCompiler) |
||
114 | os.chdir(olddir) |
||
115 | |||
116 | def __executeVS(self): |
||
117 | #devenv.exe /build Release /project INSTALL ../CMake/libjosg.sln
|
||
118 | cmdCompiler = self._supportedCompilers[self._compiler] |
||
119 | cmdCompiler += " " + self._projectName + ".sln" |
||
120 | cmdCompiler += " /build Release"
|
||
121 | if self._install: |
||
122 | cmdCompiler += " /project INSTALL"
|
||
123 | else:
|
||
124 | cmdCompiler += " /project ALL_BUILD"
|
||
125 | olddir = os.getcwd() |
||
126 | os.chdir(self._projectGenerationPath)
|
||
127 | os.system(cmdCompiler) |
||
128 | os.chdir(olddir) |
||
129 | |||
130 | def __cpuCount(self): |
||
131 | '''
|
||
132 | Returns the number of CPUs in the system
|
||
133 | '''
|
||
134 | if sys.platform == 'win32': |
||
135 | try:
|
||
136 | num = int(os.environ['NUMBER_OF_PROCESSORS']) |
||
137 | except (ValueError, KeyError): |
||
138 | pass
|
||
139 | elif sys.platform == 'darwin': |
||
140 | try:
|
||
141 | num = int(os.popen('sysctl -n hw.ncpu').read()) |
||
142 | except ValueError: |
||
143 | pass
|
||
144 | else:
|
||
145 | try:
|
||
146 | num = os.sysconf('SC_NPROCESSORS_ONLN')
|
||
147 | except (ValueError, OSError, AttributeError): |
||
148 | pass
|
||
149 | |||
150 | if num >= 1: |
||
151 | return num
|
||
152 | return 1 |
||
153 | |||
154 | |||
155 | PlugInManager().registerPlugIn("CompileSolutionPlugIn", CompileSolutionPlugIn())
|
||
156 |