4 obs_prj_name = 'SLP:Main'
5 osce_root = '/var/tmp/osce-root'
6 osce_pkgs = osce_root + '/pkgs'
7 build_root = osce_root + '/build'
8 output_dir = osce_root + '/output'
9 relative_source_dir = '/.source'
10 source_dir = build_root + relative_source_dir
11 chroot_dir = osce_root + '/chroot'
13 chroot_mounts = ['/proc', '/proc/sys/fs/binfmt_misc', '/sys', '/dev', '/dev/pts']
15 # this is a hack to make osc work as expected with utf-8 characters,
16 # no matter how site.py is set...
18 loc = locale.getdefaultlocale()[1]
20 loc = sys.getdefaultencoding()
21 sys.setdefaultencoding(loc)
22 del sys.setdefaultencoding
24 from osc import core, oscerr
25 # Injection code for osc.core to fix the empty XML bug
26 def solid_get_files_meta(self, revision='latest', skip_service=True):
27 from time import sleep
29 while retry_count > 0:
30 fm = core.show_files_meta(self.apiurl, self.prjname, self.name,
31 revision=revision, meta=self.meta)
33 root = core.ET.fromstring(fm)
36 print 'corrupted or empty obs server response ,retrying ...'
40 # all the re-try failed, abort
41 raise oscerr.OscIOError(None, 'cannet fetch files meta xml from server')
42 # look for "too large" files according to size limit and mark them
43 for e in root.findall('entry'):
45 if size and self.size_limit and int(size) > self.size_limit \
46 or skip_service and (e.get('name').startswith('_service:') or e.get('name').startswith('_service_')):
47 e.set('skipped', 'true')
48 return core.ET.tostring(root)
49 core.Package.get_files_meta = solid_get_files_meta
53 curr_dir = os.getcwd()
62 BuildRequires: zypper wget strace which git gdb vim
65 dummy spec for creating chroot env.
71 build_template = '''%build
73 if [ -d ''' + relative_source_dir + ''' ]; then
76 ln -sf ''' + relative_source_dir + ''' $build_source
82 %global _enable_debug_package 0
83 %global debug_package %{nil}
86 build_template3 = '''%ifarch %{arm}
87 %define EFL_TARGET arm
88 export RPM_OPT_FLAGS="-Wall -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=vfpv3 -mfloat-abi=softfp -D__SOFTFP__"
90 %define EFL_TARGET i386
91 export RPM_OPT_FLAGS="-Wall -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables"
93 CFLAGS="$RPM_OPT_FLAGS"
94 CXXFLAGS="$RPM_OPT_FLAGS"
99 def osce_specfile_info(specfile):
103 if not os.path.exists(specfile):
104 return specname, pkg_name, pkg_version
105 fp = open(specfile, 'r')
106 speclines = fp.readlines()
109 for line in speclines:
110 if line.lower().strip().find('name') == 0 and line.find(':') > -1:
111 pkg_name = line.split(':')[1].strip()
112 if line.lower().strip().find('version') == 0 and line.find(':') > -1:
113 pkg_version = line.split(':')[1].strip()
115 specname = specfile.split('/')[-1]
116 specname = specname[:specname.rfind('.spec')]
117 if specname != pkg_name:
118 print('spec file name and package name are not the same')
121 return specname, pkg_name, pkg_version
123 def osce_find_specfile(pkg_dir='./'):
127 if arg.find('.spec') > -1:
128 if os.path.exists(arg):
129 specfile = '(%s/%s)' % (pkg_dir, arg)
132 for dirname, dirnames, filenames in os.walk(pkg_dir):
133 for filename in filenames:
134 if filename.find('.spec') > -1 and filename != 'tmp.spec':
137 if specfile is not None:
140 specfile = os.path.abspath('%s/%s' % (pkg_dir, specfile))
142 if os.path.exists(specfile):
143 print('specfile : %s' % specfile)
146 print('cannot find specfile : %s' % specfile)
149 def osce_get_random_pkgdir():
150 if os.path.exists('%s/%s' % (osce_pkgs, obs_prj_name)):
151 for dirname, dirnames, filenames in os.walk('%s/%s' % (osce_pkgs, obs_prj_name)):
152 for pkgdir in dirnames:
154 return '%s/%s/%s' % (osce_pkgs, obs_prj_name, pkgdir)
158 from osc import commandline, babysitter
159 cmdline = commandline.Osc()
161 result = babysitter.run(cmdline)
164 def osce_sys_run(cmdln_or_args):
167 os.system(cmdln_or_args)
169 def osce_mount_srcdir(sourcedir=os.getcwd()):
170 if not os.path.exists(source_dir):
171 osce_sys_run('sudo mkdir -p ' + source_dir)
172 if os.path.exists(source_dir) and os.path.exists(sourcedir):
173 cmdline = 'sudo mount --bind %s %s' % (sourcedir, source_dir)
174 osce_sys_run(cmdline)
176 def osce_umount(mount_dir):
177 fp = open('/proc/mounts', 'r')
178 mounts = fp.readlines()
181 for mount in reversed(mounts):
182 mountpoint = mount.split(' ')[1]
183 if mountpoint.find(mount_dir) > -1:
184 osce_sys_run('sudo umount %s' % mountpoint)
187 for dirname, dirnames, filenames in os.walk('.'):
188 for filename in filenames:
189 if filename == 'tmp.spec':
190 osce_sys_run('rm %s' % filename)
192 osce_umount(source_dir)
194 fp = open('/proc/mounts', 'r')
198 if os.path.exists(source_dir) and mounts.find(source_dir) < 0:
199 osce_sys_run('sudo rmdir %s ' % source_dir)
201 def osce_chrootex_mount():
202 for mnt in chroot_mounts:
203 cmdline = 'sudo mount --bind %s %s%s' % (mnt, chroot_dir, mnt)
204 osce_sys_run(cmdline)
206 def osce_chrootex_umount():
207 osce_umount(chroot_dir)
209 def osce_mkchrootex():
210 dummyproj_dir = osce_pkgs + '/dummy'
211 dummypkg_dir = dummyproj_dir + '/dummy'
213 if os.path.exists(dummyproj_dir):
214 osce_sys_run('sudo rm -rf %s' % dummyproj_dir)
216 osce_sys_run('sudo mkdir -p %s' % dummyproj_dir)
217 os.chdir(dummyproj_dir)
218 osce_sys_run('sudo chown `whoami` %s' % dummyproj_dir)
219 osce_sys_run('osce init %s' % obs_prj_name)
220 osce_sys_run('osce mkpac dummy')
222 if not os.path.exists(dummypkg_dir + '/dummy.spec'):
223 fd = open(dummypkg_dir + '/dummy.spec', 'w')
227 if not os.path.exists(chroot_dir):
228 osce_sys_run('sudo mkdir -p ' + chroot_dir)
230 os.chdir(dummypkg_dir)
231 osce_sys_run('osc build armv7el dummy.spec --clean --local-package --no-verify --root=%s/ ' % chroot_dir)
232 osce_chrootex_mount()
233 osce_sys_run('sudo chroot %s rpm -e rpm-x86-arm rpm-libs-x86-arm rpm-build-x86-arm' % chroot_dir)
234 if len(chroot_dir) > 6:
235 osce_sys_run('sudo rm %s/var/lib/rpm/__db*' % chroot_dir)
236 osce_sys_run('sudo chroot %s zypper addrepo http://165.213.148.149:82/SLP:/Base/standard/SLP:Base.repo' % chroot_dir)
237 osce_sys_run('sudo chroot %s zypper addrepo http://165.213.148.149:82/SLP:/System/standard/SLP:System.repo' % chroot_dir)
238 osce_sys_run('sudo chroot %s zypper addrepo http://165.213.148.149:82/SLP:/Main/standard/SLP:Main.repo' % chroot_dir)
239 osce_sys_run('sudo chroot %s zypper refresh' % chroot_dir)
240 osce_sys_run('sudo chroot %s rpmdb --rebuilddb' % chroot_dir)
241 osce_sys_run('sudo chroot ' + chroot_dir )
242 osce_chrootex_umount()
245 if os.path.exists(chroot_dir):
246 osce_chrootex_mount()
247 osce_sys_run('sudo chroot ' + chroot_dir )
248 osce_chrootex_umount()
250 def osce_check__buildcmd():
251 from osc import build
252 buildfile = build.__file__
254 source = ''' repositories.append(repository)
256 packageQueries = packagequery.PackageQueries(wanted_arch)
258 for repository in repositories:'''
260 fp = open(buildfile, 'r')
261 buildcontent = fp.read()
264 if buildcontent.find(source) > -1:
265 print('------please execute below command to patch build.py---THIS WILL BE FIXED---')
266 print('''sudo sed --in-place "s/ packageQueries = packagequery.PackageQueries(wanted_arch)/ if wanted_arch == 'armv7el':\\n wanted_arch = 'armv7l'\\n\\n if wanted_arch == 'armv8el':\\n wanted_arch = 'armv7hl'\\n\\n packageQueries = packagequery.PackageQueries(wanted_arch)/g" %s''' % buildfile)
267 print('----------------------------------------------------------------------------')
270 del sys.modules["osc.build"]
273 sys.argv = sys.argv + ['--ccache', '--no-verify', '--release=999', '--build-uid=0:0', '--no-checks', '--disable-debuginfo', '--offline']
274 sys.argv = sys.argv + ['--keep-pkgs=%s' % output_dir, '--oldpackages=%s' % output_dir]
275 sys.argv = sys.argv + ['--prefer-pkgs=%s' % output_dir, '--root=%s' % build_root ]
277 if '--timerebase' in sys.argv:
278 sys.argv.remove('--timerebase')
279 os.system('sudo touch ' + build_root + '/timebase')
280 os.system('sudo find ' + build_root + '/usr -newer ' + build_root + '/timebase -exec touch 06302051 {} \\;')
281 os.system('sudo find ' + build_root + '/lib -newer ' + build_root + '/timebase -exec touch 06302051 {} \\;')
284 if '--debug' in sys.argv:
285 sys.argv.remove('--debug')
286 sys.argv.remove('--disable-debuginfo')
289 if '--online' in sys.argv:
290 sys.argv.remove('--online')
291 sys.argv.remove('--offline')
293 if os.path.exists(source_dir):
294 specfile = osce_find_specfile()
297 fp = open(specfile, 'r')
298 speccontent = fp.read()
302 speccontent = speccontent.replace('%build', build_template)
304 speccontent = build_template2 + speccontent
305 speccontent = speccontent.replace('%build', build_template + build_template3)
307 fp = open('tmp.spec', 'w')
308 fp.write(speccontent)
311 sys.argv = sys.argv + ['tmp.spec']
313 osce_check__buildcmd()
316 def osce_prepare_git_done():
317 cmdline = 'osce clear'
318 osce_sys_run(cmdline)
321 # copy output file to under the current path
322 os.system('find %s/home/abuild/rpmbuild/RPMS/ -name "*.rpm" -type f -exec cp -f {} %s' % (build_root, curr_dir + "/.."))
324 def osce_prepare_git():
325 print('osce_prepare_git')
328 if not os.path.exists(osce_pkgs) or len(osce_pkgs) < 6:
329 print('choose another directory')
332 if not os.path.exists(curr_dir + '/packaging'):
333 print('cannot find packaging directory')
336 # check packaging directory
337 # extract package name from the spec file
338 # if multiple specfile exist, then request spec file name to be built as an option
340 specfile = osce_find_specfile('%s/packaging' % curr_dir)
342 osce_prepare_git_done()
345 specname, pkg_name, pkg_version = osce_specfile_info(specfile)
347 if pkg_name is None or pkg_version is None or specname is None:
348 osce_prepare_git_done()
350 # OBSPKGDIR = osce_pkgs
353 # check whether the PKG dir exists or not,
354 # how can get the proj name? take another option? obs_prj_name
355 # osce checkout $PROJ $PKG
356 obs_pkg_dir = '%s/%s/%s' % (osce_pkgs, obs_prj_name, pkg_name)
357 if not os.path.exists(obs_pkg_dir):
358 cmdline = 'osce checkout %s %s' % (obs_prj_name, pkg_name)
359 osce_sys_run(cmdline)
361 os.chdir(obs_pkg_dir)
362 # remove source files, copy packaging/* , empty tarball (name-version.tar.gz, name-version/)
364 if os.path.exists(obs_pkg_dir) and len(os.getcwd()) > 6:
366 osce_sys_run(cmdline)
368 osce_prepare_git_done()
371 cmdline = 'cp %s/packaging/* %s/' %(curr_dir, obs_pkg_dir)
372 osce_sys_run(cmdline)
373 if not os.path.exists('%s-%s' % (pkg_name, pkg_version)):
374 os.mkdir('%s-%s' % (pkg_name, pkg_version))
376 osce_prepare_git_done()
379 shutil.make_archive('%s-%s' % (pkg_name, pkg_version), 'gztar', '.', '%s-%s' % (pkg_name, pkg_version))
381 if '--clean' in sys.argv or not os.path.exists(build_root):
382 specfile = '%s.spec' % specname
383 if os.path.exists(specfile):
384 fp = open(specfile, 'r')
387 fp = open(specfile, 'w')
388 fp.write(specs[:specs.find('%prep') + 6])
391 osce_sys_run(' '.join(sys.argv))
393 if '--clean' in sys.argv:
394 sys.argv.remove('--clean')
395 # osce srcmnt $gitdirectory
396 cmdline = 'osce srcmnt %s' % curr_dir
397 osce_sys_run(cmdline)
399 cmdline = ' '.join(sys.argv)
400 osce_sys_run(cmdline)
402 osce_prepare_git_done()
405 if os.path.exists(build_root):
406 osce_sys_run('sudo chroot ' + build_root + ' su abuild')
409 options = ["--exclude='.git*'", "--exclude='CMakeFiles'", "--exclude='CMakeCache.txt'"]
411 specfile = osce_find_specfile('%s/packaging' % curr_dir)
416 specname, pkg_name, pkg_version = osce_specfile_info(specfile)
418 if pkg_name is None or pkg_version is None or specname is None:
421 cmdline = '''tar --transform 's,^,/%s-%s/,' %s -zcvf ../%s-%s.tar.gz *''' % (pkg_name, pkg_version, ' '.join(options), pkg_name, pkg_version)
422 osce_sys_run(cmdline)
426 if not os.path.exists(osce_pkgs):
427 os.makedirs(osce_pkgs)
429 if 'clear' in sys.argv:
433 if 'srcmnt' in sys.argv:
435 if os.path.exists(sys.argv[2]):
436 osce_mount_srcdir(sys.argv[2])
439 if 'mktar' in sys.argv:
443 if 'chroot' in sys.argv:
447 if 'mkchrootex' in sys.argv:
451 if 'chrootex' in sys.argv:
455 if 'checkout' in sys.argv:
456 # sys.argv = sys.argv + ['--current-dir']
459 if '--clean' in sys.argv:
462 if 'build' in sys.argv:
463 for dirname, dirnames, filenames in os.walk('.'):
464 for dirtype in dirnames:
465 if dirtype == '.git':
468 elif dirtype == '.osc':
471 print('cannot find .git or .osc directory')
476 if __name__ == "__main__":