sourceipk: fix race condition with compileconfigs/multi-kernel
[openembedded.git] / classes / sourcepkg.bbclass
blobce57ef0e0b593532bb26e4fc8fb2920e699dd444
1 DEPLOY_DIR_SRC ?= "${DEPLOY_DIR}/sources"
2 EXCLUDE_FROM ?= ".pc patches autom4te.cache"
4 # used as part of a path. make sure it's set
5 DISTRO ?= "openembedded"
7 def get_src_tree(d):
9         workdir = bb.data.getVar('WORKDIR', d, 1)
10         if not workdir:
11                 bb.error("WORKDIR not defined, unable to find source tree.")
12                 return
14         s = bb.data.getVar('S', d, 0)
15         if not s:
16                 bb.error("S not defined, unable to find source tree.")
17                 return
19         s_tree_raw = s.split('/')[1]
20         s_tree = bb.data.expand(s_tree_raw, d)
22         src_tree_path = os.path.join(workdir, s_tree)
23         try:
24                 os.listdir(src_tree_path)
25         except OSError:
26                 bb.fatal("Expected to find source tree in '%s' which doesn't exist." % src_tree_path)
27         bb.debug("Assuming source tree is '%s'" % src_tree_path)
29         return s_tree
31 sourcepkg_do_create_orig_tgz(){
33         mkdir -p ${DEPLOY_DIR_SRC}/${PN}/${PACKAGE_ARCH}
34         cd ${WORKDIR}
35         for i in ${EXCLUDE_FROM}; do
36                 echo $i >> temp/exclude-from-file
37         done
39         src_tree=$(basename ${S})
40         
41         echo $src_tree
42         oenote "Creating .orig.tar.gz in ${DEPLOY_DIR_SRC}/${PN}/${P}.orig.tar.gz"
43         tar cvzf ${DEPLOY_DIR_SRC}/${PN}/${P}.orig.tar.gz --exclude-from temp/exclude-from-file $src_tree
44         cp -pPR $src_tree $src_tree.orig
47 sourcepkg_do_archive_bb() {
49         src_tree=$(basename ${S})
50         dest=${WORKDIR}/$src_tree/${DISTRO}
51         mkdir -p $dest
53         cp ${FILE} $dest
56 python sourcepkg_do_dumpdata() {
58         workdir = bb.data.getVar('WORKDIR', d, 1)
59         distro = bb.data.getVar('DISTRO', d, 1)
60         s_tree = get_src_tree(d)
61         openembeddeddir = os.path.join(workdir, s_tree, distro)
62         dumpfile = os.path.join(openembeddeddir, bb.data.expand("${P}-${PR}.showdata.dump",d))
63         
64         try:
65                 os.mkdir(openembeddeddir)
66         except OSError:
67                 # dir exists
68                 pass
70         bb.note("Dumping metadata into '%s'" % dumpfile)
71         f = open(dumpfile, "w")
72         # emit variables and shell functions
73         bb.data.emit_env(f, d, True)
74         # emit the metadata which isnt valid shell
75         for e in d.keys():
76                 if bb.data.getVarFlag(e, 'python', d):
77                         f.write("\npython %s () {\n%s}\n" % (e, bb.data.getVar(e, d, 1)))
78         f.close()
81 sourcepkg_do_create_diff_gz(){
83         cd ${WORKDIR}
84         for i in ${EXCLUDE_FROM}; do
85                 echo $i >> temp/exclude-from-file
86         done
89         src_tree=$(basename ${S})
91         for i in `find . -maxdepth 1 -type f`; do
92                 mkdir -p $src_tree/${DISTRO}/files
93                 cp $i $src_tree/${DISTRO}/files
94         done
95         
96         oenote "Creating .diff.gz in ${DEPLOY_DIR_SRC}/${PN}/${PACKAGE_ARCH}/${P}-${PR}.diff.gz"
97         LC_ALL=C TZ=UTC0 diff --exclude-from=temp/exclude-from-file -Naur $src_tree.orig $src_tree | gzip -c > ${DEPLOY_DIR_SRC}/${PN}/${PACKAGE_ARCH}/${P}-${PR}.diff.gz
98         rm -rf $src_tree.orig
101 EXPORT_FUNCTIONS do_create_orig_tgz do_archive_bb do_dumpdata do_create_diff_gz
103 do_create_orig_tgz[deptask] = "do_unpack"
104 do_create_diff_gz[deptask] = "do_configure"
105 do_archive_bb[deptask] = "do_patch"
106 do_dumpdata[deptask] = "do_unpack"
108 addtask create_orig_tgz after do_unpack before do_patch
109 addtask archive_bb after do_patch before do_dumpdata
110 addtask dumpdata after do_archive_bb before do_create_diff_gz
111 addtask create_diff_gz after do_configure before do_compile