-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codal_port: Update to build with latest micropython.
The only user-facing change is the addition of time.ticks_cpu(). Signed-off-by: Damien George <[email protected]>
- Loading branch information
Showing
11 changed files
with
198 additions
and
136 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
""" | ||
Generate header file with macros defining micro:bit version info. | ||
Adapted from MicroPython's py/makeversionhdr.py file at v1.21.0. | ||
""" | ||
|
||
import argparse | ||
import sys | ||
import os | ||
import datetime | ||
import subprocess | ||
|
||
|
||
def get_version_info_from_git(repo_path): | ||
# Note: git describe doesn't work if no tag is available | ||
try: | ||
git_tag = subprocess.check_output( | ||
["git", "describe", "--tags", "--dirty", "--always", "--match", "v[1-9].*"], | ||
cwd=repo_path, | ||
stderr=subprocess.STDOUT, | ||
universal_newlines=True, | ||
).strip() | ||
except subprocess.CalledProcessError as er: | ||
if er.returncode == 128: | ||
# git exit code of 128 means no repository found | ||
return None | ||
git_tag = "" | ||
except OSError: | ||
return None | ||
try: | ||
git_hash = subprocess.check_output( | ||
["git", "rev-parse", "--short", "HEAD"], | ||
cwd=repo_path, | ||
stderr=subprocess.STDOUT, | ||
universal_newlines=True, | ||
).strip() | ||
except subprocess.CalledProcessError: | ||
git_hash = "unknown" | ||
except OSError: | ||
return None | ||
|
||
try: | ||
# Check if there are any modified files. | ||
subprocess.check_call( | ||
["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], | ||
cwd=repo_path, | ||
stderr=subprocess.STDOUT, | ||
) | ||
# Check if there are any staged files. | ||
subprocess.check_call( | ||
["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], | ||
cwd=repo_path, | ||
stderr=subprocess.STDOUT, | ||
) | ||
except subprocess.CalledProcessError: | ||
git_hash += "-dirty" | ||
except OSError: | ||
return None | ||
|
||
return git_tag, git_hash | ||
|
||
|
||
def make_version_header(repo_path, filename): | ||
info = None | ||
if "MICROBIT_GIT_TAG" in os.environ: | ||
info = [os.environ["MICROBIT_GIT_TAG"], os.environ["MICROBIT_GIT_HASH"]] | ||
if info is None: | ||
info = get_version_info_from_git(repo_path) | ||
|
||
git_tag, git_hash = info | ||
|
||
build_date = datetime.date.today() | ||
if "SOURCE_DATE_EPOCH" in os.environ: | ||
build_date = datetime.datetime.utcfromtimestamp( | ||
int(os.environ["SOURCE_DATE_EPOCH"]) | ||
).date() | ||
|
||
# Generate the file with the git and version info | ||
file_data = """\ | ||
// This file was generated by py/makeversionhdr.py | ||
#define MICROBIT_GIT_TAG "%s" | ||
#define MICROBIT_GIT_HASH "%s" | ||
#define MICROBIT_BUILD_DATE "%s" | ||
""" % ( | ||
git_tag, | ||
git_hash, | ||
build_date.strftime("%Y-%m-%d"), | ||
) | ||
|
||
# Check if the file contents changed from last time | ||
write_file = True | ||
if os.path.isfile(filename): | ||
with open(filename, "r") as f: | ||
existing_data = f.read() | ||
if existing_data == file_data: | ||
write_file = False | ||
|
||
# Only write the file if we need to | ||
if write_file: | ||
print("GEN %s" % filename) | ||
with open(filename, "w") as f: | ||
f.write(file_data) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-r", | ||
"--repo-path", | ||
default=os.path.join(os.path.dirname(sys.argv[0]), ".."), | ||
help="path to git repo to query for version", | ||
) | ||
parser.add_argument("dest", nargs=1, help="output file path") | ||
args = parser.parse_args() | ||
|
||
make_version_header(args.repo_path, args.dest[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.