1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00
esp8266/tools/makecorever.py
Earle F. Philhower, III 0a031ce957
Move all scripts and documentation to Python3 (#6378)
* Move all scripts and documentation to Python3

Python 2 EOL is Jan 1, 2020.  Migrate scripts to run under Python 3.

Under Windows, we're already running Python 3.7, by dumb luck.  The
oddness is that the Windows standalone executable for Python 3 is called
"python" whereas under UNIX-like OSes it's called "python3" with
"python" always referring to the Python 2 executable.  The ZIP needs to
be updated to include a Python3.exe (copy of Python.exe) so that we can
use the same command lines under Linux and Windows, and to preserve my
sanity.

Fixes #6376

* Add new Windows ZIP with python3.exe file

* Sort options in boards.txt generation for repeatability

The order of the board opts dict changes depending on the Python version
and machine, so sort the options before printing them to get a stable
ordering.

* Re-add Python2 compatibility tweaks

Most scripts can run as Python 2 or Python 3 with minimal changes, so
re-add (and fix, as necessary) compatibility tweaks to the scripts.
2019-08-28 12:42:48 -07:00

84 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
# Generate the core_version.h header per-build
#
# Copyright (C) 2019 - Earle F. Philhower, III
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import argparse
import os
import subprocess
def generate(path, platform_path, git_ver="ffffffff", git_desc="unspecified"):
def git(*args):
cmd = ["git", "-C", platform_path]
cmd.extend(args)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
return proc.stdout.readlines()[0].strip()
try:
git_ver = git("rev-parse", "--short=8", "HEAD")
git_desc = git("describe", "--tags")
except:
pass
text = "#define ARDUINO_ESP8266_GIT_VER 0x{}\n".format(git_ver)
text += "#define ARDUINO_ESP8266_GIT_DESC {}\n".format(git_desc)
try:
with open(path, "r") as inp:
old_text = inp.read()
if old_text == text:
return
except:
pass
with open(path, "w") as out:
out.write(text)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate core_version.h")
parser.add_argument(
"-b", "--build_path", action="store", required=True, help="build.path variable"
)
parser.add_argument(
"-p",
"--platform_path",
action="store",
required=True,
help="platform.path variable",
)
parser.add_argument(
"-v", "--version", action="store", required=True, help="version variable"
)
parser.add_argument("-i", "--include_dir", default="core")
args = parser.parse_args()
include_dir = os.path.join(args.build_path, args.include_dir)
try:
os.makedirs(include_dir)
except:
pass
generate(
os.path.join(include_dir, "core_version.h"),
args.platform_path,
git_desc=args.version,
)