-
Notifications
You must be signed in to change notification settings - Fork 0
/
platformio.git.py
41 lines (32 loc) · 1.46 KB
/
platformio.git.py
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
# A small PlatformIO integration script (autogenerated by cargo-pio) that provides the capability to clone
# user-specified Git projects (platformio.ini git_repos = "...") before the build is triggered
#
# How to use:
# Insert/update the following line in one of platformio.ini's environments:
# extra_scripts = pre:platformio.git.py
# Specify a newline-separated list of Git repos to check out:
# git_repos = [dir-name1]@<repo1> \n [dir-name2]@<repo2>...
import os
Import("env")
class GitRepos:
def run(self, env):
self.__git_repos = env.GetProjectOption("git_repos", default = "")
self.__materialize_git_repos()
def __materialize_git_repos(self):
for (directory, repo) in self.__git_repos_list():
if not os.path.exists(env.subst(directory)):
print(f"Cloning {repo} as directory {directory}")
if env.Execute(f"git clone {repo} {directory}"):
Exit(1)
def __git_repos_list(self):
git_repos_dir = os.path.join("$PROJECT_WORKSPACE_DIR", "git-repos")
def get_repo(item):
repo = item
repo_directory = repo.split("/")[-1]
if "@" in item:
repo_directory, repo = item.split("@", 1)
return (
os.path.join(git_repos_dir, repo_directory.strip()),
repo.strip())
return [get_repo(item) for item in self.__git_repos.split("\n") if len(item.strip()) > 0]
GitRepos().run(env)