1 # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in all
11 # copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 import lttng_ivc
.settings
as Settings
29 from lttng_ivc
.utils
.utils
import sha256_checksum
30 from lttng_ivc
.utils
.utils
import find_dir
, find_file
32 _logger
= logging
.getLogger('project')
34 class Project(object):
36 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
38 self
.git_path
= git_path
41 """ Custom configure flags in the for of ['-x', 'arg']"""
42 self
.custom_configure_flags
= []
43 ccache
= shutil
.which("ccache")
44 if ccache
is not None:
45 self
.custom_configure_flags
.append("CC={} gcc".format(ccache
))
46 self
.custom_configure_flags
.append("CXX={} g++".format(ccache
))
47 self
.custom_configure_flags
.append("CFLAGS=-g -O0".format(ccache
))
49 """ A collection of Project dependencies """
50 self
.dependencies
= {}
51 # used for project cache and pickle validation
52 self
._immutable
= False
53 self
._py
_file
_checksum
= sha256_checksum(Settings
.project_py_file_location
)
57 self
.isConfigured
= False
58 self
.isInstalled
= False
62 self
.log_path
= os
.path
.join(tmpdir
, "log")
63 self
.source_path
= os
.path
.join(tmpdir
, "source")
64 self
.installation_path
= os
.path
.join(tmpdir
, "install")
66 if os
.path
.isdir(self
.basedir
):
67 # Perform cleanup since it should not happen
68 shutil
.rmtree(self
.basedir
)
70 os
.makedirs(self
.log_path
)
71 os
.makedirs(self
.source_path
)
72 os
.makedirs(self
.installation_path
)
74 self
.special_env_variables
= {}
76 # Init the repo for work
80 def add_special_env_variable(self
, key
, value
):
81 if key
in self
.special_env_variables
:
82 _logger
.warning("{} Special var {} is already defined".format(
84 raise Exception("Multiple definition of a special environment variable")
85 self
.special_env_variables
[key
] = value
87 def get_cppflags(self
):
88 cppflags
= ["-I{}/include".format(self
.installation_path
)]
89 for key
, dep
in self
.dependencies
.items():
90 cppflags
.append(dep
.get_cppflags())
92 return " ".join(cppflags
)
94 def get_ldflags(self
):
95 ldflags
= ["-L{}/lib".format(self
.installation_path
)]
96 for key
, dep
in self
.dependencies
.items():
97 ldflags
.append(dep
.get_ldflags())
98 return " ".join(ldflags
)
100 def get_ld_library_path(self
):
101 library_path
= ["{}/lib".format(self
.installation_path
)]
102 for key
, dep
in self
.dependencies
.items():
103 library_path
.append(dep
.get_ld_library_path())
104 return ":".join(library_path
)
106 def get_bin_path(self
):
107 bin_path
= ["{}/bin".format(self
.installation_path
)]
108 for key
, dep
in self
.dependencies
.items():
109 bin_path
.append(dep
.get_bin_path())
110 return ":".join(bin_path
)
113 """Modify environment to reflect dependency"""
114 env_var
= {"CPPFLAGS": (self
.get_cppflags(), " "),
115 "LDFLAGS": (self
.get_ldflags(), " "),
116 "LD_LIBRARY_PATH": (self
.get_ld_library_path(), ":"),
119 env
= os
.environ
.copy()
121 for var
, value
in self
.special_env_variables
.items():
123 if var
== "LD_LIBRARY_PATH":
124 env
[var
] = ":".join([env
[var
], value
])
125 elif var
== "CPPFLAGS" or var
== "CFLAGS" or var
== "LDFLAGS":
126 env
[var
] = " ".join([env
[var
], value
])
128 _logger
.warning("{} Special var {} is already defined".format(
130 raise Exception("Multiple definition of a special environment variable")
134 for key
, dep
in self
.dependencies
.items():
135 # Extra space just in case
136 for var
, value
in dep
.special_env_variables
.items():
138 # Raise for now since no special cases is known
139 _logger
.warning("{} Special var {} is already defined".format(
141 raise Exception("Multiple definition of a special environment variable")
145 for var
, (value
, delimiter
) in env_var
.items():
149 env
[var
] = delimiter
.join(tmp
)
155 Perform the bootstrap, configuration, build and install the
156 project. Build dependencies if not already built
158 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
162 raise Exception("Object is immutable. Illegal autobuild")
164 for key
, dep
in self
.dependencies
.items():
167 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
168 raise Exception("Project steps where manually triggered. Can't autobuild")
170 _logger
.debug("{} Autobuild configure".format(self
.label
))
173 except subprocess
.CalledProcessError
as e
:
174 _logger
.error("{} Configure failed. See {} for more details.".format(self
.label
, self
.log_path
))
177 _logger
.debug("{} Autobuild build".format(self
.label
))
180 except subprocess
.CalledProcessError
as e
:
181 _logger
.error("{} Build failed. See {} for more details.".format(self
.label
, self
.log_path
))
184 _logger
.debug("{} Autobuild install".format(self
.label
))
187 except subprocess
.CalledProcessError
as e
:
188 _logger
.error("{} Install failed. See {} for more details.".format(self
.label
, self
.log_path
))
193 raise Exception("Object is immutable. Illegal checkout")
195 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
196 commit
= repo
.commit(self
.sha1
)
197 repo
.head
.reference
= commit
198 assert repo
.head
.is_detached
199 repo
.head
.reset(index
=True, working_tree
=True)
203 Bootstap the project. Raise subprocess.CalledProcessError on
207 raise Exception("Object is immutable. Illegal bootstrap")
209 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
210 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
212 os
.chdir(self
.source_path
)
213 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
214 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
220 Configure the project.
221 Raises subprocess.CalledProcessError on configure error
224 raise Exception("Object is immutable. Illegal configure")
226 # Check that all our dependencies were actually installed
227 for key
, dep
in self
.dependencies
.items():
228 if not dep
.isInstalled
:
229 # TODO: Custom exception here Dependency Error
230 raise Exception("Dependency project flagged as not installed")
232 out
= os
.path
.join(self
.log_path
, "configure.out")
233 err
= os
.path
.join(self
.log_path
, "configure.err")
234 env_file
= os
.path
.join(self
.log_path
, "configure.env")
238 with
open(env_file
, 'w') as tmp
:
239 pprint
.pprint(env
, stream
=tmp
)
241 os
.chdir(self
.source_path
)
242 args
= ['./configure']
243 prefix
= '--prefix={}'.format(self
.installation_path
)
245 args
.extend(self
.custom_configure_flags
)
247 # TODO: log output and add INFO log point
248 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
249 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
252 self
.isConfigured
= True
257 Build the project. Raise subprocess.CalledProcessError on build
261 raise Exception("Object is immutable. Illegal build")
263 out
= os
.path
.join(self
.log_path
, "build.out")
264 err
= os
.path
.join(self
.log_path
, "build.err")
266 os
.chdir(self
.source_path
)
270 # Number of usable cpu
271 # https://docs.python.org/3/library/os.html#os.cpu_count
272 num_cpu
= str(len(os
.sched_getaffinity(0)))
277 # TODO: log output and add INFO log point with args
278 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
279 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
287 Install the project. Raise subprocess.CalledProcessError on
291 raise Exception("Object is immutable. Illegal install")
293 out
= os
.path
.join(self
.log_path
, "install.out")
294 err
= os
.path
.join(self
.log_path
, "install.err")
296 os
.chdir(self
.source_path
)
297 args
= ['make', 'install']
299 # TODO: log output and add INFO log point
300 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
301 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
304 self
.isInstalled
= True
308 if os
.path
.exists(self
.source_path
):
309 shutil
.rmtree(self
.source_path
)
310 if os
.path
.exists(self
.installation_path
):
311 shutil
.rmtree(self
.installation_path
)
314 class Lttng_modules(Project
):
315 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
316 super(Lttng_modules
, self
).__init
__(label
=label
, git_path
=git_path
,
317 sha1
=sha1
, tmpdir
=tmpdir
)
318 self
.add_special_env_variable("MODPROBE_OPTIONS","-d {}".format(self
.installation_path
))
328 raise Exception("Object is immutable. Illegal install")
329 os
.chdir(self
.source_path
)
330 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
332 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
333 stderr
=subprocess
.PIPE
)
336 # Perform a local depmod
337 args
= ['depmod', '-b', self
.installation_path
]
338 p
= subprocess
.run(args
, env
=self
.get_env())
340 self
.isInstalled
= True
344 super(Lttng_modules
, self
).autobuild()
345 except subprocess
.CalledProcessError
as e
:
349 class Lttng_ust(Project
):
350 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
351 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
352 sha1
=sha1
, tmpdir
=tmpdir
)
353 self
.custom_configure_flags
.extend(['--disable-man-pages'])
354 self
.custom_configure_flags
.extend(['--enable-python-agent'])
355 self
.custom_configure_flags
.extend(['--enable-java-agent-jul'])
357 jul_path
= os
.path
.join(self
.installation_path
,
358 "share/java/liblttng-ust-agent.jar")
359 classpath
= ":".join([jul_path
, '.'])
360 self
.add_special_env_variable("CLASSPATH", classpath
)
363 super(Lttng_ust
, self
).install()
364 python_path
= find_dir(self
.installation_path
, "lttngust")
366 # Fetch the parent of lttngust folder
367 python_path
= os
.path
.dirname(python_path
)
368 self
.add_special_env_variable("PYTHONPATH", python_path
)
372 class Lttng_tools(Project
):
373 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
374 super(Lttng_tools
, self
).__init
__(label
=label
, git_path
=git_path
,
375 sha1
=sha1
, tmpdir
=tmpdir
)
376 self
.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH",
377 os
.path
.join(self
.installation_path
, "share/xml/lttng/"))
380 for xsd
in Settings
.mi_xsd_file_name
:
381 mi
= find_file(self
.source_path
, xsd
)
385 raise Exception("MI xsd not found")
389 class Babeltrace(Project
):
This page took 0.043306 seconds and 6 git commands to generate.