Add ESPHOME_VERSION_CODE define (#2324)

This commit is contained in:
Oxan van Leeuwen 2021-09-20 10:16:59 +02:00 committed by GitHub
parent 9ebe075f9b
commit 7452ef23b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -6,4 +6,7 @@
//
// This file is only used by static analyzers and IDEs.
#include "esphome/core/macros.h"
#define ESPHOME_VERSION "dev"
#define ESPHOME_VERSION_CODE VERSION_CODE(2099, 12, 0)

View file

@ -342,7 +342,9 @@ DEFINES_H_FORMAT = ESPHOME_H_FORMAT = """\
"""
VERSION_H_FORMAT = """\
#pragma once
#include "esphome/core/macros.h"
#define ESPHOME_VERSION "{}"
#define ESPHOME_VERSION_CODE VERSION_CODE({}, {}, {})
"""
DEFINES_H_TARGET = "esphome/core/defines.h"
VERSION_H_TARGET = "esphome/core/version.h"
@ -415,8 +417,7 @@ def copy_src_tree():
CORE.relative_src_path("esphome.h"), ESPHOME_H_FORMAT.format(include_s)
)
write_file_if_changed(
CORE.relative_src_path("esphome", "core", "version.h"),
VERSION_H_FORMAT.format(__version__),
CORE.relative_src_path("esphome", "core", "version.h"), generate_version_h()
)
@ -426,6 +427,15 @@ def generate_defines_h():
return DEFINES_H_FORMAT.format("\n".join(define_content_l))
def generate_version_h():
match = re.match(r"^(\d+)\.(\d+).(\d+)-?\w*$", __version__)
if not match:
raise EsphomeError(f"Could not parse version {__version__}.")
return VERSION_H_FORMAT.format(
__version__, match.group(1), match.group(2), match.group(3)
)
def write_cpp(code_s):
path = CORE.relative_src_path("main.cpp")
if os.path.isfile(path):