4e1a5b6ad9fefcc75c93c34743fbc46065ba8af4
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 get_cppflags(self
):
48 return " -I{}/include".format(self
.installation_path
)
50 def get_ldflags(self
):
51 return " -L{}/lib".format(self
.installation_path
)
53 def get_ld_library_path(self
):
54 return "{}/lib".format(self
.installation_path
)
57 """Modify environment to reflect dependency"""
62 env
= os
.environ
.copy()
64 for var
, value
in self
.special_env_variables
.items():
66 # Raise for now since no special cases is known
67 _logger
.warning("% Special var % is already defined",
69 raise Exception("Multiple definition of a special environment variable")
73 for key
, dep
in self
.dependencies
.items():
74 # Extra space just in case
75 cpp_flags
+= " {}".format(dep
.get_cppflags())
76 ld_flags
+= " {}".format(dep
.get_ldflags())
77 ld_library_path
+= "{}:".format(dep
.get_ld_library_path())
78 for var
, value
in dep
.special_env_variables
.items():
80 # Raise for now since no special cases is known
81 _logger
.warning("% Special var % is already defined",
83 raise Exception("Multiple definition of a special environment variable")
89 cpp_flags
= env
['CPPFLAGS'] + cpp_flags
90 env
['CPPFLAGS'] = cpp_flags
91 _logger
.debug("% CPPFLAGS= %s", self
.label
, cpp_flags
)
94 ld_flags
= env
['LDFLAGS'] + ld_flags
95 env
['LDFLAGS'] = ld_flags
96 _logger
.debug("% LDFLAGS= %s", self
.label
, ld_flags
)
98 if 'LD_LIBRARY_PATH' in env
:
99 ld_library_path
= env
['LD_LIBRARY_PATH'] + ":" + ld_library_path
100 env
['LD_LIBRARY_PATH'] = ld_library_path
101 _logger
.debug("% LD_LIBRARY_PATH= %s", self
.label
, ld_library_path
)
106 Perform the bootstrap, configuration, build and install the
107 project. Build dependencies if not already built
109 if (self
.isConfigured
and self
.isBuilt
and self
.isInstalled
):
113 raise Exception("Object is immutable. Illegal autobuild")
115 for key
, dep
in self
.dependencies
.items():
118 if self
.isConfigured ^ self
.isBuilt ^ self
.isInstalled
:
119 raise Exception("Project steps where manually triggered. Can't autobuild")
121 _logger
.debug("% Autobuild configure", self
.label
)
123 _logger
.debug("% Autobuild build", self
.label
)
125 _logger
.debug("% Autobuild install", self
.label
)
130 raise Exception("Object is immutable. Illegal checkout")
132 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
133 commit
= repo
.commit(self
.sha1
)
134 repo
.head
.reference
= commit
135 assert repo
.head
.is_detached
136 repo
.head
.reset(index
=True, working_tree
=True)
140 Bootstap the project. Raise subprocess.CalledProcessError on
144 raise Exception("Object is immutable. Illegal bootstrap")
146 out
= os
.path
.join(self
.log_path
, "bootstrap.out")
147 err
= os
.path
.join(self
.log_path
, "bootstrap.err")
149 os
.chdir(self
.source_path
)
150 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
151 p
= subprocess
.run(['./bootstrap'], stdout
=stdout
, stderr
=stderr
)
157 Configure the project.
158 Raises subprocess.CalledProcessError on configure error
161 raise Exception("Object is immutable. Illegal configure")
163 # Check that all our dependencies were actually installed
164 for key
, dep
in self
.dependencies
.items():
165 if not dep
.isInstalled
:
166 # TODO: Custom exception here Dependency Error
167 raise Exception("Dependency project flagged as not installed")
169 out
= os
.path
.join(self
.log_path
, "configure.out")
170 err
= os
.path
.join(self
.log_path
, "configure.err")
172 os
.chdir(self
.source_path
)
173 args
= ['./configure']
174 prefix
= '--prefix={}'.format(self
.installation_path
)
176 args
.extend(self
.custom_configure_flags
)
178 # TODO: log output and add INFO log point
179 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
180 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
183 self
.isConfigured
= True
188 Build the project. Raise subprocess.CalledProcessError on build
192 raise Exception("Object is immutable. Illegal build")
194 out
= os
.path
.join(self
.log_path
, "build.out")
195 err
= os
.path
.join(self
.log_path
, "build.err")
197 os
.chdir(self
.source_path
)
200 env
['CFLAGS'] = '-g -O0'
202 # Number of usable cpu
203 # https://docs.python.org/3/library/os.html#os.cpu_count
204 num_cpu
= str(len(os
.sched_getaffinity(0)))
208 # TODO: log output and add INFO log point with args
209 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
210 p
= subprocess
.run(args
, env
=env
, stdout
=stdout
,
218 Install the project. Raise subprocess.CalledProcessError on
222 raise Exception("Object is immutable. Illegal install")
224 out
= os
.path
.join(self
.log_path
, "build.out")
225 err
= os
.path
.join(self
.log_path
, "build.err")
227 os
.chdir(self
.source_path
)
228 args
= ['make', 'install']
230 # TODO: log output and add INFO log point
231 with
open(out
, 'w') as stdout
, open(err
, 'w') as stderr
:
232 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=stdout
,
235 self
.isInstalled
= True
239 if os
.path
.exists(self
.source_path
):
240 shutil
.rmtree(self
.source_path
)
241 if os
.path
.exists(self
.installation_path
):
242 shutil
.rmtree(self
.installation_path
)
245 class Lttng_modules(Project
):
254 raise Exception("Object is immutable. Illegal install")
255 os
.chdir(self
.source_path
)
256 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
258 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
259 stderr
=subprocess
.PIPE
)
262 # Perform a local depmod
263 args
= ['depmod', '-b', self
.installation_path
]
264 p
= subprocess
.run(args
, env
=self
.get_env())
266 self
.isInstalled
= True
269 class Lttng_ust(Project
):
270 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
271 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
272 sha1
=sha1
, tmpdir
=tmpdir
)
273 self
.custom_configure_flags
.extend(['--disable-man-pages'])
276 class Lttng_tools(Project
):
280 class Babeltrace(Project
):
This page took 0.036771 seconds and 4 git commands to generate.