-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathmanifest_update.py
More file actions
62 lines (49 loc) · 2.75 KB
/
manifest_update.py
File metadata and controls
62 lines (49 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# This script is used to replace a package from the project manifest.json with a local version.
# The goal is that you will trigger the build process from your branch (for example release/1.2.3) and package from this branch will be use in the project manifest.1
# Note that for now this script is assuming that such package already has an entry in the manifest
# TODO: consider if it makes sense to just add new manifest entry (to test what?)
import json
import argparse
import os
def parse_args():
global args
parser = argparse.ArgumentParser(description='Update a Unity project manifest to point to the local package version.')
parser.add_argument('--manifest-path', required=True, help='The absolute path to the project manifest.json file.')
parser.add_argument('--package-name', default="com.unity.netcode.gameobjects", help="The name of the package to modify in the manifest.")
parser.add_argument('--local-package-path', required=True, help='The absolute file path to the local package source directory.')
args = parser.parse_args()
def main():
"""
Updates a project's manifest.json to use package under passed local-package-path,
and then prints the version of that local package.
"""
parse_args()
# Update the target project's manifest
try:
with open(args.manifest_path, 'r') as f:
manifest_data = json.load(f)
local_path_normalized = args.local_package_path.replace(os.sep, '/')
manifest_data["dependencies"][args.package_name] = f"file:{local_path_normalized}"
with open(args.manifest_path, 'w', encoding='UTF-8', newline='\n') as f:
json.dump(manifest_data, f, indent=4)
print(f"Successfully updated manifest at '{args.manifest_path}'")
print(f"Set '{args.package_name}' to use local package at '{args.local_package_path}'")
except Exception as e:
print(f"Error updating manifest: {e}")
exit(1)
# --- Read and report the local package's version for log confirmation---
# This is only for debug purposes
try:
# Construct the path to the local package's package.json file
local_package_json_path = os.path.join(args.local_package_path, 'package.json')
with open(local_package_json_path, 'r') as f:
local_package_data = json.load(f)
# Extract the version, providing a default if not found
local_package_version = local_package_data.get('version', 'N/A')
print(f"--> Verified local '{args.package-name}' version is: {local_package_version}")
except FileNotFoundError:
print(f"Warning: Could not find package.json at '{local_package_json_path}'")
except Exception as e:
print(f"Error reading local package version: {e}")
if __name__ == "__main__":
main()