7 _logger
= logging
.getLogger('project')
11 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
13 self
.git_path
= git_path
16 """ Custom configure flags in the for of ['-x', 'arg']"""
17 self
.custom_configure_flags
= []
18 ccache
= shutil
.which("ccache")
19 if ccache
is not None:
20 self
.custom_configure_flags
.append("CC={} gcc".format(ccache
))
21 self
.custom_configure_flags
.append("CXX={} g++".format(ccache
))
22 self
.custom_configure_flags
.append("CFLAGS=-g -O0".format(ccache
))
24 """ A collection of Project dependencies """
25 self
.dependencies
= {}
26 self
._immutable
= False
30 self
.isConfigured
= False
31 self
.isInstalled
= False
34 self
.log_path
= os
.path
.join(tmpdir
, "log")
35 self
.source_path
= os
.path
.join(tmpdir
, "source")
36 self
.installation_path
= os
.path
.join(tmpdir
, "install")
38 if os
.path
.isdir(self
.basedir
):
39 # Perform cleanup since it should not happen
40 shutil
.rmtree(self
.basedir
)
42 os
.makedirs(self
.log_path
)
43 os
.makedirs(self
.source_path
)
44 os
.makedirs(self
.installation_path
)
46 self
.special_env_variables
= {}
48 # Init the repo for work
52 def add_special_env_variable(self
, key
, value
):
53 if key
in self
.special_env_variables
:
54 _logger
.warning("{} Special var {} is already defined".format(
56 raise Exception("Multiple definition of a special environment variable")
57 self
.special_env_variables
[key
] = value
59 def get_cppflags(self
):
60 cppflags
= ["-I{}/include".format(self
.installation_path
)]
61 for key
, dep
in self
.dependencies
.items():
62 cppflags
.append(dep
.get_cppflags())
64 return " ".join(cppflags
)
66 def get_ldflags(self
):
67 ldflags
= ["-L{}/lib".format(self
.installation_path
)]
68 for key
, dep
in self
.dependencies
.items():
69 ldflags
.append(dep
.get_ldflags())
70 return " ".join(ldflags
)
72 def get_ld_library_path(self
):
73 library_path
= ["{}/lib".format(self
.installation_path
)]
74 for key
, dep
in self
.dependencies
.items():
75 library_path
.append(dep
.get_ld_library_path())
76 return ":".join(library_path
)
78 def get_bin_path(self
):
79 bin_path
= ["{}/bin".format(self
.installation_path
)]
80 for key
, dep
in self
.dependencies
.items():
81 bin_path
.append(dep
.get_bin_path())
82 return ":".join(bin_path
)
85 """Modify environment to reflect dependency"""
86 env_var
= {"CPPFLAGS": (self
.get_cppflags(), " "),
87 "LDFLAGS": (self
.get_ldflags(), " "),
88 "LD_LIBRARY_PATH": (self
.get_ld_library_path(), ":"),
91 env
= os
.environ
.copy()
93 for var
, value
in self
.special_env_variables
.items():
95 # Raise for now since no special cases is known
96 _logger
.warning("{} Special var {} is already defined".format(
98 raise Exception("Multiple definition of a special environment variable")
102 for key
, dep
in self
.dependencies
.items():
103 # Extra space just in case
104 for var
, value
in dep
.special_env_variables
.items():
106 # Raise for now since no special cases is known
107 _logger
.warning("{} Special var {} is already defined".format(
109 raise Exception("Multiple definition of a special environment variable")
113 for var
, (value
, delimiter
) in env_var
.items():
117 env
[var
] = delimiter
.join(tmp
)
123 Perform the bootstrap, configuration, build and install the
124 project. Build dependencies if not already built
126 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
130 raise Exception("Object is immutable. Illegal autobuild")
132 for key
, dep
in self
.dependencies
.items():
135 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
136 raise Exception("Project steps where manually triggered. Can't autobuild")
138 _logger
.debug("{} Autobuild configure".format(self
.label
))
141 except subprocess
.CalledProcessError
as e
:
142 _logger
.error("{} Configure failed. See {} for more details.".format(self
.label
, self
.log_path
))
145 _logger
.debug("{} Autobuild build".format(self
.label
))
148 except subprocess
.CalledProcessError
as e
:
149 _logger
.error("{} Build failed. See {} for more details.".format(self
.label
, self
.log_path
))
152 _logger
.debug("{} Autobuild install".format(self
.label
))
155 except subprocess
.CalledProcessError
as e
:
156 _logger
.error("{} Install failed. See {} for more details.".format(self
.label
, self
.log_path
))
161 raise Exception("Object is immutable. Illegal checkout")
163 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
164 commit
= repo
.commit(self
.sha1
)
165 repo
.head
.reference
= commit
166 assert repo
.head
.is_detached
167 repo
.head
.reset(index
=True, working_tree
=True)
171 Bootstap the project. Raise subprocess.CalledProcessError on
175 raise Exception("Object is immutable. Illegal bootstrap")
177 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
178 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
180 os
.chdir(self
.source_path
)
181 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
182 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
188 Configure the project.
189 Raises subprocess.CalledProcessError on configure error
192 raise Exception("Object is immutable. Illegal configure")
194 # Check that all our dependencies were actually installed
195 for key
, dep
in self
.dependencies
.items():
196 if not dep
.isInstalled
:
197 # TODO: Custom exception here Dependency Error
198 raise Exception("Dependency project flagged as not installed")
200 out
= os
.path
.join(self
.log_path
, "configure.out")
201 err
= os
.path
.join(self
.log_path
, "configure.err")
203 os
.chdir(self
.source_path
)
204 args
= ['./configure']
205 prefix
= '--prefix={}'.format(self
.installation_path
)
207 args
.extend(self
.custom_configure_flags
)
209 # TODO: log output and add INFO log point
210 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
211 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
214 self
.isConfigured
= True
219 Build the project. Raise subprocess.CalledProcessError on build
223 raise Exception("Object is immutable. Illegal build")
225 out
= os
.path
.join(self
.log_path
, "build.out")
226 err
= os
.path
.join(self
.log_path
, "build.err")
228 os
.chdir(self
.source_path
)
232 # Number of usable cpu
233 # https://docs.python.org/3/library/os.html#os.cpu_count
234 num_cpu
= str(len(os
.sched_getaffinity(0)))
239 # TODO: log output and add INFO log point with args
240 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
241 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
249 Install the project. Raise subprocess.CalledProcessError on
253 raise Exception("Object is immutable. Illegal install")
255 out
= os
.path
.join(self
.log_path
, "install.out")
256 err
= os
.path
.join(self
.log_path
, "install.err")
258 os
.chdir(self
.source_path
)
259 args
= ['make', 'install']
261 # TODO: log output and add INFO log point
262 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
263 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
266 self
.isInstalled
= True
270 if os
.path
.exists(self
.source_path
):
271 shutil
.rmtree(self
.source_path
)
272 if os
.path
.exists(self
.installation_path
):
273 shutil
.rmtree(self
.installation_path
)
276 class Lttng_modules(Project
):
277 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
278 super(Lttng_modules
, self
).__init
__(label
=label
, git_path
=git_path
,
279 sha1
=sha1
, tmpdir
=tmpdir
)
280 self
.add_special_env_variable("MODPROBE_OPTIONS","-b {}".format(self
.installation_path
))
290 raise Exception("Object is immutable. Illegal install")
291 os
.chdir(self
.source_path
)
292 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
294 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
295 stderr
=subprocess
.PIPE
)
298 # Perform a local depmod
299 args
= ['depmod', '-b', self
.installation_path
]
300 p
= subprocess
.run(args
, env
=self
.get_env())
302 self
.isInstalled
= True
305 class Lttng_ust(Project
):
306 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
307 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
308 sha1
=sha1
, tmpdir
=tmpdir
)
309 self
.custom_configure_flags
.extend(['--disable-man-pages'])
312 class Lttng_tools(Project
):
313 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
314 super(Lttng_tools
, self
).__init
__(label
=label
, git_path
=git_path
,
315 sha1
=sha1
, tmpdir
=tmpdir
)
316 self
.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH",
317 os
.path
.join(self
.installation_path
, "share/xml/lttng/"))
320 class Babeltrace(Project
):
This page took 0.046556 seconds and 5 git commands to generate.