6 import lttng_ivc
.settings
as Settings
8 from lttng_ivc
.utils
.utils
import sha256_checksum
9 from lttng_ivc
.utils
.utils
import find_dir
, find_file
11 _logger
= logging
.getLogger('project')
13 class Project(object):
15 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
17 self
.git_path
= git_path
20 """ Custom configure flags in the for of ['-x', 'arg']"""
21 self
.custom_configure_flags
= []
22 ccache
= shutil
.which("ccache")
23 if ccache
is not None:
24 self
.custom_configure_flags
.append("CC={} gcc".format(ccache
))
25 self
.custom_configure_flags
.append("CXX={} g++".format(ccache
))
26 self
.custom_configure_flags
.append("CFLAGS=-g -O0".format(ccache
))
28 """ A collection of Project dependencies """
29 self
.dependencies
= {}
30 # used for project cache and pickle validation
31 self
._immutable
= False
32 self
._py
_file
_checksum
= sha256_checksum(Settings
.project_py_file_location
)
36 self
.isConfigured
= False
37 self
.isInstalled
= False
41 self
.log_path
= os
.path
.join(tmpdir
, "log")
42 self
.source_path
= os
.path
.join(tmpdir
, "source")
43 self
.installation_path
= os
.path
.join(tmpdir
, "install")
45 if os
.path
.isdir(self
.basedir
):
46 # Perform cleanup since it should not happen
47 shutil
.rmtree(self
.basedir
)
49 os
.makedirs(self
.log_path
)
50 os
.makedirs(self
.source_path
)
51 os
.makedirs(self
.installation_path
)
53 self
.special_env_variables
= {}
55 # Init the repo for work
59 def add_special_env_variable(self
, key
, value
):
60 if key
in self
.special_env_variables
:
61 _logger
.warning("{} Special var {} is already defined".format(
63 raise Exception("Multiple definition of a special environment variable")
64 self
.special_env_variables
[key
] = value
66 def get_cppflags(self
):
67 cppflags
= ["-I{}/include".format(self
.installation_path
)]
68 for key
, dep
in self
.dependencies
.items():
69 cppflags
.append(dep
.get_cppflags())
71 return " ".join(cppflags
)
73 def get_ldflags(self
):
74 ldflags
= ["-L{}/lib".format(self
.installation_path
)]
75 for key
, dep
in self
.dependencies
.items():
76 ldflags
.append(dep
.get_ldflags())
77 return " ".join(ldflags
)
79 def get_ld_library_path(self
):
80 library_path
= ["{}/lib".format(self
.installation_path
)]
81 for key
, dep
in self
.dependencies
.items():
82 library_path
.append(dep
.get_ld_library_path())
83 return ":".join(library_path
)
85 def get_bin_path(self
):
86 bin_path
= ["{}/bin".format(self
.installation_path
)]
87 for key
, dep
in self
.dependencies
.items():
88 bin_path
.append(dep
.get_bin_path())
89 return ":".join(bin_path
)
92 """Modify environment to reflect dependency"""
93 env_var
= {"CPPFLAGS": (self
.get_cppflags(), " "),
94 "LDFLAGS": (self
.get_ldflags(), " "),
95 "LD_LIBRARY_PATH": (self
.get_ld_library_path(), ":"),
98 env
= os
.environ
.copy()
100 for var
, value
in self
.special_env_variables
.items():
102 # Raise for now since no special cases is known
103 _logger
.warning("{} Special var {} is already defined".format(
105 raise Exception("Multiple definition of a special environment variable")
109 for key
, dep
in self
.dependencies
.items():
110 # Extra space just in case
111 for var
, value
in dep
.special_env_variables
.items():
113 # Raise for now since no special cases is known
114 _logger
.warning("{} Special var {} is already defined".format(
116 raise Exception("Multiple definition of a special environment variable")
120 for var
, (value
, delimiter
) in env_var
.items():
124 env
[var
] = delimiter
.join(tmp
)
130 Perform the bootstrap, configuration, build and install the
131 project. Build dependencies if not already built
133 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
137 raise Exception("Object is immutable. Illegal autobuild")
139 for key
, dep
in self
.dependencies
.items():
142 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
143 raise Exception("Project steps where manually triggered. Can't autobuild")
145 _logger
.debug("{} Autobuild configure".format(self
.label
))
148 except subprocess
.CalledProcessError
as e
:
149 _logger
.error("{} Configure failed. See {} for more details.".format(self
.label
, self
.log_path
))
152 _logger
.debug("{} Autobuild build".format(self
.label
))
155 except subprocess
.CalledProcessError
as e
:
156 _logger
.error("{} Build failed. See {} for more details.".format(self
.label
, self
.log_path
))
159 _logger
.debug("{} Autobuild install".format(self
.label
))
162 except subprocess
.CalledProcessError
as e
:
163 _logger
.error("{} Install failed. See {} for more details.".format(self
.label
, self
.log_path
))
168 raise Exception("Object is immutable. Illegal checkout")
170 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
171 commit
= repo
.commit(self
.sha1
)
172 repo
.head
.reference
= commit
173 assert repo
.head
.is_detached
174 repo
.head
.reset(index
=True, working_tree
=True)
178 Bootstap the project. Raise subprocess.CalledProcessError on
182 raise Exception("Object is immutable. Illegal bootstrap")
184 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
185 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
187 os
.chdir(self
.source_path
)
188 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
189 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
195 Configure the project.
196 Raises subprocess.CalledProcessError on configure error
199 raise Exception("Object is immutable. Illegal configure")
201 # Check that all our dependencies were actually installed
202 for key
, dep
in self
.dependencies
.items():
203 if not dep
.isInstalled
:
204 # TODO: Custom exception here Dependency Error
205 raise Exception("Dependency project flagged as not installed")
207 out
= os
.path
.join(self
.log_path
, "configure.out")
208 err
= os
.path
.join(self
.log_path
, "configure.err")
210 os
.chdir(self
.source_path
)
211 args
= ['./configure']
212 prefix
= '--prefix={}'.format(self
.installation_path
)
214 args
.extend(self
.custom_configure_flags
)
216 # TODO: log output and add INFO log point
217 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
218 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
221 self
.isConfigured
= True
226 Build the project. Raise subprocess.CalledProcessError on build
230 raise Exception("Object is immutable. Illegal build")
232 out
= os
.path
.join(self
.log_path
, "build.out")
233 err
= os
.path
.join(self
.log_path
, "build.err")
235 os
.chdir(self
.source_path
)
239 # Number of usable cpu
240 # https://docs.python.org/3/library/os.html#os.cpu_count
241 num_cpu
= str(len(os
.sched_getaffinity(0)))
246 # TODO: log output and add INFO log point with args
247 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
248 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
256 Install the project. Raise subprocess.CalledProcessError on
260 raise Exception("Object is immutable. Illegal install")
262 out
= os
.path
.join(self
.log_path
, "install.out")
263 err
= os
.path
.join(self
.log_path
, "install.err")
265 os
.chdir(self
.source_path
)
266 args
= ['make', 'install']
268 # TODO: log output and add INFO log point
269 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
270 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
273 self
.isInstalled
= True
277 if os
.path
.exists(self
.source_path
):
278 shutil
.rmtree(self
.source_path
)
279 if os
.path
.exists(self
.installation_path
):
280 shutil
.rmtree(self
.installation_path
)
283 class Lttng_modules(Project
):
284 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
285 super(Lttng_modules
, self
).__init
__(label
=label
, git_path
=git_path
,
286 sha1
=sha1
, tmpdir
=tmpdir
)
287 self
.add_special_env_variable("MODPROBE_OPTIONS","-d {}".format(self
.installation_path
))
297 raise Exception("Object is immutable. Illegal install")
298 os
.chdir(self
.source_path
)
299 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
301 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
302 stderr
=subprocess
.PIPE
)
305 # Perform a local depmod
306 args
= ['depmod', '-b', self
.installation_path
]
307 p
= subprocess
.run(args
, env
=self
.get_env())
309 self
.isInstalled
= True
312 class Lttng_ust(Project
):
313 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
314 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
315 sha1
=sha1
, tmpdir
=tmpdir
)
316 self
.custom_configure_flags
.extend(['--disable-man-pages'])
317 self
.custom_configure_flags
.extend(['--enable-python-agent'])
318 self
.custom_configure_flags
.extend(['--enable-java-agent-jul'])
320 jul_path
= os
.path
.join(self
.installation_path
,
321 "share/java/liblttng-ust-agent.jar")
322 classpath
= ":".join([jul_path
, Settings
.log4j_class_path
, '.'])
323 self
.add_special_env_variable("CLASSPATH", classpath
)
326 super(Lttng_ust
, self
).install()
327 python_path
= find_dir(self
.installation_path
, "lttngust")
329 # Fetch the parent of lttngust folder
330 python_path
= os
.path
.dirname(python_path
)
331 self
.add_special_env_variable("PYTHONPATH", python_path
)
335 class Lttng_tools(Project
):
336 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
337 super(Lttng_tools
, self
).__init
__(label
=label
, git_path
=git_path
,
338 sha1
=sha1
, tmpdir
=tmpdir
)
339 self
.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH",
340 os
.path
.join(self
.installation_path
, "share/xml/lttng/"))
343 for xsd
in Settings
.mi_xsd_file_name
:
344 mi
= find_file(self
.source_path
, xsd
)
348 raise Exception("MI xsd not found")
352 class Babeltrace(Project
):
This page took 0.039239 seconds and 5 git commands to generate.