mirror of
https://github.com/google/pebble.git
synced 2025-07-28 18:24:55 -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/waftools/__init__.py
Normal file
14
tools/resources/waftools/__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.
|
||||
|
64
tools/resources/waftools/generate_builtin.py
Normal file
64
tools/resources/waftools/generate_builtin.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Node, Task, TaskGen
|
||||
|
||||
from resources.types.resource_ball import ResourceBall
|
||||
from resources.types.resource_definition import StorageType
|
||||
|
||||
import generate_c_byte_array
|
||||
|
||||
|
||||
class generate_builtin(Task.Task):
|
||||
def run(self):
|
||||
resource_ball = ResourceBall.load(self.inputs[0].abspath())
|
||||
resource_objects = [reso for reso in resource_ball.resource_objects
|
||||
if reso.definition.storage == StorageType.builtin]
|
||||
|
||||
with open(self.outputs[0].abspath(), 'w') as f:
|
||||
fw_bld_node = self.generator.bld.bldnode.find_node('src/fw')
|
||||
f.write('#include "{}"\n'.format(self.resource_id_header.path_from(fw_bld_node)))
|
||||
f.write('#include "resource/resource_storage.h"\n')
|
||||
f.write('#include "resource/resource_storage_builtin.h"\n\n')
|
||||
|
||||
def var_name(reso):
|
||||
return "{}_builtin_bytes".format(reso.definition.name)
|
||||
|
||||
# Write the blobs of data:
|
||||
for reso in resource_objects:
|
||||
# some resources require 8-byte aligned addresses
|
||||
# to simplify the handling we align all resources
|
||||
f.write('__attribute__ ((aligned (8)))\n')
|
||||
generate_c_byte_array.write(f, reso.data, var_name(reso))
|
||||
|
||||
f.write("\n")
|
||||
|
||||
f.write("const uint32_t g_num_builtin_resources = {};\n".format(len(resource_objects)))
|
||||
f.write("const BuiltInResourceData g_builtin_resources[] = {\n")
|
||||
|
||||
for reso in resource_objects:
|
||||
f.write(' {{ RESOURCE_ID_{resource_id}, {var_name}, sizeof({var_name}) }},\n'
|
||||
.format(resource_id=reso.definition.name,
|
||||
var_name=var_name(reso)))
|
||||
|
||||
f.write("};\n")
|
||||
|
||||
|
||||
@TaskGen.feature('generate_builtin')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def process_generate_builtin(self):
|
||||
task = self.create_task('generate_builtin',
|
||||
self.resource_ball,
|
||||
self.builtin_target)
|
||||
task.resource_id_header = self.resource_id_header
|
81
tools/resources/waftools/generate_fonts.py
Normal file
81
tools/resources/waftools/generate_fonts.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Task, TaskGen
|
||||
|
||||
from resources.types.resource_ball import ResourceBall
|
||||
|
||||
|
||||
def get_font_keys_from_resource_ball(resource_ball_node):
|
||||
resource_ball = ResourceBall.load(resource_ball_node.abspath())
|
||||
definitions = (o.definition for o in resource_ball.resource_objects)
|
||||
|
||||
font_keys = []
|
||||
for d in definitions:
|
||||
if d.type == 'font':
|
||||
font_keys.append(d.name)
|
||||
font_keys.extend(d.aliases)
|
||||
|
||||
return font_keys
|
||||
|
||||
|
||||
@Task.update_outputs
|
||||
class generate_font_header(Task.Task):
|
||||
def run(self):
|
||||
font_keys = get_font_keys_from_resource_ball(self.inputs[0])
|
||||
|
||||
with open(self.outputs[0].abspath(), 'w') as output_file:
|
||||
output_file.write("#pragma once\n\n")
|
||||
|
||||
for key in font_keys:
|
||||
output_file.write("#define FONT_KEY_{key} "
|
||||
"\"RESOURCE_ID_{key}\"\n".format(key=key))
|
||||
|
||||
# See PBL-9335. We removed this define as it's no longer a complete font. It looked the
|
||||
# same as Gothic 14, so going forward use that visual lookalike instead.
|
||||
output_file.write('#define FONT_KEY_FONT_FALLBACK "RESOURCE_ID_GOTHIC_14"\n')
|
||||
|
||||
|
||||
class generate_font_table(Task.Task):
|
||||
def run(self):
|
||||
font_keys = get_font_keys_from_resource_ball(self.inputs[0])
|
||||
|
||||
with open(self.outputs[0].abspath(), 'w') as output_file:
|
||||
output_file.write("""
|
||||
static const struct {
|
||||
const char *key_name;
|
||||
ResourceId resource_id;
|
||||
ResourceId extension_id;
|
||||
} s_font_resource_keys[] = {
|
||||
""")
|
||||
|
||||
for key in font_keys:
|
||||
output_file.write(" {{ FONT_KEY_{key}, "
|
||||
"RESOURCE_ID_{key}, "
|
||||
"RESOURCE_ID_{key}_EXTENDED }},\n".format(key=key))
|
||||
|
||||
output_file.write("};\n")
|
||||
|
||||
|
||||
@TaskGen.feature('generate_fonts')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def process_generate_fonts(self):
|
||||
task = self.create_task('generate_font_header',
|
||||
self.resource_ball,
|
||||
self.font_key_header)
|
||||
|
||||
if self.font_key_table is not None:
|
||||
task = self.create_task('generate_font_table',
|
||||
self.resource_ball,
|
||||
self.font_key_table)
|
44
tools/resources/waftools/generate_pbpack.py
Normal file
44
tools/resources/waftools/generate_pbpack.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Node, Task, TaskGen
|
||||
|
||||
from resources.types.resource_ball import ResourceBall
|
||||
from resources.types.resource_definition import StorageType
|
||||
|
||||
from pbpack import ResourcePack
|
||||
|
||||
|
||||
class generate_pbpack(Task.Task):
|
||||
def run(self):
|
||||
resource_ball = ResourceBall.load(self.inputs[0].abspath())
|
||||
resource_objects = [reso for reso in resource_ball.resource_objects
|
||||
if reso.definition.storage == StorageType.pbpack]
|
||||
|
||||
pack = ResourcePack(self.is_system)
|
||||
|
||||
for r in resource_objects:
|
||||
pack.add_resource(r.data)
|
||||
|
||||
with open(self.outputs[0].abspath(), 'wb') as f:
|
||||
pack.serialize(f)
|
||||
|
||||
|
||||
@TaskGen.feature('generate_pbpack')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def process_generate_pbpack(self):
|
||||
task = self.create_task('generate_pbpack',
|
||||
self.resource_ball,
|
||||
self.pbpack_target)
|
||||
task.is_system = getattr(self, 'is_system', False)
|
64
tools/resources/waftools/generate_pfs_resources.py
Normal file
64
tools/resources/waftools/generate_pfs_resources.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Task, TaskGen
|
||||
|
||||
|
||||
class pfs_resources_table(Task.Task):
|
||||
def run(self):
|
||||
with open(self.outputs[0].abspath(), 'w') as f:
|
||||
f.write("""
|
||||
//
|
||||
// AUTOGENERATED
|
||||
// DO NOT MODIFY
|
||||
//
|
||||
|
||||
#include "resource/resource_storage_file.h"
|
||||
""")
|
||||
|
||||
fw_bld_node = self.generator.bld.bldnode.find_node('src/fw')
|
||||
f.write('#include "{}"\n'.format(self.resource_id_header.path_from(fw_bld_node)))
|
||||
f.write('\n')
|
||||
|
||||
f.write('const uint32_t g_num_file_resource_stores = {};\n'
|
||||
.format(len(self.file_definitions)))
|
||||
f.write('\n')
|
||||
|
||||
f.write('const FileResourceData g_file_resource_stores[] = {\n')
|
||||
|
||||
for d in self.file_definitions:
|
||||
first_resource_id = 'RESOURCE_ID_{}'.format(d['resources'][0])
|
||||
last_resource_id = 'RESOURCE_ID_{}'.format(d['resources'][-1])
|
||||
|
||||
# FIXME: We should just get rid of this concept since it's trivially calculated at
|
||||
# compile time
|
||||
id_offset_expr = '({} - 1)'.format(first_resource_id)
|
||||
|
||||
filename = d['name']
|
||||
|
||||
f.write(' {{ {first}, {last}, {id_offset}, "{filename}" }},\n'
|
||||
.format(first=first_resource_id, last=last_resource_id,
|
||||
id_offset=id_offset_expr, filename=filename))
|
||||
|
||||
f.write("};\n")
|
||||
|
||||
|
||||
@TaskGen.feature('generate_pfs_resources')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def generate_pfs_resources(self):
|
||||
task = self.create_task('pfs_resources_table',
|
||||
self.resource_definition_files + [self.resource_id_header],
|
||||
self.pfs_table_node)
|
||||
task.file_definitions = self.file_definitions
|
||||
task.resource_id_header = self.resource_id_header
|
117
tools/resources/waftools/generate_resource_ball.py
Normal file
117
tools/resources/waftools/generate_resource_ball.py
Normal file
|
@ -0,0 +1,117 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Node, Task, TaskGen
|
||||
|
||||
from resources.resource_map import resource_generator
|
||||
from resources.resource_map.resource_generator_js import JsResourceGenerator
|
||||
from resources.types.resource_definition import StorageType
|
||||
from resources.types.resource_object import ResourceObject
|
||||
from resources.types.resource_ball import ResourceBall
|
||||
|
||||
|
||||
class reso(Task.Task):
|
||||
def run(self):
|
||||
reso = resource_generator.generate_object(self, self.definition)
|
||||
reso.dump(self.outputs[0])
|
||||
|
||||
|
||||
@Task.update_outputs
|
||||
class resource_ball(Task.Task):
|
||||
def run(self):
|
||||
resos = [ResourceObject.load(r.abspath()) for r in self.inputs]
|
||||
resource_id_mapping = getattr(self.env, 'RESOURCE_ID_MAPPING', {})
|
||||
|
||||
ordered_resos = []
|
||||
|
||||
# Sort the resources into an ordered list by storage. Don't just use sorted
|
||||
# because we want to preserve the ordering within the storage type. If a
|
||||
# resource id mapping exists, use that to sort the resources instead.
|
||||
if not resource_id_mapping:
|
||||
for s in [StorageType.pbpack, StorageType.builtin, StorageType.pfs]:
|
||||
ordered_resos.extend((o for o in resos if o.definition.storage == s))
|
||||
else:
|
||||
resos_dict = {resource_id_mapping[reso.definition.name]: reso for reso in resos}
|
||||
ordered_resos = [resos_dict[x] for x in range(1, len(resos) + 1)]
|
||||
|
||||
res_ball = ResourceBall(ordered_resos, getattr(self, 'resource_declarations', []))
|
||||
res_ball.dump(self.outputs[0])
|
||||
|
||||
|
||||
def process_resource_definition(task_gen, resource_definition):
|
||||
"""
|
||||
Create a task that generates a .reso and returns the node pointing to
|
||||
the output
|
||||
"""
|
||||
|
||||
sources = []
|
||||
for s in resource_definition.sources:
|
||||
source_node = task_gen.path.make_node(s)
|
||||
if source_node is None:
|
||||
task_gen.bld.fatal("Could not find resource at %s" %
|
||||
task_gen.bld.path.find_node(s).abspath())
|
||||
sources.append(source_node)
|
||||
|
||||
output_name = '%s.%s.%s' % (sources[0].relpath(), str(resource_definition.name), 'reso')
|
||||
|
||||
# Build our outputs in a directory relative to where our final pbpack is going to go
|
||||
output = task_gen.resource_ball.parent.make_node(output_name)
|
||||
|
||||
task = task_gen.create_task('reso', sources, output)
|
||||
task.definition = resource_definition
|
||||
task.dep_nodes = getattr(task_gen, 'resource_dependencies', [])
|
||||
|
||||
# Save JS bytecode filename for dependency calculation for SDK memory report
|
||||
if resource_definition.type == 'js' and 'PEBBLE_SDK_ROOT' in task_gen.env:
|
||||
task_gen.bld.all_envs[task_gen.env.PLATFORM_NAME].JS_RESO = output
|
||||
|
||||
return output
|
||||
|
||||
|
||||
@TaskGen.feature('generate_resource_ball')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def process_resource_ball(task_gen):
|
||||
"""
|
||||
resources: a list of ResourceDefinitions objects and nodes pointing to
|
||||
.reso files
|
||||
resource_dependencies: node list that all our generated resources depend on
|
||||
resource_ball: a node to where the ball should be generated
|
||||
vars: a list of environment variables that generated resources should depend on as a source
|
||||
"""
|
||||
resource_objects = []
|
||||
bundled_resos = []
|
||||
|
||||
for r in task_gen.resources:
|
||||
if isinstance(r, Node.Node):
|
||||
# It's already a node, presumably pointing to a .reso file
|
||||
resource_objects.append(r)
|
||||
else:
|
||||
# It's a resource definition, we need to process it into a .reso
|
||||
# file. Note this is where the task that does the data conversion
|
||||
# gets created.
|
||||
processed_resource = process_resource_definition(task_gen, r)
|
||||
resource_objects.append(processed_resource)
|
||||
bundled_resos.append(processed_resource)
|
||||
|
||||
if getattr(task_gen, 'project_resource_ball', None):
|
||||
prb_task = task_gen.create_task('resource_ball',
|
||||
bundled_resos,
|
||||
task_gen.project_resource_ball)
|
||||
prb_task.dep_node = getattr(task_gen, 'resource_dependencies', [])
|
||||
prb_task.dep_vars = getattr(task_gen, 'vars', [])
|
||||
|
||||
task = task_gen.create_task('resource_ball', resource_objects, task_gen.resource_ball)
|
||||
task.resource_declarations = getattr(task_gen, 'resource_declarations', [])
|
||||
task.dep_nodes = getattr(task_gen, 'resource_dependencies', [])
|
||||
task.dep_vars = getattr(task_gen, 'vars', [])
|
177
tools/resources/waftools/generate_resource_id_header.py
Normal file
177
tools/resources/waftools/generate_resource_id_header.py
Normal file
|
@ -0,0 +1,177 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Task, TaskGen
|
||||
|
||||
from resources.types.resource_ball import ResourceBall
|
||||
from resources.types.resource_definition import ResourceDefinition
|
||||
|
||||
|
||||
enum_header = (
|
||||
"""#pragma once
|
||||
|
||||
//
|
||||
// AUTOGENERATED BY BUILD
|
||||
// DO NOT MODIFY - CHANGES WILL BE OVERWRITTEN
|
||||
//
|
||||
|
||||
typedef enum {
|
||||
INVALID_RESOURCE = 0,
|
||||
RESOURCE_ID_INVALID = 0,
|
||||
DEFAULT_MENU_ICON = 0,
|
||||
""")
|
||||
|
||||
|
||||
define_header = (
|
||||
"""#pragma once
|
||||
|
||||
//
|
||||
// AUTOGENERATED BY BUILD
|
||||
// DO NOT MODIFY - CHANGES WILL BE OVERWRITTEN
|
||||
//
|
||||
|
||||
#define DEFAULT_MENU_ICON 0
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
extern_header = (
|
||||
"""#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
//
|
||||
// AUTOGENERATED BY BUILD
|
||||
// DO NOT MODIFY - CHANGES WILL BE OVERWRITTEN
|
||||
//
|
||||
|
||||
""")
|
||||
|
||||
|
||||
definitions_file = (
|
||||
"""#include <stdint.h>
|
||||
|
||||
//
|
||||
// AUTOGENERATED BY BUILD
|
||||
// DO NOT MODIFY - CHANGES WILL BE OVERWRITTEN
|
||||
//
|
||||
|
||||
""")
|
||||
|
||||
|
||||
@Task.update_outputs
|
||||
class generate_resource_id_header(Task.Task):
|
||||
def run(self):
|
||||
use_extern = getattr(self, 'use_extern', False)
|
||||
use_define = getattr(self, 'use_define', False)
|
||||
published_media = getattr(self, 'published_media', [])
|
||||
|
||||
if use_extern:
|
||||
RESOURCE_ID_DECLARATION = "extern uint32_t RESOURCE_ID_{};"
|
||||
PUBLISHED_ID_DECLARATION = "extern uint32_t PUBLISHED_ID_{};"
|
||||
elif use_define:
|
||||
RESOURCE_ID_DECLARATION = "#define RESOURCE_ID_{} {}"
|
||||
PUBLISHED_ID_DECLARATION = "#define PUBLISHED_ID_{} {}"
|
||||
else:
|
||||
RESOURCE_ID_DECLARATION = " RESOURCE_ID_{} = {},"
|
||||
INVALID_RESOURCE_ID_DECLARATION = " RESOURCE_ID_{} = INVALID_RESOURCE,"
|
||||
|
||||
if published_media:
|
||||
self.generator.bld.fatal("publishedMedia is only supported for resource headers "
|
||||
"using externs and defines. Check your "
|
||||
"generate_resource_id_header arguments.")
|
||||
|
||||
resource_ball = ResourceBall.load(self.inputs[0].abspath())
|
||||
declarations_dict = {d.name: d for d in resource_ball.get_all_declarations()}
|
||||
|
||||
self.outputs[0].parent.mkdir()
|
||||
with open(self.outputs[0].abspath(), 'w') as output_file:
|
||||
if use_extern:
|
||||
output_file.write(extern_header)
|
||||
elif use_define:
|
||||
output_file.write(define_header)
|
||||
else:
|
||||
output_file.write(enum_header)
|
||||
|
||||
# Write out all the fonts and their aliases
|
||||
for i, declaration in enumerate(resource_ball.get_all_declarations(), start=1):
|
||||
output_file.write(RESOURCE_ID_DECLARATION.format(declaration.name, i) + "\n")
|
||||
if isinstance(declaration, ResourceDefinition):
|
||||
for alias in declaration.aliases:
|
||||
output_file.write(RESOURCE_ID_DECLARATION.format(alias, i) + " // alias\n")
|
||||
for item in published_media:
|
||||
output_file.write(
|
||||
PUBLISHED_ID_DECLARATION.format(item['name'], item['id'] or 0) + "\n")
|
||||
|
||||
# Handle defining extended font ids for extended fonts that don't actually exist.
|
||||
# Every font should have a matching ID defined, but if the resource itself doesn't
|
||||
# exist we generate a fake ID for them.
|
||||
if not use_extern and not use_define:
|
||||
def write_invalid_id_if_needed(name):
|
||||
extended_name = name + '_EXTENDED'
|
||||
|
||||
if extended_name not in declarations_dict:
|
||||
output_file.write(INVALID_RESOURCE_ID_DECLARATION.format(extended_name) +
|
||||
"\n")
|
||||
|
||||
for o in resource_ball.resource_objects:
|
||||
if o.definition.type == 'font':
|
||||
write_invalid_id_if_needed(o.definition.name)
|
||||
|
||||
for alias in o.definition.aliases:
|
||||
write_invalid_id_if_needed(alias)
|
||||
output_file.write('} ResourceId;')
|
||||
|
||||
|
||||
@Task.update_outputs
|
||||
class generate_resource_id_definitions(Task.Task):
|
||||
def run(self):
|
||||
RESOURCE_ID_DEFINITION = "uint32_t RESOURCE_ID_{} = {};"
|
||||
PUBLISHED_ID_DEFINITION = "uint32_t PUBLISHED_ID_{} = {};"
|
||||
|
||||
resource_ball = ResourceBall.load(self.inputs[0].abspath())
|
||||
published_media = getattr(self, 'published_media', [])
|
||||
|
||||
self.outputs[0].parent.mkdir()
|
||||
with open(self.outputs[0].abspath(), 'w') as output_file:
|
||||
output_file.write(definitions_file)
|
||||
|
||||
for i, declaration in enumerate(resource_ball.get_all_declarations(), start=1):
|
||||
output_file.write(RESOURCE_ID_DEFINITION.format(declaration.name, i) + "\n")
|
||||
if isinstance(declaration, ResourceDefinition):
|
||||
for alias in declaration.aliases:
|
||||
output_file.write(RESOURCE_ID_DEFINITION.format(alias, i) + " // alias\n")
|
||||
|
||||
for item in published_media:
|
||||
output_file.write(PUBLISHED_ID_DEFINITION.format(item['name'], item['id']))
|
||||
|
||||
|
||||
@TaskGen.feature('generate_resource_id_header')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def process_generate_resource_id_header(self):
|
||||
task = self.create_task('generate_resource_id_header',
|
||||
self.resource_ball,
|
||||
self.resource_id_header_target)
|
||||
task.use_extern = getattr(self, 'use_extern', False)
|
||||
task.use_define = getattr(self, 'use_define', False)
|
||||
task.published_media = getattr(self, 'published_media', [])
|
||||
|
||||
|
||||
@TaskGen.feature('generate_resource_id_definitions')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def generate_resource_id_definitions(self):
|
||||
task = self.create_task('generate_resource_id_definitions',
|
||||
self.resource_ball,
|
||||
self.resource_id_definitions_target)
|
||||
task.published_media = getattr(self, 'published_media', [])
|
95
tools/resources/waftools/generate_timeline.py
Normal file
95
tools/resources/waftools/generate_timeline.py
Normal file
|
@ -0,0 +1,95 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Task, TaskGen
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class generate_timeline_table(Task.Task):
|
||||
def run(self):
|
||||
with open(self.outputs[0].abspath(), 'w') as f:
|
||||
f.write("""
|
||||
//
|
||||
// AUTOGENERATED
|
||||
// DO NOT MODIFY
|
||||
//
|
||||
|
||||
#include "resource/resource_ids.auto.h"
|
||||
#include "services/normal/timeline/timeline_resources.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
const uint16_t g_timeline_resources[][TimelineResourceSizeCount] = {
|
||||
""")
|
||||
|
||||
for res in self.timeline_dict:
|
||||
f.write(" [{}] = {{ {}, {}, {} }},\n"
|
||||
.format(res["id"],
|
||||
res["sizes"].get('tiny', 'RESOURCE_ID_INVALID'),
|
||||
res["sizes"].get('small', 'RESOURCE_ID_INVALID'),
|
||||
res["sizes"].get('large', 'RESOURCE_ID_INVALID')))
|
||||
|
||||
f.write("};\n")
|
||||
|
||||
|
||||
class generate_timeline_ids(Task.Task):
|
||||
def run(self):
|
||||
with open(self.outputs[0].abspath(), 'w') as f:
|
||||
f.write("""
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// AUTOGENERATED
|
||||
// DO NOT MODIFY
|
||||
//
|
||||
|
||||
typedef enum {
|
||||
TIMELINE_RESOURCE_INVALID = 0,
|
||||
""")
|
||||
|
||||
SYSTEM_RESOURCE_FLAG = 0x80000000
|
||||
max_timeline_id = 0
|
||||
for res in self.timeline_dict:
|
||||
max_timeline_id = max(max_timeline_id, res["id"])
|
||||
id = res["id"] | SYSTEM_RESOURCE_FLAG
|
||||
f.write(" TIMELINE_RESOURCE_{} = {:#x},\n".format(res["name"], id))
|
||||
|
||||
f.write("} TimelineResourceId;\n\n")
|
||||
f.write("#define NUM_TIMELINE_RESOURCES {}\n".format(max_timeline_id + 1))
|
||||
|
||||
|
||||
@TaskGen.feature('generate_timeline')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def process_generate_timeline(self):
|
||||
# map the resources into URIs and invert the key/val
|
||||
timeline_uris = {"system://images/" + r["name"]: r["id"] for r in self.timeline_dict
|
||||
if not r.get("internal", False)}
|
||||
self.RESOURCE_URIS = json.dumps(timeline_uris, indent=4)
|
||||
|
||||
# substitute it into the json template
|
||||
layouts_in = self.bld.path.find_node('resources/normal/base/layouts/layouts.json.in')
|
||||
task = self.create_task('subst',
|
||||
[layouts_in] + self.resource_definition_files,
|
||||
self.layouts_node)
|
||||
|
||||
task = self.create_task('generate_timeline_table',
|
||||
self.resource_definition_files,
|
||||
self.timeline_table_node)
|
||||
task.timeline_dict = self.timeline_dict
|
||||
|
||||
task = self.create_task('generate_timeline_ids',
|
||||
self.resource_definition_files,
|
||||
self.timeline_ids_node)
|
||||
task.timeline_dict = self.timeline_dict
|
54
tools/resources/waftools/generate_version_header.py
Normal file
54
tools/resources/waftools/generate_version_header.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
# 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.
|
||||
|
||||
from waflib import Node, Task, TaskGen
|
||||
|
||||
from resources.types.resource_ball import ResourceBall
|
||||
|
||||
from pbpack import ResourcePack
|
||||
|
||||
|
||||
class generate_version_header(Task.Task):
|
||||
def run(self):
|
||||
if len(self.inputs):
|
||||
# is_system=True because only firmwares use version headers
|
||||
with open(self.inputs[0].abspath(), 'rb') as f:
|
||||
pbpack = ResourcePack.deserialize(f, is_system=True)
|
||||
resource_crc = pbpack.get_content_crc()
|
||||
else:
|
||||
resource_crc = 0
|
||||
|
||||
self.outputs[0].parent.mkdir() # Make sure the output directory exists
|
||||
with open(self.outputs[0].abspath(), 'w') as output_file:
|
||||
output_file.write("""
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// AUTOGENERATED
|
||||
// DO NOT MODIFY
|
||||
//
|
||||
|
||||
static const ResourceVersion SYSTEM_RESOURCE_VERSION = {{
|
||||
.crc = {},
|
||||
.timestamp = 0
|
||||
}};
|
||||
""".format(resource_crc))
|
||||
|
||||
|
||||
@TaskGen.feature('generate_version_header')
|
||||
@TaskGen.before_method('process_source', 'process_rule')
|
||||
def process_generate_version_header(self):
|
||||
task = self.create_task('generate_version_header',
|
||||
self.pbpack,
|
||||
self.version_header_target)
|
Loading…
Add table
Add a link
Reference in a new issue