-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfollow_nfc_examples.sh
More file actions
79 lines (69 loc) · 3.91 KB
/
Copy pathfollow_nfc_examples.sh
File metadata and controls
79 lines (69 loc) · 3.91 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
#!/bin/bash
REMOTE_NAME="nfc_examples"
REMOTE_URL="git@github.com:m5stack/M5Unit-NFC.git"
#REMOTE_BRANCH="main"
REMOTE_BRANCH="develop"
SUBDIRS=("NFCA" "NFCB" "common")
# Prevent M5Unit-NFC's tags from polluting this repo's tag namespace.
# Fetch auto-follows tags pointing to downloaded objects (git subtree's internal
# fetch too), which imported NFC's 0.0.3 / 0.1.0 etc. into refs/tags here.
# --no-tags on the remote disables tag-following for every fetch to it.
git config remote.$REMOTE_NAME.tagOpt --no-tags
echo "--- 1. Fetch nfc_examples ---"
git fetch --no-tags $REMOTE_NAME
for SUBDIR in "${SUBDIRS[@]}"; do
SRC_DIR="examples/UnitUnified/$SUBDIR" # Path(M5Unit-NFC)
DEST_DIR="examples/UnitUnified/$SUBDIR" # Path(M5Unit-RFID)
echo "--- 2. Extracting $SRC_DIR ---"
SHA=$(git subtree split --prefix=$SRC_DIR $REMOTE_NAME/$REMOTE_BRANCH)
if [ -z "$SHA" ]; then
echo "Error: Failed to extract $SUBDIR"
exit 1
fi
echo "Extracted SHA: $SHA"
if [ -d "$DEST_DIR" ]; then
echo "--- 3. Merge (pull) into $DEST_DIR ---"
git subtree pull --prefix=$DEST_DIR $REMOTE_NAME $SHA --squash
else
echo "--- 3. Add into $DEST_DIR ---"
git subtree add --prefix=$DEST_DIR $REMOTE_NAME $SHA --squash
fi
done
# --- 4. Rewrite example idf_component.yml self-reference for M5Unit-RFID ---
# NFC follow leaves a self-ref override_path to M5Unit-NFC. In this repo the
# self-component is M5Unit-RFID; M5Unit-NFC (and M5UnitUnified) are pulled in
# transitively via M5Unit-RFID's own root idf_component.yml, so we only need to
# rename the self-reference (no explicit M5Unit-NFC entry here).
# NOTE: this leaves the manifests modified in the working tree; commit them
# yourself before the next follow (subtree pull requires a clean tree).
echo "--- 4. Rewrite example idf_component.yml self-reference for M5Unit-RFID ---"
for YML in $(find examples/UnitUnified/NFCA examples/UnitUnified/NFCB -path '*/main/idf_component.yml'); do
perl -0pi -e 's{ m5stack/M5Unit-NFC:\n (override_path|path): "\.\./\.\./\.\./\.\./\.\."}{ m5stack/M5Unit-RFID:\n $1: "../../../../.."}g' "$YML"
# The comment above the dependency names the upstream repo too. Without this the manifest
# says "self reference" about M5Unit-NFC while the entry below it points at M5Unit-RFID.
perl -0pi -e 's{## - M5Unit-NFC is taken from this repository itself}{## - M5Unit-RFID is taken from this repository itself}g' "$YML"
perl -0pi -e "s{dependency of M5Unit-NFC's root idf_component\\.yml}{dependency of M5Unit-RFID's root idf_component.yml}g" "$YML"
echo " rewrote $YML"
done
# --- 5. Rewrite Kconfig for M5Unit-RFID (menu label + default variant) ---
# The shared common/ Kconfig files label the menuconfig menu "M5Unit-NFC example"
# and default to UnitNFC. In this repo we surface "M5Unit-RFID example" and default
# to UnitRFID2 where offered. Like §4 this leaves the common/ files modified in the
# working tree; commit before the next follow.
echo "--- 5. Rewrite Kconfig for M5Unit-RFID ---"
for KC in examples/UnitUnified/common/Kconfig.variant.*; do
perl -0pi -e 's{menu "M5Unit-NFC example"}{menu "M5Unit-RFID example"}g' "$KC"
echo " rewrote menu label: $KC"
done
# The header comment names the upstream repo. Rewrite it so the shared file reads as this
# repository's own; without this the Kconfig keeps saying "M5Unit-NFC" here.
for KC in examples/UnitUnified/common/Kconfig.variant.*; do
perl -0pi -e 's{for the M5Unit-NFC UnitUnified examples}{for the M5Unit-RFID UnitUnified examples}g' "$KC"
echo " rewrote header comment: $KC"
done
# Default to UnitRFID2 where it is offered (full / no_dial; basic has no RFID2 option).
for KC in examples/UnitUnified/common/Kconfig.variant.full examples/UnitUnified/common/Kconfig.variant.no_dial; do
perl -0pi -e 's{default EXAMPLE_USING_UNIT_NFC}{default EXAMPLE_USING_UNIT_RFID2}g' "$KC"
echo " rewrote default: $KC"
done
echo "--- Done ---"