10 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
12 self
.git_path
= git_path
15 """ Custom configure flags in the for of ['-x', 'arg']"""
16 self
.custom_configure_flags
= []
17 ccache
= shutil
.which("ccache")
18 if ccache
is not None:
19 self
.custom_configure_flags
.append("CC={} gcc".format(ccache
))
20 self
.custom_configure_flags
.append("CXX={} g++".format(ccache
))
22 """ A collection of Project dependencies """
23 self
.dependencies
= []
26 self
.isCheckedOut
= False
27 self
.isBootStrapped
= False
29 self
.isConfigured
= False
30 self
.isInstalled
= False
32 self
.source_path
= tmpdir
+ "/source"
33 self
.installation_path
= tmpdir
+ "/install"
34 os
.makedirs(self
.source_path
)
35 os
.makedirs(self
.installation_path
)
36 self
.logger
= logging
.getLogger('project.{}'.format(self
.label
))
38 self
.special_env_variables
= {}
40 # Init the repo for work
44 def get_cppflags(self
):
45 return " -I{}/include".format(self
.installation_path
)
47 def get_ldflags(self
):
48 return " -L{}/lib".format(self
.installation_path
)
50 def get_ld_library_path(self
):
51 return "{}/lib".format(self
.installation_path
)
54 """Modify environment to reflect dependency"""
59 env
= os
.environ
.copy()
61 for var
, value
in self
.special_env_variables
.items():
63 # TODO: WARNING log point
64 # Raise for now since no special cases is known
65 self
.logger
.warning("Special var % is already defined", var
)
66 raise Exception("Multiple definition of a special environment variable")
70 for dep
in self
.dependencies
:
71 # Extra space just in case
72 cpp_flags
+= " {}".format(dep
.get_cppflags())
73 ld_flags
+= " {}".format(dep
.get_ldflags())
74 ld_library_path
+= "{}:".format(dep
.get_ld_library_path())
75 for var
, value
in dep
.special_env_variables
.items():
77 # TODO: WARNING log point
78 # Raise for now since no special cases is known
79 self
.logger
.warning("Special var % is already defined", var
)
80 raise Exception("Multiple definition of a special environment variable")
84 # TODO: INFO log point for each variable with project information
87 cpp_flags
= env
['CPPFLAGS'] + cpp_flags
88 env
['CPPFLAGS'] = cpp_flags
91 ld_flags
= env
['LDFLAGS'] + ld_flags
92 env
['LDFLAGS'] = ld_flags
94 if 'LD_LIBRARY_PATH' in env
:
95 ld_library_path
= env
['LD_LIBRARY_PATH'] + ":" + ld_library_path
96 env
['LD_LIBRARY_PATH'] = ld_library_path
101 Perform the bootstrap, configuration, build and install the
102 project. Build dependencies if not already built
104 for dep
in self
.dependencies
:
107 if self
.isCheckedOut ^ self
.isBootStrapped ^ self
.isBootStrapped ^ self
.isBuilt ^ self
.isConfigured ^ self
.isInstalled
:
108 raise Exception("Project steps where manually triggered. Can't autobuild")
115 repo
= git
.Repo
.clone_from(self
.git_path
, self
.source_path
)
116 commit
= repo
.commit(self
.sha1
)
117 repo
.head
.reference
= commit
118 assert repo
.head
.is_detached
119 repo
.head
.reset(index
=True, working_tree
=True)
123 Bootstap the project. Raise subprocess.CalledProcessError on
126 os
.chdir(self
.source_path
)
127 p
= subprocess
.run(['./bootstrap'], stdout
=subprocess
.PIPE
,
128 stderr
=subprocess
.PIPE
)
134 Configure the project.
135 Raises subprocess.CalledProcessError on configure error
137 # Check that all our dependencies were actually installed
138 for dep
in self
.dependencies
:
139 if not dep
.isInstalled
:
140 # TODO: Custom exception here Dependency Error
141 raise Exception("Dependency project flagged as not installed")
143 os
.chdir(self
.source_path
)
144 args
= ['./configure']
145 prefix
= '--prefix={}'.format(self
.installation_path
)
147 args
.extend(self
.custom_configure_flags
)
149 # TODO: log output and add INFO log point
150 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
151 stderr
=subprocess
.PIPE
)
153 self
.isConfigured
= True
158 Build the project. Raise subprocess.CalledProcessError on build
161 os
.chdir(self
.source_path
)
164 env
['CFLAGS'] = '-g -O0'
166 # Number of usable cpu
167 # https://docs.python.org/3/library/os.html#os.cpu_count
168 num_cpu
= str(len(os
.sched_getaffinity(0)))
172 # TODO: log output and add INFO log point with args
173 p
= subprocess
.run(args
, env
=env
, stdout
=subprocess
.PIPE
,
174 stderr
=subprocess
.PIPE
)
181 Install the project. Raise subprocess.CalledProcessError on
184 os
.chdir(self
.source_path
)
185 args
= ['make', 'install']
187 # TODO: log output and add INFO log point
188 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
189 stderr
=subprocess
.PIPE
)
191 self
.isInstalled
= True
195 if os
.path
.exists(self
.source_path
):
196 shutil
.rmtree(self
.source_path
)
197 if os
.path
.exists(self
.installation_path
):
198 shutil
.rmtree(self
.installation_path
)
201 class Lttng_modules(Project
):
209 os
.chdir(self
.source_path
)
210 args
= ['make', 'INSTALL_MOD_PATH={}'.format(self
.installation_path
),
212 p
= subprocess
.run(args
, env
=self
.get_env(), stdout
=subprocess
.PIPE
,
213 stderr
=subprocess
.PIPE
)
216 # Perform a local depmod
217 args
= ['depmod', '-b', self
.installation_path
]
218 p
= subprocess
.run(args
, env
=self
.get_env())
220 self
.isInstalled
= True
223 class Lttng_ust(Project
):
224 def __init__(self
, label
, git_path
, sha1
, tmpdir
):
225 super(Lttng_ust
, self
).__init
__(label
=label
, git_path
=git_path
,
226 sha1
=sha1
, tmpdir
=tmpdir
)
227 self
.custom_configure_flags
.extend(['--disable-man-pages'])
230 class Lttng_tools(Project
):
234 class Babeltrace(Project
):
This page took 0.035347 seconds and 5 git commands to generate.