forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-fork-nugets.sh
More file actions
executable file
·172 lines (144 loc) · 6.17 KB
/
build-fork-nugets.sh
File metadata and controls
executable file
·172 lines (144 loc) · 6.17 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BASE_VERSION=$(sed -n 's/.*<Version>\(.*\)<\/Version>.*/\1/p' "$SCRIPT_DIR/build/SharedVersion.props")
FORK_VERSION="${1:-11.9.1}"
CONFIGURATION="${2:-Release}"
OUTPUT_DIR="$SCRIPT_DIR/forked_nugets"
echo "============================================"
echo " Base version: $BASE_VERSION"
echo " Fork version: $FORK_VERSION"
echo " Output: $OUTPUT_DIR"
echo "============================================"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
# Pack order: OpenGL/Skia first (no fork-to-fork deps), then Android/iOS
PROJECTS=(
"src/Avalonia.OpenGL/Avalonia.OpenGL.csproj"
"src/Skia/Avalonia.Skia/Avalonia.Skia.csproj"
"src/Android/Avalonia.Android/Avalonia.Android.csproj"
"src/iOS/Avalonia.iOS/Avalonia.iOS.csproj"
)
for proj in "${PROJECTS[@]}"; do
echo ">> Packing $proj ..."
dotnet pack "$SCRIPT_DIR/$proj" \
-c "$CONFIGURATION" \
-p:ForkVersion="$FORK_VERSION" \
-o "$OUTPUT_DIR"
echo ""
done
# Post-process nuspecs to match official nuget.org package structure.
#
# The official Avalonia build uses Numerge to merge sub-packages into the
# Avalonia meta-package. These sub-packages don't exist on nuget.org:
# Avalonia.Base, Avalonia.Controls, Avalonia.DesignerSupport, Avalonia.OpenGL,
# Avalonia.Metal, Avalonia.Vulkan, Avalonia.Dialogs, Avalonia.Markup,
# Avalonia.Markup.Xaml, Avalonia.MicroCom
#
# Our dotnet pack creates deps on these non-existent packages. We fix this by:
# 1. Removing deps on merged/bundled packages
# 2. Ensuring a dep on Avalonia >= base_version exists (it provides those DLLs)
# 3. Pinning Avalonia dep to base_version (not fork_version)
echo ">> Post-processing nupkgs..."
python3 - "$OUTPUT_DIR" "$BASE_VERSION" "$FORK_VERSION" <<'PYEOF'
import sys, os, zipfile, tempfile
import xml.etree.ElementTree as ET
output_dir = sys.argv[1]
base_version = sys.argv[2]
fork_version = sys.argv[3]
# Packages bundled inside the Avalonia meta-package (don't exist on nuget.org)
MERGED = {
"Avalonia.Base", "Avalonia.Controls", "Avalonia.DesignerSupport",
"Avalonia.OpenGL", "Avalonia.Metal", "Avalonia.Vulkan",
"Avalonia.Dialogs", "Avalonia.Markup", "Avalonia.Markup.Xaml",
"Avalonia.MicroCom"
}
# Our forked packages (keep deps on these at fork_version)
FORKED = {"Avalonia.Skia", "Avalonia.OpenGL", "Avalonia.Android", "Avalonia.iOS"}
NS_URIS = [
"http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd",
"http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd",
"http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd",
]
def find_ns(root):
for uri in NS_URIS:
if root.find(f"{{{uri}}}metadata") is not None:
return uri
return ""
for fname in sorted(os.listdir(output_dir)):
if not fname.endswith(".nupkg"):
continue
nupkg_path = os.path.join(output_dir, fname)
with tempfile.TemporaryDirectory() as tmpdir:
with zipfile.ZipFile(nupkg_path, 'r') as z:
z.extractall(tmpdir)
nuspec_files = [f for f in os.listdir(tmpdir) if f.endswith(".nuspec")]
if not nuspec_files:
continue
nuspec_path = os.path.join(tmpdir, nuspec_files[0])
tree = ET.parse(nuspec_path)
root = tree.getroot()
ns = find_ns(root)
if not ns:
continue
ET.register_namespace("", ns)
metadata = root.find(f"{{{ns}}}metadata")
pkg_id = metadata.find(f"{{{ns}}}id").text
modified = False
deps_el = metadata.find(f"{{{ns}}}dependencies")
if deps_el is None:
continue
for group in deps_el.findall(f"{{{ns}}}group"):
to_remove = []
has_avalonia_dep = False
needs_avalonia_dep = False
for dep in group.findall(f"{{{ns}}}dependency"):
dep_id = dep.get("id")
dep_ver = dep.get("version", "")
if dep_id == "Avalonia":
has_avalonia_dep = True
# Pin to base version (official meta-package on nuget.org)
if dep_ver == fork_version:
dep.set("version", base_version)
modified = True
print(f" {pkg_id}: Avalonia dep {fork_version} -> {base_version}")
elif dep_id in MERGED:
# Remove deps on packages bundled in the Avalonia meta-package
to_remove.append(dep)
needs_avalonia_dep = True
elif dep_id in FORKED:
# Keep fork deps at fork version (already correct)
pass
# All other deps (SkiaSharp, Xamarin, etc.) stay unchanged
for dep in to_remove:
group.remove(dep)
modified = True
print(f" {pkg_id}: removed dep on {dep.get('id')}")
# If we removed merged deps, ensure Avalonia dep exists
if needs_avalonia_dep and not has_avalonia_dep:
new_dep = ET.SubElement(group, f"{{{ns}}}dependency")
new_dep.set("id", "Avalonia")
new_dep.set("version", base_version)
new_dep.set("exclude", "Build,Analyzers")
modified = True
print(f" {pkg_id}: added dep on Avalonia {base_version}")
if modified:
tree.write(nuspec_path, xml_declaration=True, encoding="utf-8")
os.remove(nupkg_path)
with zipfile.ZipFile(nupkg_path, 'w', zipfile.ZIP_DEFLATED) as zout:
for dirpath, dirnames, filenames in os.walk(tmpdir):
for fn in filenames:
full = os.path.join(dirpath, fn)
arcname = os.path.relpath(full, tmpdir)
zout.write(full, arcname)
print(f" {pkg_id}: repackaged OK")
PYEOF
echo ""
echo "============================================"
echo " Done! Packages:"
echo "============================================"
ls -1 "$OUTPUT_DIR"/*.nupkg 2>/dev/null
echo ""
echo "Copy to your local feed and clean stale cache:"
echo " cp $OUTPUT_DIR/*.nupkg /opt/dev/local_nugets/"
echo " rm -rf ~/.nuget/packages/avalonia*/11.9.1"