mirror of
https://github.com/google/pebble.git
synced 2025-07-21 06:44:49 -04:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
14
tools/resources/types/__init__.py
Normal file
14
tools/resources/types/__init__.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Copyright 2024 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
55
tools/resources/types/resource_ball.py
Normal file
55
tools/resources/types/resource_ball.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
# Copyright 2024 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import pickle
|
||||
|
||||
|
||||
class ResourceBall(object):
|
||||
""" A object meant to be serialized to the filesystem that represents the complete set of
|
||||
resources for a firmware variant. Resources that are distributed with the firmware are present
|
||||
as ResourceObject instances where resources that are not (such as language packs) are present
|
||||
as ResourceDeclaration instances. This data structure is ordered, with the resource_objects
|
||||
conceptually coming first followed by the resource_declarations.
|
||||
"""
|
||||
|
||||
def __init__(self, resource_objects, resource_declarations):
|
||||
self.resource_objects = resource_objects
|
||||
self.resource_declarations = resource_declarations
|
||||
|
||||
def get_all_declarations(self):
|
||||
return [o.definition for o in self.resource_objects] + self.resource_declarations
|
||||
|
||||
def dump(self, output_node):
|
||||
output_node.parent.mkdir()
|
||||
with open(output_node.abspath(), 'wb') as f:
|
||||
pickle.dump(self, f, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
@classmethod
|
||||
def load(cls, path):
|
||||
with open(path, 'rb') as f:
|
||||
return pickle.load(f)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('resball')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
rb = ResourceBall.load(args.resball)
|
||||
|
||||
for i, o in enumerate(rb.resource_objects, start=1):
|
||||
print "%4u: %-50s %-10s %6u" % (i, o.definition.name, o.definition.type, len(o.data))
|
23
tools/resources/types/resource_declaration.py
Normal file
23
tools/resources/types/resource_declaration.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Copyright 2024 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
class ResourceDeclaration(object):
|
||||
""" A resource that has a name and nothing else.
|
||||
|
||||
Used for resources that are stored on the filesystem. We don't know anything about these
|
||||
resources other than that they exist at firmware compile time.
|
||||
"""
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
52
tools/resources/types/resource_definition.py
Normal file
52
tools/resources/types/resource_definition.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
# Copyright 2024 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
from resources.types.resource_declaration import ResourceDeclaration
|
||||
|
||||
|
||||
class StorageType(object):
|
||||
pbpack = 1
|
||||
builtin = 2
|
||||
pfs = 3
|
||||
|
||||
|
||||
class ResourceDefinition(ResourceDeclaration):
|
||||
def __init__(self, type, name, file, storage=StorageType.pbpack,
|
||||
target_platforms=None, aliases=()):
|
||||
self.type = type
|
||||
self.name = name
|
||||
|
||||
self.file = file
|
||||
|
||||
self.storage = storage
|
||||
|
||||
# A list of platforms this resource is valid for. None means all platforms. [] means none.
|
||||
self.target_platforms = target_platforms
|
||||
self.aliases = list(aliases)
|
||||
|
||||
self.sources = [self.file]
|
||||
|
||||
def is_in_target_platform(self, bld):
|
||||
if self.target_platforms is None:
|
||||
return True
|
||||
|
||||
return bld.env.PLATFORM_NAME in self.target_platforms
|
||||
|
||||
def find_specific_filename(self, task_gen):
|
||||
return find_most_specific_filename(task_gen.bld, task_gen.env, task_gen.bld.path, self.file)
|
||||
|
||||
def __repr__(self):
|
||||
return '<ResourceDefinition %r>' % self.__dict__
|
38
tools/resources/types/resource_object.py
Normal file
38
tools/resources/types/resource_object.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Copyright 2024 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import pickle
|
||||
|
||||
class ResourceObject(object):
|
||||
"""
|
||||
Defines a single resource object in a namespace. Must be serializable.
|
||||
"""
|
||||
|
||||
def __init__(self, definition, data):
|
||||
self.definition = definition
|
||||
|
||||
if isinstance(data, list):
|
||||
self.data = b"".join(data)
|
||||
else:
|
||||
self.data = data
|
||||
|
||||
def dump(self, output_node):
|
||||
output_node.parent.mkdir()
|
||||
with open(output_node.abspath(), 'wb') as f:
|
||||
pickle.dump(self, f, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
@classmethod
|
||||
def load(cls, path):
|
||||
with open(path, 'rb') as f:
|
||||
return pickle.load(f)
|
Loading…
Add table
Add a link
Reference in a new issue