Skip to content

Commit

Permalink
tools/build.py: Add "path" entry to index.json.
Browse files Browse the repository at this point in the history
This points to the package's base directory of the within the
micropython-lib directory structure.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Aug 20, 2024
1 parent 60d1370 commit 910af18
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

# index.json is:
# {
# "v": 1, <-- file format version
# "v": 2, <-- file format version
# "updated": <utc-seconds-since-1970>,
# "packages": {
# {
Expand All @@ -78,7 +78,9 @@
# "7": ["0.2", "0.3", "0.4"],
# ... <-- Other bytecode versions
# "py": ["0.1", "0.2", "0.3", "0.4"]
# }
# },
# // The following entries were added in file format version 2.
# path: "micropython/bluetooth/aioble",
# },
# ...
# }
Expand Down Expand Up @@ -122,7 +124,7 @@
import time


_JSON_VERSION_INDEX = 1
_JSON_VERSION_INDEX = 2
_JSON_VERSION_PACKAGE = 1


Expand Down Expand Up @@ -268,7 +270,7 @@ def _copy_as_py(

# Update to the latest metadata, and add any new versions to the package in
# the index json.
def _update_index_package_metadata(index_package_json, metadata, mpy_version):
def _update_index_package_metadata(index_package_json, metadata, mpy_version, package_path):
index_package_json["version"] = metadata.version or ""
index_package_json["author"] = "" # TODO: Make manifestfile.py capture this.
index_package_json["description"] = metadata.description or ""
Expand All @@ -283,6 +285,9 @@ def _update_index_package_metadata(index_package_json, metadata, mpy_version):
print(" New version {}={}".format(v, metadata.version))
index_package_json["versions"][v].append(metadata.version)

# The following entries were added in file format version 2.
index_package_json["path"] = package_path


def build(output_path, hash_prefix_len, mpy_cross_path):
import manifestfile
Expand Down Expand Up @@ -318,7 +323,8 @@ def build(output_path, hash_prefix_len, mpy_cross_path):

for lib_dir in lib_dirs:
for manifest_path in glob.glob(os.path.join(lib_dir, "**", "manifest.py"), recursive=True):
print("{}".format(os.path.dirname(manifest_path)))
package_path = os.path.dirname(manifest_path)
print("{}".format(package_path))
# .../foo/manifest.py -> foo
package_name = os.path.basename(os.path.dirname(manifest_path))

Expand All @@ -342,7 +348,9 @@ def build(output_path, hash_prefix_len, mpy_cross_path):
}
index_json["packages"].append(index_package_json)

_update_index_package_metadata(index_package_json, manifest.metadata(), mpy_version)
_update_index_package_metadata(
index_package_json, manifest.metadata(), mpy_version, package_path
)

# This is the package json that mip/mpremote downloads.
mpy_package_json = {
Expand Down

0 comments on commit 910af18

Please sign in to comment.