6 import lttng_ivc
.utils
.project
as Project
7 import lttng_ivc
.settings
as Settings
10 _logger
= logging
.getLogger('project.factory')
11 _project_constructor
= {
12 'babeltrace': Project
.Babeltrace
,
13 'lttng-modules': Project
.Lttng_modules
,
14 'lttng-tools': Project
.Lttng_tools
,
15 'lttng-ust': Project
.Lttng_ust
,
21 with
open(Settings
.run_configuration_file
, 'r') as stream
:
22 # This is voluntary static across calls, no need to perform this
24 _markers
= yaml
.load(stream
)
27 def get_fresh(label
, tmpdir
):
28 if label
not in _markers
:
29 # TODO: specialized exception, handle it caller-side so the caller
30 # can decide to skip or fail test.
31 raise Exception('Label is no present')
32 marker
= _markers
[label
]
33 constructor
= _project_constructor
[marker
['project']]
36 return constructor(label
, path
, sha1
, tmpdir
)
39 def _validate_pickle(pickle
, label
):
40 _logger
.debug("Checking validate for {} {}".format(pickle
,
42 if pickle
.label
!= label
:
43 _logger
.warn("Label {} and {} are not the same".format(pickle
.label
,
46 if pickle
.sha1
!= _markers
[label
]['sha1']:
47 _logger
.warn("Sha1 {} and {} are not the same".format(pickle
.sha1
,
48 _markers
[label
]['sha1']))
51 deps
= _markers
[label
]['deps']
52 if len(deps
) != len(pickle
.dependencies
):
53 _logger
.warn("Len {} and {} are not the same".format(len(deps
),
54 len(pickle
.dependencies
)))
57 if dep
not in pickle
.dependencies
:
58 _logger
.warn("Dep {} is not in {}".format(dep
,
62 _logger
.debug("Calling validate {} {}".format(pickle
.dependencies
[dep
],
64 valid
= _validate_pickle(pickle
.dependencies
[dep
], dep
)
70 def get_precook(label
):
72 Retrieve a precooked immutable projects from a cache if present
73 otherwise the project is built, installed and cached for future access.
75 if label
not in _markers
:
76 # TODO: specialized exception, handle it caller-side so the caller
77 # can decide to skip or fail test.
78 raise Exception('Label is no present')
79 marker
= _markers
[label
]
80 constructor
= _project_constructor
[marker
['project']]
85 # Cache path for the label
86 cache_path
= os
.path
.join(Settings
.projects_cache_folder
, label
)
87 pickle_path
= os
.path
.join(cache_path
, label
+".pickle")
89 # Check if Pickle Rick is present and valid. If so return it asap.
90 if os
.path
.exists(pickle_path
):
91 with
open(pickle_path
, 'rb') as pickle_file
:
92 pickled
= pickle
.load(pickle_file
)
93 if _validate_pickle(pickled
, label
):
97 _logger
.warn("Pickle for {} is invalid. Rebuilding".format(label
))
99 project
= constructor(label
, path
, sha1
, cache_path
)
102 obj_dep
= get_precook(dep
)
103 project
.dependencies
[dep
] = obj_dep
106 project
._immutable
= True
107 with
open(pickle_path
, 'wb') as pickle_file
:
108 pickle
.dump(project
, pickle_file
)
This page took 0.041131 seconds and 5 git commands to generate.