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
))
23 """ A collection of Project dependencies """
24 self
.dependencies
= {}
25 self
._immutable
= False
29 self
.isConfigured
= False
30 self
.isInstalled
= False
33 self
.log_path
= os
.path
.join(tmpdir
, "log")
34 self
.source_path
= os
.path
.join(tmpdir
, "source")
35 self
.installation_path
= os
.path
.join(tmpdir
, "install")
37 os
.makedirs(self
.log_path
)
38 os
.makedirs(self
.source_path
)
39 os
.makedirs(self
.installation_path
)
41 self
.special_env_variables
= {}
43 # Init the repo for work
47 def add_special_env_variable(self
, key
, value
):
48 if key
in self
.special_env_variables
:
49 _logger
.warning("{} Special var {} is already defined".format(
51 raise Exception("Multiple definition of a special environment variable")
52 self
.special_env_variables
[key
] = value
54 def get_cppflags(self
):
55 cppflags
= ["-I{}/include".format(self
.installation_path
)]
56 for key
, dep
in self
.dependencies
.items():
57 cppflags
.append(dep
.get_cppflags())
59 return " ".join(cppflags
)
61 def get_ldflags(self
):
62 ldflags
= ["-L{}/lib".format(self
.installation_path
)]
63 for key
, dep
in self
.dependencies
.items():
64 ldflags
.append(dep
.get_ldflags())
65 return " ".join(ldflags
)
67 def get_ld_library_path(self
):
68 library_path
= ["{}/lib".format(self
.installation_path
)]
69 for key
, dep
in self
.dependencies
.items():
70 library_path
.append(dep
.get_ld_library_path())
71 return ":".join(library_path
)
73 def get_bin_path(self
):
74 bin_path
= ["{}/bin".format(self
.installation_path
)]
75 for key
, dep
in self
.dependencies
.items():
76 bin_path
.append(dep
.get_bin_path())
77 return ":".join(bin_path
)
80 """Modify environment to reflect dependency"""
81 env_var
= {"CPPFLAGS": (self
.get_cppflags(), " "),
82 "LDFLAGS": (self
.get_ldflags(), " "),
83 "LD_LIBRARY_PATH": (self
.get_ld_library_path(), ":"),
86 env
= os
.environ
.copy()
88 for var
, value
in self
.special_env_variables
.items():
90 # Raise for now since no special cases is known
91 _logger
.warning("{} Special var {} is already defined".format(
93 raise Exception("Multiple definition of a special environment variable")
97 for key
, dep
in self
.dependencies
.items():
98 # Extra space just in case
99 for var
, value
in dep
.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 var
, (value
, delimiter
) in env_var
.items():
112 env
[var
] = delimiter
.join(tmp
)
118 Perform the bootstrap, configuration, build and install the
119 project. Build dependencies if not already built
121 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
125 raise Exception("Object is immutable. Illegal autobuild")
127 for key
, dep
in self
.dependencies
.items():
130 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
131 raise Exception("Project steps where manually triggered. Can't autobuild")
133 _logger
.debug("% Autobuild configure", self
.label
)
135 _logger
.debug("% Autobuild build", self
.label
)
137 _logger
.debug("% Autobuild install", self
.label
)
142 raise Exception("Object is immutable. Illegal checkout")
144 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
145 commit
= repo
.commit(self
.sha1
)
146 repo
.head
.reference
= commit
147 assert repo
.head
.is_detached
148 repo
.head
.reset(index
=True, working_tree
=True)
152 Bootstap the project. Raise subprocess.CalledProcessError on
156 raise Exception("Object is immutable. Illegal bootstrap")
158 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
159 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
161 os
.chdir(self
.source_path
)
162 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
163 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
169 Configure the project.
170 Raises subprocess.CalledProcessError on configure error
173 raise Exception("Object is immutable. Illegal configure")
175 # Check that all our dependencies were actually installed
176 for key
, dep
in self
.dependencies
.items():
177 if not dep
.isInstalled
:
178 # TODO: Custom exception here Dependency Error
179 raise Exception("Dependency project flagged as not installed")
181 out
= os
.path
.join(self
.log_path
, "configure.out")
182 err
= os
.path
.join(self
.log_path
, "configure.err")
184 os
.chdir(self
.source_path
)
185 args
= ['./configure']
186 prefix
= '--prefix={}'.format(self
.installation_path
)
188 args
.extend(self
.custom_configure_flags
)
190 # TODO: log output and add INFO log point
191 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
192 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
195 self
.isConfigured
= True
200 Build the project. Raise subprocess.CalledProcessError on build
204 raise Exception("Object is immutable. Illegal build")
206 out
= os
.path
.join(self
.log_path
, "build.out")
207 err
= os
.path
.join(self
.log_path
, "build.err")
209 os
.chdir(self
.source_path
)
212 env
['CFLAGS'] = '-g -O0'
214 # Number of usable cpu
215 # https://docs.python.org/3/library/os.html#os.cpu_count
216 num_cpu
= str(len(os
.sched_getaffinity(0)))
220 # TODO: log output and add INFO log point with args
221 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
222 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
230 Install the project. Raise subprocess.CalledProcessError on
234 raise Exception("Object is immutable. Illegal install")
236 out
= os
.path
.join(self
.log_path
, "build.out")
237 err
= os
.path
.join(self
.log_path
, "build.err")
239 os
.chdir(self
.source_path
)
240 args
= ['make', 'install']
242 # TODO: log output and add INFO log point
243 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
244 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
247 self
.isInstalled
= True
251 if os
.path
.exists(self
.source_path
):
252 shutil
.rmtree(self
.source_path
)
253 if os
.path
.exists(self
.installation_path
):
254 shutil
.rmtree(self
.installation_path
)
257 class Lttng_modules(Project
):
266 raise Exception("Object is immutable. Illegal install")
267 os
.chdir(self
.source_path
)
268 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
270 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
271 stderr
=subprocess
.PIPE
)
274 # Perform a local depmod
275 args
= ['depmod', '-b', self
.installation_path
]
276 p
= subprocess
.run(args
, env
=self
.get_env())
278 self
.isInstalled
= True
281 class Lttng_ust(Project
):
282 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
283 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
284 sha1
=sha1
, tmpdir
=tmpdir
)
285 self
.custom_configure_flags
.extend(['--disable-man-pages'])
288 class Lttng_tools(Project
):
289 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
290 super(Lttng_tools
, self
).__init
__(label
=label
, git_path
=git_path
,
291 sha1
=sha1
, tmpdir
=tmpdir
)
292 self
.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH",
293 os
.path
.join(self
.installation_path
, "share/xml/lttng/"))
296 class Babeltrace(Project
):
This page took 0.036173 seconds and 5 git commands to generate.