forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set LastKnownGoodTime using UTC via python-generated header (project-…
…chip#28668) * WIP: set LKGT using UTC via python * appease the linter * Changes from review * Remove header guard cruft
- Loading branch information
1 parent
7213660
commit 7c4c966
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) 2023 Project CHIP Authors | ||
# | ||
# 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 argparse | ||
import os | ||
from datetime import datetime, timezone | ||
|
||
|
||
def utc_time_in_matter_epoch_s(): | ||
""" Returns the time in matter epoch in s. """ | ||
# Matter epoch is 0 hours, 0 minutes, 0 seconds on Jan 1, 2000 UTC | ||
utc_matter = datetime.now(tz=timezone.utc) - datetime(2000, 1, 1, 0, 0, 0, 0, timezone.utc) | ||
return int(utc_matter.total_seconds()) | ||
|
||
|
||
class Options: | ||
def __init__(self, output, define_name, define_val): | ||
self.output = output | ||
self.define_name = define_name | ||
self.define_val = define_val | ||
|
||
|
||
def GetOptions(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--output', help="Output header name (inside gen dir)") | ||
parser.add_argument('--gen-dir', | ||
help="Path to root of generated file directory tree.") | ||
cmdline_options = parser.parse_args() | ||
|
||
# The actual output file is inside the gen dir. | ||
output = os.path.join(cmdline_options.gen_dir, cmdline_options.output) | ||
|
||
define_name = 'CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_TIME_MATTER_EPOCH_S' | ||
build_time = utc_time_in_matter_epoch_s() | ||
|
||
return Options(output=output, | ||
define_name=define_name, | ||
define_val=str(build_time)) | ||
|
||
|
||
def WriteHeader(options): | ||
with open(options.output, "w") as output_file: | ||
output_file.write("// Generated by write_build_time_header.py\n") | ||
output_file.write('#pragma once\n\n') | ||
|
||
output_file.write(f'#define {options.define_name} {options.define_val}\n') | ||
|
||
|
||
options = GetOptions() | ||
WriteHeader(options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters