399b9266bb0765d92bd14f3b88c5de6e8adc8cf7
6 import lttng_ivc
.settings
as Settings
8 from lttng_ivc
.utils
.utils
import sha256_checksum
10 _logger
= logging
.getLogger('project')
12 class Project(object):
14 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
16 self
.git_path
= git_path
19 """ Custom configure flags in the for of ['-x', 'arg']"""
20 self
.custom_configure_flags
= []
21 ccache
= shutil
.which("ccache")
22 if ccache
is not None:
23 self
.custom_configure_flags
.append("CC={} gcc".format(ccache
))
24 self
.custom_configure_flags
.append("CXX={} g++".format(ccache
))
25 self
.custom_configure_flags
.append("CFLAGS=-g -O0".format(ccache
))
27 """ A collection of Project dependencies """
28 self
.dependencies
= {}
29 # used for project cache and pickle validation
30 self
._immutable
= False
31 self
._py
_file
_checksum
= sha256_checksum(Settings
.project_py_file_location
)
35 self
.isConfigured
= False
36 self
.isInstalled
= False
39 self
.log_path
= os
.path
.join(tmpdir
, "log")
40 self
.source_path
= os
.path
.join(tmpdir
, "source")
41 self
.installation_path
= os
.path
.join(tmpdir
, "install")
43 if os
.path
.isdir(self
.basedir
):
44 # Perform cleanup since it should not happen
45 shutil
.rmtree(self
.basedir
)
47 os
.makedirs(self
.log_path
)
48 os
.makedirs(self
.source_path
)
49 os
.makedirs(self
.installation_path
)
51 self
.special_env_variables
= {}
53 # Init the repo for work
57 def add_special_env_variable(self
, key
, value
):
58 if key
in self
.special_env_variables
:
59 _logger
.warning("{} Special var {} is already defined".format(
61 raise Exception("Multiple definition of a special environment variable")
62 self
.special_env_variables
[key
] = value
64 def get_cppflags(self
):
65 cppflags
= ["-I{}/include".format(self
.installation_path
)]
66 for key
, dep
in self
.dependencies
.items():
67 cppflags
.append(dep
.get_cppflags())
69 return " ".join(cppflags
)
71 def get_ldflags(self
):
72 ldflags
= ["-L{}/lib".format(self
.installation_path
)]
73 for key
, dep
in self
.dependencies
.items():
74 ldflags
.append(dep
.get_ldflags())
75 return " ".join(ldflags
)
77 def get_ld_library_path(self
):
78 library_path
= ["{}/lib".format(self
.installation_path
)]
79 for key
, dep
in self
.dependencies
.items():
80 library_path
.append(dep
.get_ld_library_path())
81 return ":".join(library_path
)
83 def get_bin_path(self
):
84 bin_path
= ["{}/bin".format(self
.installation_path
)]
85 for key
, dep
in self
.dependencies
.items():
86 bin_path
.append(dep
.get_bin_path())
87 return ":".join(bin_path
)
90 """Modify environment to reflect dependency"""
91 env_var
= {"CPPFLAGS": (self
.get_cppflags(), " "),
92 "LDFLAGS": (self
.get_ldflags(), " "),
93 "LD_LIBRARY_PATH": (self
.get_ld_library_path(), ":"),
96 env
= os
.environ
.copy()
98 for var
, value
in self
.special_env_variables
.items():
100 # Raise for now since no special cases is known
101 _logger
.warning("{} Special var {} is already defined".format(
103 raise Exception("Multiple definition of a special environment variable")
107 for key
, dep
in self
.dependencies
.items():
108 # Extra space just in case
109 for var
, value
in dep
.special_env_variables
.items():
111 # Raise for now since no special cases is known
112 _logger
.warning("{} Special var {} is already defined".format(
114 raise Exception("Multiple definition of a special environment variable")
118 for var
, (value
, delimiter
) in env_var
.items():
122 env
[var
] = delimiter
.join(tmp
)
128 Perform the bootstrap, configuration, build and install the
129 project. Build dependencies if not already built
131 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
135 raise Exception("Object is immutable. Illegal autobuild")
137 for key
, dep
in self
.dependencies
.items():
140 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
141 raise Exception("Project steps where manually triggered. Can't autobuild")
143 _logger
.debug("{} Autobuild configure".format(self
.label
))
146 except subprocess
.CalledProcessError
as e
:
147 _logger
.error("{} Configure failed. See {} for more details.".format(self
.label
, self
.log_path
))
150 _logger
.debug("{} Autobuild build".format(self
.label
))
153 except subprocess
.CalledProcessError
as e
:
154 _logger
.error("{} Build failed. See {} for more details.".format(self
.label
, self
.log_path
))
157 _logger
.debug("{} Autobuild install".format(self
.label
))
160 except subprocess
.CalledProcessError
as e
:
161 _logger
.error("{} Install failed. See {} for more details.".format(self
.label
, self
.log_path
))
166 raise Exception("Object is immutable. Illegal checkout")
168 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
169 commit
= repo
.commit(self
.sha1
)
170 repo
.head
.reference
= commit
171 assert repo
.head
.is_detached
172 repo
.head
.reset(index
=True, working_tree
=True)
176 Bootstap the project. Raise subprocess.CalledProcessError on
180 raise Exception("Object is immutable. Illegal bootstrap")
182 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
183 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
185 os
.chdir(self
.source_path
)
186 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
187 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
193 Configure the project.
194 Raises subprocess.CalledProcessError on configure error
197 raise Exception("Object is immutable. Illegal configure")
199 # Check that all our dependencies were actually installed
200 for key
, dep
in self
.dependencies
.items():
201 if not dep
.isInstalled
:
202 # TODO: Custom exception here Dependency Error
203 raise Exception("Dependency project flagged as not installed")
205 out
= os
.path
.join(self
.log_path
, "configure.out")
206 err
= os
.path
.join(self
.log_path
, "configure.err")
208 os
.chdir(self
.source_path
)
209 args
= ['./configure']
210 prefix
= '--prefix={}'.format(self
.installation_path
)
212 args
.extend(self
.custom_configure_flags
)
214 # TODO: log output and add INFO log point
215 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
216 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
219 self
.isConfigured
= True
224 Build the project. Raise subprocess.CalledProcessError on build
228 raise Exception("Object is immutable. Illegal build")
230 out
= os
.path
.join(self
.log_path
, "build.out")
231 err
= os
.path
.join(self
.log_path
, "build.err")
233 os
.chdir(self
.source_path
)
237 # Number of usable cpu
238 # https://docs.python.org/3/library/os.html#os.cpu_count
239 num_cpu
= str(len(os
.sched_getaffinity(0)))
244 # TODO: log output and add INFO log point with args
245 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
246 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
254 Install the project. Raise subprocess.CalledProcessError on
258 raise Exception("Object is immutable. Illegal install")
260 out
= os
.path
.join(self
.log_path
, "install.out")
261 err
= os
.path
.join(self
.log_path
, "install.err")
263 os
.chdir(self
.source_path
)
264 args
= ['make', 'install']
266 # TODO: log output and add INFO log point
267 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
268 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
271 self
.isInstalled
= True
275 if os
.path
.exists(self
.source_path
):
276 shutil
.rmtree(self
.source_path
)
277 if os
.path
.exists(self
.installation_path
):
278 shutil
.rmtree(self
.installation_path
)
281 class Lttng_modules(Project
):
282 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
283 super(Lttng_modules
, self
).__init
__(label
=label
, git_path
=git_path
,
284 sha1
=sha1
, tmpdir
=tmpdir
)
285 self
.add_special_env_variable("MODPROBE_OPTIONS","-d {}".format(self
.installation_path
))
295 raise Exception("Object is immutable. Illegal install")
296 os
.chdir(self
.source_path
)
297 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
299 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
300 stderr
=subprocess
.PIPE
)
303 # Perform a local depmod
304 args
= ['depmod', '-b', self
.installation_path
]
305 p
= subprocess
.run(args
, env
=self
.get_env())
307 self
.isInstalled
= True
310 class Lttng_ust(Project
):
311 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
312 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
313 sha1
=sha1
, tmpdir
=tmpdir
)
314 self
.custom_configure_flags
.extend(['--disable-man-pages'])
317 class Lttng_tools(Project
):
318 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
319 super(Lttng_tools
, self
).__init
__(label
=label
, git_path
=git_path
,
320 sha1
=sha1
, tmpdir
=tmpdir
)
321 self
.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH",
322 os
.path
.join(self
.installation_path
, "share/xml/lttng/"))
325 class Babeltrace(Project
):
This page took 0.037955 seconds and 4 git commands to generate.