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
40 self
.log_path
= os
.path
.join(tmpdir
, "log")
41 self
.source_path
= os
.path
.join(tmpdir
, "source")
42 self
.installation_path
= os
.path
.join(tmpdir
, "install")
44 if os
.path
.isdir(self
.basedir
):
45 # Perform cleanup since it should not happen
46 shutil
.rmtree(self
.basedir
)
48 os
.makedirs(self
.log_path
)
49 os
.makedirs(self
.source_path
)
50 os
.makedirs(self
.installation_path
)
52 self
.special_env_variables
= {}
54 # Init the repo for work
58 def add_special_env_variable(self
, key
, value
):
59 if key
in self
.special_env_variables
:
60 _logger
.warning("{} Special var {} is already defined".format(
62 raise Exception("Multiple definition of a special environment variable")
63 self
.special_env_variables
[key
] = value
65 def get_cppflags(self
):
66 cppflags
= ["-I{}/include".format(self
.installation_path
)]
67 for key
, dep
in self
.dependencies
.items():
68 cppflags
.append(dep
.get_cppflags())
70 return " ".join(cppflags
)
72 def get_ldflags(self
):
73 ldflags
= ["-L{}/lib".format(self
.installation_path
)]
74 for key
, dep
in self
.dependencies
.items():
75 ldflags
.append(dep
.get_ldflags())
76 return " ".join(ldflags
)
78 def get_ld_library_path(self
):
79 library_path
= ["{}/lib".format(self
.installation_path
)]
80 for key
, dep
in self
.dependencies
.items():
81 library_path
.append(dep
.get_ld_library_path())
82 return ":".join(library_path
)
84 def get_bin_path(self
):
85 bin_path
= ["{}/bin".format(self
.installation_path
)]
86 for key
, dep
in self
.dependencies
.items():
87 bin_path
.append(dep
.get_bin_path())
88 return ":".join(bin_path
)
91 """Modify environment to reflect dependency"""
92 env_var
= {"CPPFLAGS": (self
.get_cppflags(), " "),
93 "LDFLAGS": (self
.get_ldflags(), " "),
94 "LD_LIBRARY_PATH": (self
.get_ld_library_path(), ":"),
97 env
= os
.environ
.copy()
99 for var
, value
in self
.special_env_variables
.items():
101 # Raise for now since no special cases is known
102 _logger
.warning("{} Special var {} is already defined".format(
104 raise Exception("Multiple definition of a special environment variable")
108 for key
, dep
in self
.dependencies
.items():
109 # Extra space just in case
110 for var
, value
in dep
.special_env_variables
.items():
112 # Raise for now since no special cases is known
113 _logger
.warning("{} Special var {} is already defined".format(
115 raise Exception("Multiple definition of a special environment variable")
119 for var
, (value
, delimiter
) in env_var
.items():
123 env
[var
] = delimiter
.join(tmp
)
129 Perform the bootstrap, configuration, build and install the
130 project. Build dependencies if not already built
132 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
136 raise Exception("Object is immutable. Illegal autobuild")
138 for key
, dep
in self
.dependencies
.items():
141 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
142 raise Exception("Project steps where manually triggered. Can't autobuild")
144 _logger
.debug("{} Autobuild configure".format(self
.label
))
147 except subprocess
.CalledProcessError
as e
:
148 _logger
.error("{} Configure failed. See {} for more details.".format(self
.label
, self
.log_path
))
151 _logger
.debug("{} Autobuild build".format(self
.label
))
154 except subprocess
.CalledProcessError
as e
:
155 _logger
.error("{} Build failed. See {} for more details.".format(self
.label
, self
.log_path
))
158 _logger
.debug("{} Autobuild install".format(self
.label
))
161 except subprocess
.CalledProcessError
as e
:
162 _logger
.error("{} Install failed. See {} for more details.".format(self
.label
, self
.log_path
))
167 raise Exception("Object is immutable. Illegal checkout")
169 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
170 commit
= repo
.commit(self
.sha1
)
171 repo
.head
.reference
= commit
172 assert repo
.head
.is_detached
173 repo
.head
.reset(index
=True, working_tree
=True)
177 Bootstap the project. Raise subprocess.CalledProcessError on
181 raise Exception("Object is immutable. Illegal bootstrap")
183 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
184 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
186 os
.chdir(self
.source_path
)
187 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
188 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
194 Configure the project.
195 Raises subprocess.CalledProcessError on configure error
198 raise Exception("Object is immutable. Illegal configure")
200 # Check that all our dependencies were actually installed
201 for key
, dep
in self
.dependencies
.items():
202 if not dep
.isInstalled
:
203 # TODO: Custom exception here Dependency Error
204 raise Exception("Dependency project flagged as not installed")
206 out
= os
.path
.join(self
.log_path
, "configure.out")
207 err
= os
.path
.join(self
.log_path
, "configure.err")
209 os
.chdir(self
.source_path
)
210 args
= ['./configure']
211 prefix
= '--prefix={}'.format(self
.installation_path
)
213 args
.extend(self
.custom_configure_flags
)
215 # TODO: log output and add INFO log point
216 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
217 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
220 self
.isConfigured
= True
225 Build the project. Raise subprocess.CalledProcessError on build
229 raise Exception("Object is immutable. Illegal build")
231 out
= os
.path
.join(self
.log_path
, "build.out")
232 err
= os
.path
.join(self
.log_path
, "build.err")
234 os
.chdir(self
.source_path
)
238 # Number of usable cpu
239 # https://docs.python.org/3/library/os.html#os.cpu_count
240 num_cpu
= str(len(os
.sched_getaffinity(0)))
245 # TODO: log output and add INFO log point with args
246 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
247 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
255 Install the project. Raise subprocess.CalledProcessError on
259 raise Exception("Object is immutable. Illegal install")
261 out
= os
.path
.join(self
.log_path
, "install.out")
262 err
= os
.path
.join(self
.log_path
, "install.err")
264 os
.chdir(self
.source_path
)
265 args
= ['make', 'install']
267 # TODO: log output and add INFO log point
268 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
269 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
272 self
.isInstalled
= True
276 if os
.path
.exists(self
.source_path
):
277 shutil
.rmtree(self
.source_path
)
278 if os
.path
.exists(self
.installation_path
):
279 shutil
.rmtree(self
.installation_path
)
282 class Lttng_modules(Project
):
283 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
284 super(Lttng_modules
, self
).__init
__(label
=label
, git_path
=git_path
,
285 sha1
=sha1
, tmpdir
=tmpdir
)
286 self
.add_special_env_variable("MODPROBE_OPTIONS","-d {}".format(self
.installation_path
))
296 raise Exception("Object is immutable. Illegal install")
297 os
.chdir(self
.source_path
)
298 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
300 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
301 stderr
=subprocess
.PIPE
)
304 # Perform a local depmod
305 args
= ['depmod', '-b', self
.installation_path
]
306 p
= subprocess
.run(args
, env
=self
.get_env())
308 self
.isInstalled
= True
311 class Lttng_ust(Project
):
312 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
313 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
314 sha1
=sha1
, tmpdir
=tmpdir
)
315 self
.custom_configure_flags
.extend(['--disable-man-pages'])
318 class Lttng_tools(Project
):
319 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
320 super(Lttng_tools
, self
).__init
__(label
=label
, git_path
=git_path
,
321 sha1
=sha1
, tmpdir
=tmpdir
)
322 self
.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH",
323 os
.path
.join(self
.installation_path
, "share/xml/lttng/"))
326 class Babeltrace(Project
):
This page took 0.046563 seconds and 5 git commands to generate.