Skip to content

Commit

Permalink
Install Max package on setup
Browse files Browse the repository at this point in the history
  • Loading branch information
eliottparis committed Jun 23, 2023
1 parent ded0e9c commit 182c242
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build-system/completion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def semihosting (): return '--semihosting'
def only_gerber (): return '--only-gerber'
def with_xcode_support (): return '--with-xcode-support'
def with_vscode_support (): return '--with-vscode-support'
def with_max_support (): return '--with-max-support'

def build_simulator (): return 'simulator', ZeroOrMore ([configuration, xcode])
def build_firmware (): return 'firmware', ZeroOrMore ([configuration, semihosting])
Expand All @@ -34,9 +35,12 @@ def install_bootloader (): return 'bootloader'

def setup ():
if platform.system () == 'Darwin':
return 'setup', ZeroOrMore ([with_xcode_support, with_vscode_support])
return 'setup', ZeroOrMore ([with_xcode_support, with_vscode_support, with_max_support])
elif platform.system () == 'Windows':
return 'setup', ZeroOrMore ([with_vscode_support, with_max_support])
else:
return 'setup', ZeroOrMore ([with_vscode_support])

def init (): return 'init', ZeroOrMore ([name, language])
def configure (): return 'configure'
def build (): return 'build', [build_simulator, build_firmware, build_hardware]
Expand All @@ -52,6 +56,7 @@ def erbb_cli (): return 'erbb', commands
'setup': 'install all dependencies',
'--with-xcode-support': 'for Xcode support',
'--with-vscode-support': 'for Visual Studio Code support',
'--with-max-support': 'for Cycling\'74 Max support',
'init': 'create a new project in current directory',
'--name': 'name of project, random name if not specified',
'--language': 'the language to use, defaults to c++',
Expand Down
12 changes: 12 additions & 0 deletions build-system/scripts/erbb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def setup (args):
setup.install_toolchain_macos ()
if args.with_xcode_support:
setup.install_xcode_support ()
if args.with_max_support:
setup.install_max_package ()

elif platform.system () == 'Linux':
subprocess.check_call ('sudo apt-get update', shell=True)
Expand All @@ -183,6 +185,8 @@ def setup (args):
setup.install_msys2_mingw64 ()
setup.install_kicad_windows ()
setup.install_gnu_arm_embedded_windows ()
if args.with_max_support:
setup.install_max_package ()

else:
print ('Error: Platform %s unsupported' % platform.system ())
Expand Down Expand Up @@ -418,6 +422,14 @@ def parse_args_setup (parent):
help = 'add Visual Studio Code extra support such as erbui/erbb syntax coloring'
)

if platform.system () == 'Darwin' or platform.system () == 'Windows':
parser.add_argument(
'--with-max-support',
action = 'store_true',
help = 'add Cycling\'74 Max extra support'
)



#-- parse_args_init ----------------------------------------------------------

Expand Down
66 changes: 66 additions & 0 deletions build-system/setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@



"""
==============================================================================
Name: path_documents
==============================================================================
"""

def path_documents ():
if platform.system () == 'Windows':
# The default location of the Documents folder might be redirected on Windows.
# This situation typically arises when OneDrive is installed.

import ctypes.wintypes
CSIDL_PERSONAL = 5 # My Documents
SHGFP_TYPE_CURRENT = 0 # Current, not default value

buf = ctypes.create_unicode_buffer (ctypes.wintypes.MAX_PATH)
ctypes.windll.shell32.SHGetFolderPathW (0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, buf)
return buf.value

else:
return os.path.join (os.path.expanduser ('~'), 'Documents')



"""
==============================================================================
Name: check_environment
Expand Down Expand Up @@ -512,6 +536,48 @@ def install_python_requirements ():



"""
==============================================================================
Name: install_max_package
==============================================================================
"""

def install_max_package ():
print ('Adding Max support...')

max8_packages_path = os.path.join (path_documents (), 'Max 8', 'Packages')
src_path = os.path.join (PATH_ROOT, 'max', 'Eurorack-blocks')
dst_path = os.path.join (max8_packages_path, 'Eurorack-blocks')

def is_link (path):
try:
return os.path.islink (path) or bool (os.readlink (path))
except OSError:
return False

def create_erbb_max_package_symlink ():
if platform.system () == 'Windows':
import _winapi
_winapi.CreateJunction (src_path, dst_path)
else:
os.symlink (src_path, dst_path)

if os.path.exists (max8_packages_path) and os.path.isdir (max8_packages_path):
if os.path.exists (dst_path):
if os.path.samefile (dst_path, src_path):
pass # package already installed
elif is_link (dst_path):
os.remove (dst_path)
create_erbb_max_package_symlink ()
else:
print (f'\033[33mwarning:\033[0m"Eurorack-blocks" file in max packages already exist.\nPlease remove "{dst_path}" and run `erbb setup --with-max-support` again.')
else:
create_erbb_max_package_symlink ()
else:
print (f"\033[33mwarning:\033[0m Can't find Max packages folder {max8_packages_path}.\nPlease make sure Max is properly installed and run `erbb setup --with-max-support` again.")



"""
==============================================================================
Name: optimize_kicad_pcb_sch_read
Expand Down

0 comments on commit 182c242

Please sign in to comment.