diff --git a/.gitignore b/.gitignore index 51d321d922..ec9d4efcc3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ .pioenvs .piolibdeps .vscode +compile_commands.json +__pycache__/ esp01-update.sh platformio_override.ini diff --git a/pio-scripts/set_repo.py b/pio-scripts/set_repo.py new file mode 100644 index 0000000000..6ef826cab1 --- /dev/null +++ b/pio-scripts/set_repo.py @@ -0,0 +1,54 @@ +Import('env') +import subprocess +import re + +def get_github_repo(): + """Extract GitHub repository name from git remote URL. + + Returns: + str: Repository name in 'owner/repo' format for GitHub repos, + 'unknown' for non-GitHub repos, missing git CLI, or any errors. + """ + try: + # Get the remote URL for origin + result = subprocess.run(['git', 'remote', 'get-url', 'origin'], + capture_output=True, text=True, check=True) + remote_url = result.stdout.strip() + + # Check if it's a GitHub URL + if 'github.com' not in remote_url.lower(): + return 'unknown' + + # Parse GitHub URL patterns: + # https://github.com/owner/repo.git + # git@github.com:owner/repo.git + # https://github.com/owner/repo + + # Remove .git suffix if present + if remote_url.endswith('.git'): + remote_url = remote_url[:-4] + + # Handle HTTPS URLs + https_match = re.search(r'github\.com/([^/]+/[^/]+)', remote_url, re.IGNORECASE) + if https_match: + return https_match.group(1) + + # Handle SSH URLs + ssh_match = re.search(r'github\.com:([^/]+/[^/]+)', remote_url, re.IGNORECASE) + if ssh_match: + return ssh_match.group(1) + + return 'unknown' + + except FileNotFoundError: + # Git CLI is not installed or not in PATH + return 'unknown' + except subprocess.CalledProcessError: + # Git command failed (e.g., not a git repo, no remote, etc.) + return 'unknown' + except Exception: + # Any other unexpected error + return 'unknown' + +repo = get_github_repo() +env.Append(BUILD_FLAGS=[f'-DWLED_REPO=\\"{repo}\\"']) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index f8d4f31d95..d1b884b083 100644 --- a/platformio.ini +++ b/platformio.ini @@ -111,6 +111,7 @@ ldscript_4m1m = eagle.flash.4m1m.ld [scripts_defaults] extra_scripts = pre:pio-scripts/set_version.py + pre:pio-scripts/set_repo.py post:pio-scripts/output_bins.py post:pio-scripts/strip-floats.py pre:pio-scripts/user_config_copy.py diff --git a/wled00/json.cpp b/wled00/json.cpp index 5f4c3cfe00..5b28750e44 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -695,6 +695,7 @@ void serializeInfo(JsonObject root) root[F("vid")] = VERSION; root[F("cn")] = F(WLED_CODENAME); root[F("release")] = releaseString; + root[F("repo")] = repoString; JsonObject leds = root.createNestedObject(F("leds")); leds[F("count")] = strip.getLengthTotal(); diff --git a/wled00/wled.h b/wled00/wled.h index 5115b65b7c..db1aab4fe0 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -276,10 +276,14 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument; #ifndef WLED_RELEASE_NAME #define WLED_RELEASE_NAME "Custom" #endif +#ifndef WLED_REPO + #define WLED_REPO "unknown" +#endif // Global Variable definitions WLED_GLOBAL char versionString[] _INIT(TOSTRING(WLED_VERSION)); WLED_GLOBAL char releaseString[] _INIT(WLED_RELEASE_NAME); // must include the quotes when defining, e.g -D WLED_RELEASE_NAME=\"ESP32_MULTI_USREMODS\" +WLED_GLOBAL char repoString[] _INIT(WLED_REPO); #define WLED_CODENAME "Niji" // AP and OTA default passwords (for maximum security change them!)