1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements.  See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership.  The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License.  You may obtain a copy of the License at
8#
9#   http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied.  See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18"""Defines an Artifact implementation for representing compiled micro TVM binaries."""
19
20from . import artifact
21
22
23class MicroBinary(artifact.Artifact):
24    """An Artifact that describes a compiled binary."""
25
26    ARTIFACT_TYPE = "micro_binary"
27
28    @classmethod
29    def from_unarchived(cls, base_dir, labelled_files, metadata):
30        binary_file = labelled_files["binary_file"][0]
31        del labelled_files["binary_file"]
32
33        debug_files = None
34        if "debug_files" in labelled_files:
35            debug_files = labelled_files["debug_files"]
36            del labelled_files["debug_files"]
37
38        return cls(
39            base_dir,
40            binary_file,
41            debug_files=debug_files,
42            labelled_files=labelled_files,
43            metadata=metadata,
44        )
45
46    def __init__(self, base_dir, binary_file, debug_files=None, labelled_files=None, metadata=None):
47        labelled_files = {} if labelled_files is None else dict(labelled_files)
48        metadata = {} if metadata is None else dict(metadata)
49        labelled_files["binary_file"] = [binary_file]
50        if debug_files is not None:
51            labelled_files["debug_files"] = debug_files
52
53        super(MicroBinary, self).__init__(base_dir, labelled_files, metadata)
54
55        self.binary_file = binary_file
56        self.debug_files = debug_files
57