diff --git a/tools python/deploy_skeleton.py b/tools python/deploy_skeleton.py new file mode 100644 index 0000000..a455c42 --- /dev/null +++ b/tools python/deploy_skeleton.py @@ -0,0 +1,182 @@ +import getopt +import sys +import os +import subprocess +import platform +import shutil +from turtle import clone, update +import git +from git import Repo +import adr_func + + + +use_adr=0 +use_pottery=0 +copy_license=0 +use_git=1 +use_submodules=1 +replace_name = None +check_dir="c:/subprojects" + + +def help(): + print("Usage: deploy_skeleton.sh [optional ags] dest_dir ") + print("Optional args:") + print("-a: initialize destination to use adr-tools") + print(" -p: initialize destination to use pottery") + print("-l: copy the license file") + print("-r : Replace template project/app name values with specified name") + print("-g: Assume non-git environment. Installs submodule files directly.") + print("-s: Don't use submodules, and copy files directly") + print("-k : Check directory ") + exit () + +if (platform.release() == "Darwin"): + sed="sed -i ''" +else: + sed="sed -i" + +try : + opts, args = getopt.getopt(sys.argv[1:], "aplghsrk:") +except: + print("Error !") + help() +for o , a in opts: + if o == "-a" : + use_adr = 1 + elif o == "-p": + use_pottery=1 + elif o == "-l": + copy_license=1 + elif o == "-g": + use_git=0 + use_submodules=0 + elif o =="-r": + replace_name=args[0] + elif o == "-k": + check_dir=input("CHECK_DIRECTORY : ") + elif o =="-h": + help() + + else : + print(f"Invalid option {args[0]}") + help() + + + +pwd=os.getcwd() +check_path_1= os.path.exists(f"{check_dir}/Tools") +if(check_path_1==False): + check_dir=os.chdir(f"{check_dir}") + check_path_1= os.path.exists(f"{check_dir}") + if(check_path_1==False): + print("This script must be run from the project skeleton root or the tools/ directory.") + exit () + + +dest_dir=args[0] +dest_path_2= os.path.exists(f"{dest_dir}") +if(dest_path_2==False): + dest_path_2= os.path.exists(f"{pwd}/{dest_dir}") + if(dest_path_2==False): + dest_dir=f"{pwd}/{dest_dir}" + else: + print(f"Destination directory {dest_dir} cannot be found. Does it exist?") + exit() + + +# Remove .DS_Store files + + +findCMD = f'find . -name ".DS_Store"' +out = subprocess.Popen(findCMD,shell=True,stdin=subprocess.PIPE + ,stdout=subprocess.PIPE,stderr=subprocess.PIPE) +for file in os.listdir("c:"): + if file.endswith(".DS_Store"): + shutil.rmtree(file) + + +core_files="docs src test tools .clang-format .clang-tidy Makefile meson.build meson_options.txt README.md" +git_files=".gitattributes .github .gitignore" + + +submodule_dirs="build" +submodule_urls="git@github.com:embeddedartistry/meson-buildsystem.git" + +# Copy skeleton files to the destination + +shutil.copytree(core_files,dest_dir) +path = os.path.join(dest_dir, f"{check_dir}") +os.mkdir(path) +shutil.copytree("subprojects/*.wrap",f"{dest_dir}/subprojects" ) +shutil.rmtree(f"{dest_dir}/tools/deploy_skeleton.py") +shutil.rmtree(f"{dest_dir}/tools/download_and_deploy.py") +if (use_git == 1): + shutil.copytree(git_files,dest_dir) +if (use_submodules==0): + repo = git.Repo(pwd) + output = repo.git.submodule('update','--init','--recursive') + shutil.copytree(submodule_dirs,dest_dir) +if (copy_license == 1): + shutil.copytree("LICENSE",dest_dir) + +## The following operations all take place in the destination directory + +os.chdir(dest_dir) + +# Initialize Submodules + +if (use_submodules==1): + repo = git.Repo(submodule_urls) + output = repo.git.submodule('add') + index=Repo.init(submodule_dirs).index + index.commit("Add submodules from project skeleton. ") +else : + findCMD = f'find {submodule_dirs} -name ".git*"' + out = subprocess.Popen(findCMD,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + for file in os.listdir(submodule_dirs): + if file.endswith(".git*"): + shutil.rmtree(submodule_dirs) +if (use_git==1): + repo.git.add(all=True ) + + index=Repo.init(submodule_dirs).index + index.commit("Initial commit of project skeleton files.") + +if (replace_name !=""): + subprocess.Popen(f"{sed} ",f's/PROJECT_NAME/{replace_name}/g "meson.build"') + replace_name=f"{replace_name}// /_" + subprocess.Popen(f"{sed} ",f's/PROJECT_NAME/{replace_name}/g "src/app/meson.build"') + subprocess.Popen(f"{sed} ",f's/PROJECT_NAME/{replace_name}/g "test/meson.build"') + + if(use_git==1): + index=Repo.init(submodule_dirs).index + index.commit(f"Replace placeholder values in build files with {replace_name} ") + +if(use_adr==1): + adr_func.adr_init('/docs') + if use_git==1: + repo.git.add(all=True ) + index=Repo.init(submodule_dirs).index + index.commit("Initiaize adr-tools") + +if(use_git==1): + try: + repo.git.pull("adham") + repo.git.push("adham") + except: + print("WARNING: git push failed: check repository.") + +if(replace_name ==""): + print("NOTE: Replace the placeholder project name in meson.build") + print("NOTE: Replace the placeholder application name in src/app/meson.build") + print("NOTE: Replace the placeholder test application name in test/meson.build") + +variable_1=os.path.isfile(f"{dest_dir}/LICENSE") +variable_2=os.path.isfile(f"{dest_dir}/LICENSE.md") + +if ( (copy_license==0 and variable_1==False) or variable_2==False): + print("NOTE: Your project does not have a LICENSE or LICENSE.md file in the project root.") + + diff --git a/tools python/download_and_deploy.py b/tools python/download_and_deploy.py new file mode 100644 index 0000000..fdf5120 --- /dev/null +++ b/tools python/download_and_deploy.py @@ -0,0 +1,38 @@ +import os +import git +import shutil +import platform + + +pwd=os.getcwd() +initial_dir=pwd + +linux_dir="\tmp" +windows_dir="C://tmp" +if (platform.system() == "Darwin" or platform.system() == "Linux" ): + temporary_dir=linux_dir + os.mkdir(temporary_dir) + os.chdir(temporary_dir) + git.Git().clone("https://github.com/embeddedartistry/project-skeleton","project-skeleton",depth=1,recursive=True) + os.chdir(f"{temporary_dir}\project-skeleton\tools") + exec(open('deploy_skeleton.py').read()) + os.chdir(temporary_dir) + shutil.rmtree(f"{temporary_dir}\project-skeleton") + os.chdir(f"{initial_dir}") + +else: + temporary_dir=windows_dir + os.mkdir(temporary_dir) + os.chdir(temporary_dir) + git.Git().clone("https://github.com/embeddedartistry/project-skeleton","project-skeleton",depth=1,recursive=True) + os.chdir(f"{temporary_dir}/project-skeleton/tools") + exec(open('deploy_skeleton.py').read()) + os.chdir(temporary_dir) + shutil.rmtree(f"{temporary_dir}/project-skeleton") + os.chdir(f"{initial_dir}") + + + + + + diff --git a/tools python/download_and_deploy_config_files.py b/tools python/download_and_deploy_config_files.py new file mode 100644 index 0000000..1b57a95 --- /dev/null +++ b/tools python/download_and_deploy_config_files.py @@ -0,0 +1,35 @@ +import os +import git +import shutil +import platform + +pwd=os.getcwd() +initial_dir=pwd +linux_dir="/tmp" +windows_dir="C:\\tmp" +if (platform.system() == "Darwin" or platform.system() == "Linux" ): + + temporary_dir=linux_dir + os.mkdir(temporary_dir) + os.chdir(temporary_dir) + git.Git().clone("https://github.com/embeddedartistry/config-files","config-files",depth=1) + os.chdir(f"{temporary_dir}\config-files") + exec(open('copy_config.sh').read()) + os.chdir(temporary_dir) + shutil.rmtree(f"{temporary_dir}\config-files") + os.chdir(f"{initial_dir}") + +else : + temporary_dir=windows_dir + os.mkdir(temporary_dir) + os.chdir(temporary_dir) + git.Git().clone("https://github.com/embeddedartistry/config-files","config-files",depth=1) + os.chdir(f"{temporary_dir}\\config-files") + exec(open('copy_config.sh').read()) + os.chdir(temporary_dir) + shutil.rmtree(f"{temporary_dir}\\config-files") + os.chdir(f"{initial_dir}") + + + + diff --git a/tools python/install_arm.py b/tools python/install_arm.py new file mode 100644 index 0000000..35674fd --- /dev/null +++ b/tools python/install_arm.py @@ -0,0 +1,74 @@ +import os +import platform +import os.path +import wget +import shutil +import tarfile +import sys + + +# pwd +pwd=os.getcwd() +STARTING_DIR=pwd +# taking arguments from the client +args=sys.argv[1:] +if (args[0]==None): + TOOLCHAIN_INSTALL_DIR = "/usr/local/toolchains " +else : + TOOLCHAIN_INSTALL_DIR = args[0] +#TOOLCHAIN_INSTALL_DIR=input(" Please inssert TOOLCHAIN_INSTALL_DIR :") +if(args[1]==None): + TOOLCHAIN_DISABLE_SUDO = 0 +else : + TOOLCHAIN_DISABLE_SUDO = args[1] + +TOOLCHAIN_SUDO="sudo" + +if (TOOLCHAIN_DISABLE_SUDO==1): + TOOLCHAIN_SUDO = None +OSX_ARM_URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2" +LINUX_ARM_URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2" + +if (platform.release() == "Darwin"): + ARM_URL = OSX_ARM_URL + ARM_DIR=os.path.basename(f"{ARM_URL}"+"-mac.tar.bz2") +else: + ARM_URL=LINUX_ARM_URL + ARM_DIR=os.path.basename(f"{ARM_URL}"+"-aarch64-linux.tar.bz2") + +ARM_ARCHIVE=os.path.basename(f"{ARM_URL}") + + +################################### +# Download and install dependency # +################################### + +os.chdir('c:\\tmp') +wget.download(ARM_URL,'c:\\tmp') +os.makedirs(TOOLCHAIN_INSTALL_DIR,exist_ok=True) +# Move current toolchain if it exists +if (os.path.exists(f'{TOOLCHAIN_INSTALL_DIR}/gcc-arm-none-eabi')==True): + os.system("sudo su-") + shutil.rmtree(f"{TOOLCHAIN_INSTALL_DIR}/gcc-arm-none-eabi") + shutil.move(f'{TOOLCHAIN_INSTALL_DIR}/gcc-arm-none-eabi',f'{TOOLCHAIN_INSTALL_DIR}/gcc-arm-none-eabi-bak') +tar=tarfile.open(f"{ARM_ARCHIVE}") +os.chdir(f"{TOOLCHAIN_INSTALL_DIR}") +a=os.getcwd() +tar.extractall(a) # specify which folder to extract to + +tar.close() +shutil.move(f'{TOOLCHAIN_INSTALL_DIR}/{ARM_DIR}',f'{TOOLCHAIN_INSTALL_DIR}/gcc-arm-none-eabi') +os.remove(f"{ARM_ARCHIVE}") +os.chdir(f"{STARTING_DIR}") + + + + + + + + + + + + diff --git a/tools python/install_deps.py b/tools python/install_deps.py new file mode 100644 index 0000000..0ca5025 --- /dev/null +++ b/tools python/install_deps.py @@ -0,0 +1,126 @@ + +import os +from reprlib import recursive_repr +import sys +import getopt +import platform +import subprocess +import requests +import wget +import shutil +import git + +pwd=os.getcwd() +starting_dir=pwd +toolchain_install_dir="/usr/local/toolchains" +tool_install_dir="/usr/local/tools" +toolchain_disable_sudo=0 +tool_disable_sudo=0 + + +#commands : +update=0 +update_env=0 +pip_update=None +brew_command="install" +apt_command="install" +tools_sudo="Sudo" + +brew_package=["python3" ,"ninja" ,"wget" ,"gcc@7" ,"gcc@8" ,"gcc@9" ,"llvm" ,"adr-tools" ,"cmocka" ,"pkg-config"] +brew_package.append["vale","doxygen","cppcheck","clang-format","gcovr","lcov","sloccount"] +apt_package=["python3" ,"python3-pip", "ninja-build", "wget" ,"build-essential", "clang" ,"lld" ,"llvm"] +apt_package.append=["clang-tools", "libcmocka0" ,"libcmocka-dev" ,"pkg-config" ,"sloccount" ,"curl"] +apt_package.append=["doxygen", "cppcheck", "gcovr" ,"lcov" ,"clang-format" ,"clang-tidy", "clang-tools"] +apt_package.append=["gcc-7" ,"g++-7", "gcc-8" ,"g++-8", "gcc-9" ,"g++-9"] +pip3_package=["meson" ,"lizard" ,"thefuck"] +try : + opts, args = getopt.getopt(sys.argv[1:], "euhdst") +except: + print("Error in the getopts function") +for o , a in opts : + if o=="-d": + toolchain_install_dir=input("TOOLCHAIN_INSTALL_DIR : ") + elif o == "-s": + tool_install_dir=input("TOOL_INSTALL_DIR :") + elif o =="-r": + toolchain_disable_sudo=input("TOOLCHAIN_DISABLE_SUDO :") + elif o =="-z": + tool_disable_sudo=input("TOOL_DISABLE_SUDO :") + elif o == "-e": + update_env=1 + elif o == "-u": + update=1 + pip_update="--upgrade" + brew_command="upgrade" + apt_command="upgrade" + + elif o =="-h": + print("Usage: install_deps.sh [optional ags]") + print("Optional args:") + print("-u: Run an update instead of install") + print(" -e: Include environment setup during install process (.bashrc + .bash_profile)") + exit() + + else: + print(f"Invalid option {args[0]}") + + +if (platform.system() == "Darwin"): + if(update==1): + os.system("brew update") + else: + print("installing the Homebrew ...") + r = requests.get('https://raw.githubusercontent.com/Homebrew/install/master/install.sh') + r.status_code + os.system("brew tap homebrew/cask-versions") + + subprocess.Popen(['brew',brew_command,brew_package],shell=True) + subprocess.Popen(['pip3','install',pip3_package,pip_update],shell=True) +else: + os.system(f"{tools_sudo} apt-get update ") + subprocess.Popen([tools_sudo, "apt",apt_command,"-y",apt_package],shell=True) + subprocess.Popen([tools_sudo,"-H","pip3","install",pip3_package,pip_update]) + + # Install Vale : + + if(platform.system()=="Darwnin" or platform.system()=="Linux" ): + os.chdir("/tmp") + wget.download("https://install.goreleaser.com/github.com/ValeLint/vale.sh",'\tmp') + subprocess.Popen([tools_sudo,"sh","vale.sh","-b","/usr/local/bin"]) + os.remove("vale.sh") + if(update==1): + os.chdir(f"{tool_install_dir}/adr-tools") + repo=git.Repo("/tmp") + repo.git.pull("adham") + else : + os.mkdir(tool_install_dir) + os.chdir(tool_disable_sudo) + git.Git().clone(" https://github.com/npryce/pottery.git",recursive_repr=True) + +############################# +# Install Environment Files # +############################# + +if(update==0): + if(update_env==1): + os.chdir(starting_dir) + + + + + + + + + + + + + + + + + + + + diff --git a/tools python/setup_env.py b/tools python/setup_env.py new file mode 100644 index 0000000..95ddb1f --- /dev/null +++ b/tools python/setup_env.py @@ -0,0 +1,115 @@ +import getopt +import sys +import platform +import os +import wget +import shutil +import git + +TOOLCHAIN_INSTALL_DIR="/usr/local/toolchains" +TOOL_INSTALL_DIR="/usr/local/tools" + +def helpfunction(): + print("Usage: setup_env.py [optional ags] dest_dir ") + print("Optional args:") + print("-a: initialize the toolchain install directory") + print(" -p: initialize TOOL install directory ") + print("-r: give the path ") + print("-s: initialize home directory") + exit() +try : + opts, args = getopt.getopt(sys.argv[1:], "aprs:") +except: + print("An Error has occured !") + helpfunction() +for o , a in opts: + if o == "-a" : + TOOLCHAIN_INSTALL_DIR = input("TOOLCHAIN_INSTALL_DIR :") + elif o == "-p": + TOOL_INSTALL_DIR=input("TOOL_INSTALL_DIR :") + elif o == "-r": + PATH=input("PATH :") + elif o == "-s": + HOME=input("Give Home Directory :") + else : + print("An Error has occured ! ") + helpfunction() + + + +DEPLOY_URL="https://gist.githubusercontent.com/phillipjohnston/bb95f19d156007f99be4c10c1efdf694/raw/f2f141e31fca0a12eb391e8251efe2ce1f9e68bd/download_and_deploy.sh" +if(platform.system()=="Darwin"): + file=open('.bash_profile','a') + file.write("if [ -f \$HOME/.bashrc ]; then") + file.write(" source \$HOME/.bashrc") + file.write("fi") + file.close() + + +PATHMOD=f"{TOOLCHAIN_INSTALL_DIR}/gcc-arm-none-eabi/bin:{TOOL_INSTALL_DIR}/pottery/src" +if (platform.system()=="Darwin"): + PATHMOD=f"{PATHMOD}:/usr/local/opt/llvm/bin" +else: + PATHMOD=f"{PATHMOD}:{TOOL_INSTALL_DIR}:adr-tools/src" + + +file2=open(".bashrc","a") +file2.write("################") +file2.write("# Path Updates #") +file2.write("################") +file2.write("export PATH=${PATHMOD}:\$PATH") +file2.write("# set PATH so it includes user's private bin if it exists") +file2.write("if [ -d \$HOME/bin ] ; then") +file2.write(" PATH=\$HOME/bin:\$PATH") +file2.write("fi") +file2.write("") +file2.write("#########################") +file2.write("# Aliases and Functions #") +file2.write("#########################") +file2.write("function deploy_skeleton()") +file2.write("{") +file2.write(" INITIAL_DIR=\$(pwd)") +file2.write(" cd /tmp") +file2.write(" wget $DEPLOY_URL") +file2.write(" bash download_and_deploy.sh \$@") +file2.write(" rm download_and_deploy.sh") +file2.write(" cd \$INITIAL_DIR") +file2.write("}") +file2.write("alias init_skeleton='deploy_skeleton -a -p `pwd`'") +file2.write("function init_repo()") +file2.write("{") +file2.write(" URL=\$1") +file2.write(" shift") +file2.write(" git clone \$URL") +file2.write('" cd \$(basename "\$URL" .git)"') +file2.write(" deploy_skeleton -a -p \${@} `pwd`") +file2.write(" deploy_skeleton -a -p \${@} `pwd`") +file2.write("}") +file2.write("") +file2.write('alias sm_update_build="cd build; git checkout master; git pull; cd ../"') +file2.write('alias sm_update_commit_build="sm_update_build; git add build; git commit -m "Update build submodule to use the latest changes."') + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/download_and_deploy_config_files.sh b/tools/download_and_deploy_config_files.sh index 4a4815f..f341b25 100755 --- a/tools/download_and_deploy_config_files.sh +++ b/tools/download_and_deploy_config_files.sh @@ -8,4 +8,4 @@ bash copy_config.sh ls copy_config.sh cd ../ rm -rf config-files -cd $INITIAL_DIR +cd $INITIAL_DIR diff --git a/tools/install_arm_gcc.sh b/tools/install_arm_gcc.sh index 11c1e3c..364c753 100755 --- a/tools/install_arm_gcc.sh +++ b/tools/install_arm_gcc.sh @@ -9,7 +9,7 @@ TOOLCHAIN_INSTALL_DIR=${TOOLCHAIN_INSTALL_DIR:-/usr/local/toolchains} TOOLCHAIN_DISABLE_SUDO=${TOOLCHAIN_DISABLE_SUDO:-0} TOOLCHAIN_SUDO=sudo -if [ $TOOLCHAIN_DISABLE_SUDO == 1 ]; then +if [ $TOOLCHAIN_DISABLE_SUDO == 1 ]; then TOOLCHAIN_SUDO= fi