blob: c0e7541c02ae210037b6edf9cff407bb44bb8863 [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):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050017 def __init__(self, context, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018 self.d = d
Patrick Williamsf1e5d692016-03-30 15:21:19 -050019 self.context = context
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020 self.layerdirs = d.getVar('BBLAYERS', True).split()
21
22 def copy_bitbake_and_layers(self, destdir):
23 # Copy in all metadata layers + bitbake (as repositories)
24 layers_copied = []
25 bb.utils.mkdirhier(destdir)
26 layers = list(self.layerdirs)
27
28 corebase = self.d.getVar('COREBASE', True)
29 layers.append(corebase)
30
31 corebase_files = self.d.getVar('COREBASE_FILES', True).split()
32 corebase_files = [corebase + '/' +x for x in corebase_files]
33 # Make sure bitbake goes in
34 bitbake_dir = bb.__file__.rsplit('/', 3)[0]
35 corebase_files.append(bitbake_dir)
36
37 for layer in layers:
38 layerconf = os.path.join(layer, 'conf', 'layer.conf')
39 if os.path.exists(layerconf):
40 with open(layerconf, 'r') as f:
41 if f.readline().startswith("# ### workspace layer auto-generated by devtool ###"):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050042 bb.plain("NOTE: Excluding local workspace layer %s from %s" % (layer, self.context))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 continue
44
45 # If the layer was already under corebase, leave it there
46 # since layers such as meta have issues when moved.
47 layerdestpath = destdir
48 if corebase == os.path.dirname(layer):
49 layerdestpath += '/' + os.path.basename(corebase)
50 layerdestpath += '/' + os.path.basename(layer)
51
52 layer_relative = os.path.relpath(layerdestpath,
53 destdir)
54 layers_copied.append(layer_relative)
55
56 # Treat corebase as special since it typically will contain
57 # build directories or other custom items.
58 if corebase == layer:
59 bb.utils.mkdirhier(layerdestpath)
60 for f in corebase_files:
61 f_basename = os.path.basename(f)
62 destname = os.path.join(layerdestpath, f_basename)
63 _smart_copy(f, destname)
64 else:
65 if os.path.exists(layerdestpath):
66 bb.note("Skipping layer %s, already handled" % layer)
67 else:
68 _smart_copy(layer, layerdestpath)
69
70 return layers_copied
71
72def generate_locked_sigs(sigfile, d):
73 bb.utils.mkdirhier(os.path.dirname(sigfile))
74 depd = d.getVar('BB_TASKDEPDATA', True)
75 tasks = ['%s.%s' % (v[2], v[1]) for v in depd.itervalues()]
76 bb.parse.siggen.dump_lockedsigs(sigfile, tasks)
77
78def prune_lockedsigs(allowed_tasks, excluded_targets, lockedsigs, pruned_output):
79 with open(lockedsigs, 'r') as infile:
80 bb.utils.mkdirhier(os.path.dirname(pruned_output))
81 with open(pruned_output, 'w') as f:
82 invalue = False
83 for line in infile:
84 if invalue:
85 if line.endswith('\\\n'):
86 splitval = line.strip().split(':')
87 if splitval[1] in allowed_tasks and not splitval[0] in excluded_targets:
88 f.write(line)
89 else:
90 f.write(line)
91 invalue = False
92 elif line.startswith('SIGGEN_LOCKEDSIGS'):
93 invalue = True
94 f.write(line)
95
96def create_locked_sstate_cache(lockedsigs, input_sstate_cache, output_sstate_cache, d, fixedlsbstring=""):
97 bb.note('Generating sstate-cache...')
98
99 bb.process.run("gen-lockedsig-cache %s %s %s" % (lockedsigs, input_sstate_cache, output_sstate_cache))
100 if fixedlsbstring:
101 os.rename(output_sstate_cache + '/' + d.getVar('NATIVELSBSTRING', True),
102 output_sstate_cache + '/' + fixedlsbstring)