Compare commits
16 commits
tannewt-pa
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4672763fab | ||
|
|
a292909c21 | ||
|
|
06c4237c08 | ||
|
|
bab005fb54 | ||
|
|
2c982ad536 | ||
|
|
181368b0e4 | ||
|
|
381253f2ae | ||
|
|
8ccfa837a3 | ||
|
|
b014d651cd | ||
|
|
0fe0ed6353 | ||
|
|
e5da2baed3 | ||
|
|
283d8286bd | ||
|
|
318fa70652 | ||
|
|
b803b26f4a | ||
|
|
83ecd9525a | ||
|
|
ffcbdc598c |
4 changed files with 62 additions and 70 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# Adafruit CircuitPython Build Tools
|
# Adafruit CircuitPython Build Tools
|
||||||
|
|
||||||
[](https://discord.gg/nBQh6qu)
|
[](https://adafru.it/discord)
|
||||||
|
|
||||||
This repo contains build scripts used to build the
|
This repo contains build scripts used to build the
|
||||||
[Adafruit CircuitPython bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle), [CircuitPython Community bundle](https://github.com/adafruit/CircuitPython_Community_Bundle)
|
[Adafruit CircuitPython bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle), [CircuitPython Community bundle](https://github.com/adafruit/CircuitPython_Community_Bundle)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# The MIT License (MIT)
|
# The MIT License (MIT)
|
||||||
#
|
#
|
||||||
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
||||||
|
# 2018, 2019 Michael Schroeder
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
@ -24,6 +25,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import pathlib
|
||||||
import semver
|
import semver
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -31,6 +33,7 @@ import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
IGNORE_PY = ["setup.py", "conf.py", "__init__.py"]
|
IGNORE_PY = ["setup.py", "conf.py", "__init__.py"]
|
||||||
|
GLOB_PATTERNS = ["*.py", "font5x8.bin"]
|
||||||
|
|
||||||
def version_string(path=None, *, valid_semver=False):
|
def version_string(path=None, *, valid_semver=False):
|
||||||
version = None
|
version = None
|
||||||
|
|
@ -106,71 +109,46 @@ def library(library_path, output_directory, package_folder_prefix,
|
||||||
package_files = []
|
package_files = []
|
||||||
example_files = []
|
example_files = []
|
||||||
total_size = 512
|
total_size = 512
|
||||||
for filename in os.listdir(library_path):
|
|
||||||
full_path = os.path.join(library_path, filename)
|
|
||||||
if os.path.isdir(full_path):
|
|
||||||
path_walk = [names for names in os.walk(full_path)]
|
|
||||||
#print("- '{}' walk: {}".format(filename, path_walk))
|
|
||||||
|
|
||||||
# iterate through path_walk, appending each file to
|
lib_path = pathlib.Path(library_path)
|
||||||
# 'walked_files' while retaining subdirectory structure
|
parent_idx = len(lib_path.parts)
|
||||||
walked_files = []
|
glob_search = []
|
||||||
for path in path_walk:
|
for pattern in GLOB_PATTERNS:
|
||||||
rel_path = ""
|
glob_search.extend(list(lib_path.rglob(pattern)))
|
||||||
if filename.startswith("examples"):
|
|
||||||
path_tail_idx = path[0].rfind("examples/")
|
|
||||||
if path_tail_idx != -1:
|
|
||||||
rel_path = "{}/".format(path[0][path_tail_idx + 9:])
|
|
||||||
|
|
||||||
|
for file in glob_search:
|
||||||
|
if file.parts[parent_idx] == "examples":
|
||||||
|
example_files.append(file)
|
||||||
|
else:
|
||||||
|
if not example_bundle:
|
||||||
|
is_package = False
|
||||||
|
for prefix in package_folder_prefix:
|
||||||
|
if file.parts[parent_idx].startswith(prefix):
|
||||||
|
is_package = True
|
||||||
|
|
||||||
|
if is_package:
|
||||||
|
package_files.append(file)
|
||||||
else:
|
else:
|
||||||
path_tail_idx = (path[0].rfind("{}/".format(filename))
|
if file.name in IGNORE_PY:
|
||||||
+ (len(filename) +1))
|
#print("Ignoring:", file.resolve())
|
||||||
path_tail = path[0][path_tail_idx:]
|
|
||||||
|
|
||||||
# if this entry is the package top dir, keep it
|
|
||||||
# empty so we don't double append the dir name
|
|
||||||
if filename not in path_tail:
|
|
||||||
rel_path = "{}/".format(path_tail)
|
|
||||||
|
|
||||||
for path_files in path[2]:
|
|
||||||
walked_files.append("{}{}".format(rel_path, path_files))
|
|
||||||
#print(" - expanded file walk: {}".format(walked_files))
|
|
||||||
|
|
||||||
files = filter(
|
|
||||||
lambda x: x.endswith(".py") or x.startswith("font5x8.bin"),
|
|
||||||
walked_files
|
|
||||||
)
|
|
||||||
files = map(lambda x: os.path.join(filename, x), files)
|
|
||||||
|
|
||||||
if filename.startswith("examples"):
|
|
||||||
example_files.extend(files)
|
|
||||||
#print("- example files: {}".format(example_files))
|
|
||||||
else:
|
|
||||||
if (not example_bundle and
|
|
||||||
not filename.startswith(package_folder_prefix)):
|
|
||||||
print("skipped path: {}".format(full_path))
|
|
||||||
continue
|
continue
|
||||||
if not example_bundle:
|
if file.parent == lib_path:
|
||||||
package_files.extend(files)
|
py_files.append(file)
|
||||||
#print("- package files: {} | {}".format(filename, package_files))
|
|
||||||
|
|
||||||
if (filename.endswith(".py") and
|
|
||||||
filename not in IGNORE_PY and
|
|
||||||
not example_bundle):
|
|
||||||
py_files.append(filename)
|
|
||||||
|
|
||||||
if len(py_files) > 1:
|
if len(py_files) > 1:
|
||||||
raise ValueError("Multiple top level py files not allowed. Please put them in a package "
|
raise ValueError("Multiple top level py files not allowed. Please put "
|
||||||
"or combine them into a single file.")
|
"them in a package or combine them into a single file.")
|
||||||
|
|
||||||
for fn in example_files:
|
for fn in example_files:
|
||||||
base_dir = os.path.join(output_directory.replace("/lib", "/"), os.path.dirname(fn))
|
base_dir = os.path.join(output_directory.replace("/lib", "/"),
|
||||||
|
fn.relative_to(library_path).parent)
|
||||||
if not os.path.isdir(base_dir):
|
if not os.path.isdir(base_dir):
|
||||||
os.makedirs(base_dir)
|
os.makedirs(base_dir)
|
||||||
total_size += 512
|
total_size += 512
|
||||||
|
|
||||||
for fn in package_files:
|
for fn in package_files:
|
||||||
base_dir = os.path.join(output_directory, os.path.dirname(fn))
|
base_dir = os.path.join(output_directory,
|
||||||
|
fn.relative_to(library_path).parent)
|
||||||
if not os.path.isdir(base_dir):
|
if not os.path.isdir(base_dir):
|
||||||
os.makedirs(base_dir)
|
os.makedirs(base_dir)
|
||||||
total_size += 512
|
total_size += 512
|
||||||
|
|
@ -188,16 +166,20 @@ def library(library_path, output_directory, package_folder_prefix,
|
||||||
|
|
||||||
for filename in py_files:
|
for filename in py_files:
|
||||||
full_path = os.path.join(library_path, filename)
|
full_path = os.path.join(library_path, filename)
|
||||||
output_file = os.path.join(output_directory,
|
output_file = os.path.join(
|
||||||
filename.replace(".py", new_extension))
|
output_directory,
|
||||||
|
filename.relative_to(library_path).with_suffix(new_extension)
|
||||||
|
)
|
||||||
with tempfile.NamedTemporaryFile() as temp_file:
|
with tempfile.NamedTemporaryFile() as temp_file:
|
||||||
_munge_to_temp(full_path, temp_file, library_version)
|
_munge_to_temp(full_path, temp_file, library_version)
|
||||||
|
|
||||||
if mpy_cross:
|
if mpy_cross:
|
||||||
mpy_success = subprocess.call([mpy_cross,
|
mpy_success = subprocess.call([
|
||||||
"-o", output_file,
|
mpy_cross,
|
||||||
"-s", filename,
|
"-o", output_file,
|
||||||
temp_file.name])
|
"-s", str(filename.relative_to(library_path)),
|
||||||
|
temp_file.name
|
||||||
|
])
|
||||||
if mpy_success != 0:
|
if mpy_success != 0:
|
||||||
raise RuntimeError("mpy-cross failed on", full_path)
|
raise RuntimeError("mpy-cross failed on", full_path)
|
||||||
else:
|
else:
|
||||||
|
|
@ -208,21 +190,28 @@ def library(library_path, output_directory, package_folder_prefix,
|
||||||
with tempfile.NamedTemporaryFile() as temp_file:
|
with tempfile.NamedTemporaryFile() as temp_file:
|
||||||
_munge_to_temp(full_path, temp_file, library_version)
|
_munge_to_temp(full_path, temp_file, library_version)
|
||||||
if not mpy_cross or os.stat(full_path).st_size == 0:
|
if not mpy_cross or os.stat(full_path).st_size == 0:
|
||||||
output_file = os.path.join(output_directory, filename)
|
output_file = os.path.join(output_directory,
|
||||||
|
filename.relative_to(library_path))
|
||||||
shutil.copyfile(temp_file.name, output_file)
|
shutil.copyfile(temp_file.name, output_file)
|
||||||
else:
|
else:
|
||||||
output_file = os.path.join(output_directory,
|
output_file = os.path.join(
|
||||||
filename.replace(".py", new_extension))
|
output_directory,
|
||||||
mpy_success = subprocess.call([mpy_cross,
|
filename.relative_to(library_path).with_suffix(new_extension)
|
||||||
"-o", output_file,
|
)
|
||||||
"-s", filename,
|
|
||||||
temp_file.name])
|
mpy_success = subprocess.call([
|
||||||
|
mpy_cross,
|
||||||
|
"-o", output_file,
|
||||||
|
"-s", str(filename.relative_to(library_path)),
|
||||||
|
temp_file.name
|
||||||
|
])
|
||||||
if mpy_success != 0:
|
if mpy_success != 0:
|
||||||
raise RuntimeError("mpy-cross failed on", full_path)
|
raise RuntimeError("mpy-cross failed on", full_path)
|
||||||
|
|
||||||
for filename in example_files:
|
for filename in example_files:
|
||||||
full_path = os.path.join(library_path, filename)
|
full_path = os.path.join(library_path, filename)
|
||||||
output_file = os.path.join(output_directory.replace("/lib", "/"), filename)
|
output_file = os.path.join(output_directory.replace("/lib", "/"),
|
||||||
|
filename.relative_to(library_path))
|
||||||
with tempfile.NamedTemporaryFile() as temp_file:
|
with tempfile.NamedTemporaryFile() as temp_file:
|
||||||
_munge_to_temp(full_path, temp_file, library_version)
|
_munge_to_temp(full_path, temp_file, library_version)
|
||||||
shutil.copyfile(temp_file.name, output_file)
|
shutil.copyfile(temp_file.name, output_file)
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,9 @@ def build_bundle(libs, bundle_version, output_filename, package_folder_prefix,
|
||||||
for line in versions.stdout.split(b"\n"):
|
for line in versions.stdout.split(b"\n"):
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
if line.startswith(b"git@"):
|
if line.startswith(b"ssh://git@"):
|
||||||
|
repo = b"https://" + line.split(b"@")[1][:-len(".git")]
|
||||||
|
elif line.startswith(b"git@"):
|
||||||
repo = b"https://github.com/" + line.split(b":")[1][:-len(".git")]
|
repo = b"https://github.com/" + line.split(b":")[1][:-len(".git")]
|
||||||
elif line.startswith(b"https:"):
|
elif line.startswith(b"https:"):
|
||||||
repo = line.strip()[:-len(".git")]
|
repo = line.strip()[:-len(".git")]
|
||||||
|
|
@ -139,6 +141,8 @@ def _find_libraries(current_path, depth):
|
||||||
def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix):
|
def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix):
|
||||||
os.makedirs(output_directory, exist_ok=True)
|
os.makedirs(output_directory, exist_ok=True)
|
||||||
|
|
||||||
|
package_folder_prefix = package_folder_prefix.split(", ")
|
||||||
|
|
||||||
bundle_version = build.version_string()
|
bundle_version = build.version_string()
|
||||||
|
|
||||||
libs = _find_libraries(os.path.abspath(library_location), library_depth)
|
libs = _find_libraries(os.path.abspath(library_location), library_depth)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,5 @@
|
||||||
# The tag specifies which version of CircuitPython to use for mpy-cross.
|
# The tag specifies which version of CircuitPython to use for mpy-cross.
|
||||||
# The name is used when constructing the zip file names.
|
# The name is used when constructing the zip file names.
|
||||||
VERSIONS = [
|
VERSIONS = [
|
||||||
{"tag": "4.0.0-alpha.2", "name": "4.x"},
|
{"tag": "6.1.0", "name": "6.x"},
|
||||||
{"tag": "5.0.0-alpha.0", "name": "5.x"},
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue