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
28 from lttng_ivc
.utils
.utils
import sha256_checksum
29 from lttng_ivc
.utils
.utils
import find_dir
, find_file
31 _logger
= logging
.getLogger('project')
33 class Project(object):
35 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
37 self
.git_path
= git_path
40 """ Custom configure flags in the for of ['-x', 'arg']"""
41 self
.custom_configure_flags
= []
42 ccache
= shutil
.which("ccache")
43 if ccache
is not None:
44 self
.custom_configure_flags
.append("CC={} gcc".format(ccache
))
45 self
.custom_configure_flags
.append("CXX={} g++".format(ccache
))
46 self
.custom_configure_flags
.append("CFLAGS=-g -O0".format(ccache
))
48 """ A collection of Project dependencies """
49 self
.dependencies
= {}
50 # used for project cache and pickle validation
51 self
._immutable
= False
52 self
._py
_file
_checksum
= sha256_checksum(Settings
.project_py_file_location
)
56 self
.isConfigured
= False
57 self
.isInstalled
= False
61 self
.log_path
= os
.path
.join(tmpdir
, "log")
62 self
.source_path
= os
.path
.join(tmpdir
, "source")
63 self
.installation_path
= os
.path
.join(tmpdir
, "install")
65 if os
.path
.isdir(self
.basedir
):
66 # Perform cleanup since it should not happen
67 shutil
.rmtree(self
.basedir
)
69 os
.makedirs(self
.log_path
)
70 os
.makedirs(self
.source_path
)
71 os
.makedirs(self
.installation_path
)
73 self
.special_env_variables
= {}
75 # Init the repo for work
79 def add_special_env_variable(self
, key
, value
):
80 if key
in self
.special_env_variables
:
81 _logger
.warning("{} Special var {} is already defined".format(
83 raise Exception("Multiple definition of a special environment variable")
84 self
.special_env_variables
[key
] = value
86 def get_cppflags(self
):
87 cppflags
= ["-I{}/include".format(self
.installation_path
)]
88 for key
, dep
in self
.dependencies
.items():
89 cppflags
.append(dep
.get_cppflags())
91 return " ".join(cppflags
)
93 def get_ldflags(self
):
94 ldflags
= ["-L{}/lib".format(self
.installation_path
)]
95 for key
, dep
in self
.dependencies
.items():
96 ldflags
.append(dep
.get_ldflags())
97 return " ".join(ldflags
)
99 def get_ld_library_path(self
):
100 library_path
= ["{}/lib".format(self
.installation_path
)]
101 for key
, dep
in self
.dependencies
.items():
102 library_path
.append(dep
.get_ld_library_path())
103 return ":".join(library_path
)
105 def get_bin_path(self
):
106 bin_path
= ["{}/bin".format(self
.installation_path
)]
107 for key
, dep
in self
.dependencies
.items():
108 bin_path
.append(dep
.get_bin_path())
109 return ":".join(bin_path
)
112 """Modify environment to reflect dependency"""
113 env_var
= {"CPPFLAGS": (self
.get_cppflags(), " "),
114 "LDFLAGS": (self
.get_ldflags(), " "),
115 "LD_LIBRARY_PATH": (self
.get_ld_library_path(), ":"),
118 env
= os
.environ
.copy()
120 for var
, value
in self
.special_env_variables
.items():
122 # Raise for now since no special cases is known
123 _logger
.warning("{} Special var {} is already defined".format(
125 raise Exception("Multiple definition of a special environment variable")
129 for key
, dep
in self
.dependencies
.items():
130 # Extra space just in case
131 for var
, value
in dep
.special_env_variables
.items():
133 # Raise for now since no special cases is known
134 _logger
.warning("{} Special var {} is already defined".format(
136 raise Exception("Multiple definition of a special environment variable")
140 for var
, (value
, delimiter
) in env_var
.items():
144 env
[var
] = delimiter
.join(tmp
)
150 Perform the bootstrap, configuration, build and install the
151 project. Build dependencies if not already built
153 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
157 raise Exception("Object is immutable. Illegal autobuild")
159 for key
, dep
in self
.dependencies
.items():
162 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
163 raise Exception("Project steps where manually triggered. Can't autobuild")
165 _logger
.debug("{} Autobuild configure".format(self
.label
))
168 except subprocess
.CalledProcessError
as e
:
169 _logger
.error("{} Configure failed. See {} for more details.".format(self
.label
, self
.log_path
))
172 _logger
.debug("{} Autobuild build".format(self
.label
))
175 except subprocess
.CalledProcessError
as e
:
176 _logger
.error("{} Build failed. See {} for more details.".format(self
.label
, self
.log_path
))
179 _logger
.debug("{} Autobuild install".format(self
.label
))
182 except subprocess
.CalledProcessError
as e
:
183 _logger
.error("{} Install failed. See {} for more details.".format(self
.label
, self
.log_path
))
188 raise Exception("Object is immutable. Illegal checkout")
190 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
191 commit
= repo
.commit(self
.sha1
)
192 repo
.head
.reference
= commit
193 assert repo
.head
.is_detached
194 repo
.head
.reset(index
=True, working_tree
=True)
198 Bootstap the project. Raise subprocess.CalledProcessError on
202 raise Exception("Object is immutable. Illegal bootstrap")
204 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
205 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
207 os
.chdir(self
.source_path
)
208 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
209 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
215 Configure the project.
216 Raises subprocess.CalledProcessError on configure error
219 raise Exception("Object is immutable. Illegal configure")
221 # Check that all our dependencies were actually installed
222 for key
, dep
in self
.dependencies
.items():
223 if not dep
.isInstalled
:
224 # TODO: Custom exception here Dependency Error
225 raise Exception("Dependency project flagged as not installed")
227 out
= os
.path
.join(self
.log_path
, "configure.out")
228 err
= os
.path
.join(self
.log_path
, "configure.err")
230 os
.chdir(self
.source_path
)
231 args
= ['./configure']
232 prefix
= '--prefix={}'.format(self
.installation_path
)
234 args
.extend(self
.custom_configure_flags
)
236 # TODO: log output and add INFO log point
237 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
238 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
241 self
.isConfigured
= True
246 Build the project. Raise subprocess.CalledProcessError on build
250 raise Exception("Object is immutable. Illegal build")
252 out
= os
.path
.join(self
.log_path
, "build.out")
253 err
= os
.path
.join(self
.log_path
, "build.err")
255 os
.chdir(self
.source_path
)
259 # Number of usable cpu
260 # https://docs.python.org/3/library/os.html#os.cpu_count
261 num_cpu
= str(len(os
.sched_getaffinity(0)))
266 # TODO: log output and add INFO log point with args
267 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
268 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
276 Install the project. Raise subprocess.CalledProcessError on
280 raise Exception("Object is immutable. Illegal install")
282 out
= os
.path
.join(self
.log_path
, "install.out")
283 err
= os
.path
.join(self
.log_path
, "install.err")
285 os
.chdir(self
.source_path
)
286 args
= ['make', 'install']
288 # TODO: log output and add INFO log point
289 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
290 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
293 self
.isInstalled
= True
297 if os
.path
.exists(self
.source_path
):
298 shutil
.rmtree(self
.source_path
)
299 if os
.path
.exists(self
.installation_path
):
300 shutil
.rmtree(self
.installation_path
)
303 class Lttng_modules(Project
):
304 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
305 super(Lttng_modules
, self
).__init
__(label
=label
, git_path
=git_path
,
306 sha1
=sha1
, tmpdir
=tmpdir
)
307 self
.add_special_env_variable("MODPROBE_OPTIONS","-d {}".format(self
.installation_path
))
317 raise Exception("Object is immutable. Illegal install")
318 os
.chdir(self
.source_path
)
319 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
321 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
322 stderr
=subprocess
.PIPE
)
325 # Perform a local depmod
326 args
= ['depmod', '-b', self
.installation_path
]
327 p
= subprocess
.run(args
, env
=self
.get_env())
329 self
.isInstalled
= True
333 super(Lttng_modules
, self
).autobuild()
334 except subprocess
.CalledProcessError
as e
:
338 class Lttng_ust(Project
):
339 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
340 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
341 sha1
=sha1
, tmpdir
=tmpdir
)
342 self
.custom_configure_flags
.extend(['--disable-man-pages'])
343 self
.custom_configure_flags
.extend(['--enable-python-agent'])
344 self
.custom_configure_flags
.extend(['--enable-java-agent-jul'])
346 jul_path
= os
.path
.join(self
.installation_path
,
347 "share/java/liblttng-ust-agent.jar")
348 classpath
= ":".join([jul_path
, Settings
.log4j_class_path
, '.'])
349 self
.add_special_env_variable("CLASSPATH", classpath
)
352 super(Lttng_ust
, self
).install()
353 python_path
= find_dir(self
.installation_path
, "lttngust")
355 # Fetch the parent of lttngust folder
356 python_path
= os
.path
.dirname(python_path
)
357 self
.add_special_env_variable("PYTHONPATH", python_path
)
361 class Lttng_tools(Project
):
362 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
363 super(Lttng_tools
, self
).__init
__(label
=label
, git_path
=git_path
,
364 sha1
=sha1
, tmpdir
=tmpdir
)
365 self
.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH",
366 os
.path
.join(self
.installation_path
, "share/xml/lttng/"))
369 for xsd
in Settings
.mi_xsd_file_name
:
370 mi
= find_file(self
.source_path
, xsd
)
374 raise Exception("MI xsd not found")
378 class Babeltrace(Project
):
This page took 0.042801 seconds and 5 git commands to generate.