1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from collections
import defaultdict
7 import mozpack
.path
as mozpath
9 import six
.moves
.cPickle
as pickle
11 from mozbuild
.backend
.base
import PartialBackend
12 from mozbuild
.frontend
.data
import TestManifest
15 class TestManifestBackend(PartialBackend
):
16 """Partial backend that generates test metadata files."""
19 self
.tests_by_path
= defaultdict(list)
20 self
.installs_by_path
= defaultdict(list)
21 self
.deferred_installs
= set()
22 self
.manifest_defaults
= {}
24 # Add config.status so performing a build will invalidate this backend.
25 self
.backend_input_files
.add(
26 mozpath
.join(self
.environment
.topobjdir
, "config.status")
29 def consume_object(self
, obj
):
30 if not isinstance(obj
, TestManifest
):
33 self
.backend_input_files
.add(obj
.path
)
34 self
.backend_input_files |
= obj
.context_all_paths
35 for source
in obj
.source_relpaths
:
36 self
.backend_input_files
.add(mozpath
.join(obj
.topsrcdir
, source
))
38 from reftest
import ReftestManifest
40 if isinstance(obj
.manifest
, ReftestManifest
):
41 # Mark included files as part of the build backend so changes
42 # result in re-config.
43 self
.backend_input_files |
= obj
.manifest
.manifests
45 # Ignore errors caused by the reftest module not being present.
46 # This can happen when building SpiderMonkey standalone, for example.
49 for test
in obj
.tests
:
50 self
.add(test
, obj
.flavor
, obj
.topsrcdir
)
51 self
.add_defaults(obj
.manifest
)
52 self
.add_installs(obj
, obj
.topsrcdir
)
54 def consume_finished(self
):
55 topobjdir
= self
.environment
.topobjdir
57 with self
._write
_file
(
58 mozpath
.join(topobjdir
, "all-tests.pkl"), readmode
="rb"
60 pickle
.dump(dict(self
.tests_by_path
), fh
, protocol
=2)
62 with self
._write
_file
(
63 mozpath
.join(topobjdir
, "test-defaults.pkl"), readmode
="rb"
65 pickle
.dump(self
.manifest_defaults
, fh
, protocol
=2)
67 path
= mozpath
.join(topobjdir
, "test-installs.pkl")
68 with self
._write
_file
(path
, readmode
="rb") as fh
:
72 for k
, v
in self
.installs_by_path
.items()
73 if k
in self
.deferred_installs
79 def add(self
, t
, flavor
, topsrcdir
):
83 path
= mozpath
.normpath(t
["path"])
84 manifest
= mozpath
.normpath(t
["manifest"])
85 assert mozpath
.basedir(path
, [topsrcdir
])
86 assert mozpath
.basedir(manifest
, [topsrcdir
])
88 key
= path
[len(topsrcdir
) + 1 :]
89 t
["file_relpath"] = key
90 t
["dir_relpath"] = mozpath
.dirname(key
)
91 t
["srcdir_relpath"] = key
92 t
["manifest_relpath"] = manifest
[len(topsrcdir
) + 1 :]
94 self
.tests_by_path
[key
].append(t
)
96 def add_defaults(self
, manifest
):
97 if not hasattr(manifest
, "manifest_defaults"):
99 for sub_manifest
, defaults
in manifest
.manifest_defaults
.items():
100 self
.manifest_defaults
[sub_manifest
] = defaults
102 def add_installs(self
, obj
, topsrcdir
):
103 for src
, (dest
, _
) in six
.iteritems(obj
.installs
):
104 key
= src
[len(topsrcdir
) + 1 :]
105 self
.installs_by_path
[key
].append((src
, dest
))
106 for src
, pat
, dest
in obj
.pattern_installs
:
107 key
= mozpath
.join(src
[len(topsrcdir
) + 1 :], pat
)
108 self
.installs_by_path
[key
].append((src
, pat
, dest
))
109 for path
in obj
.deferred_installs
:
110 self
.deferred_installs
.add(path
[2:])