blob: 979578c41dc72942d5f10927232827569a6f3407 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# This class should provide easy access to the different aspects of the
2# buildsystem such as layers, bitbake location, etc.
3import stat
4import shutil
5
6def _smart_copy(src, dest):
7 # smart_copy will choose the correct function depending on whether the
8 # source is a file or a directory.
9 mode = os.stat(src).st_mode
10 if stat.S_ISDIR(mode):
11 shutil.copytree(src, dest, symlinks=True)
12 else:
13 shutil.copyfile(src, dest)
14 shutil.copymode(src, dest)
15
16class BuildSystem(object):
17 def __init__(self, d):
18 self.d = d
19 self.layerdirs = d.getVar('BBLAYERS', True).split()
20
21 def copy_bitbake_and_layers(self, destdir):
22 # Copy in all metadata layers + bitbake (as repositories)
23 layers_copied = []
24 bb.utils.mkdirhier(destdir)
25 layers = list(self.layerdirs)
26
27 corebase = self.d.getVar('COREBASE', True)
28 layers.append(corebase)
29
30 corebase_files = self.d.getVar('COREBASE_FILES', True).split()
31 corebase_files = [corebase + '/' +x for x in corebase_files]
32 # Make sure bitbake goes in
33 bitbake_dir = bb.__file__.rsplit('/', 3)[0]
34 corebase_files.append(bitbake_dir)
35
36 for layer in layers:
37 layerconf = os.path.join(layer, 'conf', 'layer.conf')
38 if os.path.exists(layerconf):
39 with open(layerconf, 'r') as f:
40 if f.readline().startswith("# ### workspace layer auto-generated by devtool ###"):
41 bb.warn("Skipping local workspace layer %s" % layer)
42 continue
43
44 # If the layer was already under corebase, leave it there
45 # since layers such as meta have issues when moved.
46 layerdestpath = destdir
47 if corebase == os.path.dirname(layer):
48 layerdestpath += '/' + os.path.basename(corebase)
49 layerdestpath += '/' + os.path.basename(layer)
50
51 layer_relative = os.path.relpath(layerdestpath,
52 destdir)
53 layers_copied.append(layer_relative)
54
55 # Treat corebase as special since it typically will contain
56 # build directories or other custom items.
57 if corebase == layer:
58 bb.utils.mkdirhier(layerdestpath)
59 for f in corebase_files:
60 f_basename = os.path.basename(f)
61 destname = os.path.join(layerdestpath, f_basename)
62 _smart_copy(f, destname)
63 else:
64 if os.path.exists(layerdestpath):
65 bb.note("Skipping layer %s, already handled" % layer)
66 else:
67 _smart_copy(layer, layerdestpath)
68
69 return layers_copied
70
71def generate_locked_sigs(sigfile, d):
72 bb.utils.mkdirhier(os.path.dirname(sigfile))
73 depd = d.getVar('BB_TASKDEPDATA', True)
74 tasks = ['%s.%s' % (v[2], v[1]) for v in depd.itervalues()]
75 bb.parse.siggen.dump_lockedsigs(sigfile, tasks)
76
77def prune_lockedsigs(allowed_tasks, excluded_targets, lockedsigs, pruned_output):
78 with open(lockedsigs, 'r') as infile:
79 bb.utils.mkdirhier(os.path.dirname(pruned_output))
80 with open(pruned_output, 'w') as f:
81 invalue = False
82 for line in infile:
83 if invalue:
84 if line.endswith('\\\n'):
85 splitval = line.strip().split(':')
86 if splitval[1] in allowed_tasks and not splitval[0] in excluded_targets:
87 f.write(line)
88 else:
89 f.write(line)
90 invalue = False
91 elif line.startswith('SIGGEN_LOCKEDSIGS'):
92 invalue = True
93 f.write(line)
94
95def create_locked_sstate_cache(lockedsigs, input_sstate_cache, output_sstate_cache, d, fixedlsbstring=""):
96 bb.note('Generating sstate-cache...')
97
98 bb.process.run("gen-lockedsig-cache %s %s %s" % (lockedsigs, input_sstate_cache, output_sstate_cache))
99 if fixedlsbstring:
100 os.rename(output_sstate_cache + '/' + d.getVar('NATIVELSBSTRING', True),
101 output_sstate_cache + '/' + fixedlsbstring)