Skip to content

Commit

Permalink
Added NVC (name version cookbook) named tuple to represent specific r…
Browse files Browse the repository at this point in the history
…ecipes in a hashable format.
  • Loading branch information
val-ms committed Sep 2, 2019
1 parent c631155 commit 5a4b0b8
Show file tree
Hide file tree
Showing 31 changed files with 146 additions and 123 deletions.
184 changes: 89 additions & 95 deletions mussels/mussels.py

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions mussels/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class BaseRecipe(object):
# will change:
# v2.3.4 to nghttp2-2.3.4.
# This hack is necessary because archives with changed names will extract to their original directory name.
archive_name_change = ("", "")
archive_name_change: tuple = ("", "")

install_paths = {
install_paths: dict = {
# "x86": {
# "include" : [], # "Destination directory": ["list", "of", "source", "items"],
# "lib" : [], # Will copy source item to destination directory,
Expand All @@ -77,15 +77,15 @@ class BaseRecipe(object):
# },
}

platform = []
platform: list = []

# Dependencies on other Mussels builds.
# str format: name@version.
# "@version" is optional.
# If version is omitted, the default (highest) will be selected.
dependencies = []
dependencies: list = []

required_tools = [] # List of tools required by the build commands.
required_tools: list = [] # List of tools required by the build commands.

# build_script is a dictionary containing build scripts for each build target.
# Variables in "".format() syntax will be evaluated at build time.
Expand All @@ -96,7 +96,7 @@ class BaseRecipe(object):
# - includes: The install/{build}/include directory.
# - libs: The install/{build}/lib directory.
# - build: The build directory for a given build.
build_script = {
build_script: dict = {
# "x86": """
# """,
# "x64": """
Expand All @@ -105,7 +105,7 @@ class BaseRecipe(object):
# """,
}

builds = {} # Dictionary of build paths.
builds: dict = {} # Dictionary of build paths.

# The following will be defined during the build and exist here for convenience
# when writing build_script's using the f-string `f` prefix to help remember the
Expand Down Expand Up @@ -135,22 +135,22 @@ def __init__(self, toolchain: dict, data_dir: str = ""):
self.srcdir = os.path.join(self.data_dir, "src")
os.makedirs(self.srcdir, exist_ok=True)

self.__init_logging()
self._init_logging()

self.toolchain = toolchain

# Skip download & build steps for collections.
if self.is_collection == False:
# Download and build if necessary.
if self.__download_archive() == False:
if self._download_archive() == False:
raise (
Exception(
f"Failed to download source archive for {self.name}-{self.version}"
)
)

# Extract to the data_dir.
if self.__extract_archive() == False:
if self._extract_archive() == False:
raise (
Exception(
f"Failed to extract source archive for {self.name}-{self.version}"
Expand All @@ -162,7 +162,7 @@ def __init__(self, toolchain: dict, data_dir: str = ""):
os.path.split(os.path.abspath(module_file))[0], "patches"
)

def __init_logging(self):
def _init_logging(self):
"""
Initializes the logging parameters
"""
Expand All @@ -186,7 +186,7 @@ def __init_logging(self):

self.logger.addHandler(filehandler)

def __download_archive(self) -> bool:
def _download_archive(self) -> bool:
"""
Use the URL to download the archive if it doesn't already exist in the Downloads directory.
"""
Expand Down Expand Up @@ -224,7 +224,7 @@ def __download_archive(self) -> bool:

return True

def __extract_archive(self) -> bool:
def _extract_archive(self) -> bool:
"""
Extract the archive found in Downloads directory, if necessary.
"""
Expand Down Expand Up @@ -262,7 +262,7 @@ def __extract_archive(self) -> bool:

return True

def __install(self, build):
def _install(self, build):
"""
Copy the headers and libs to an install directory.
"""
Expand Down Expand Up @@ -306,7 +306,7 @@ def __install(self, build):
self.logger.info(f"{self.name}-{self.version} {build} install succeeded.")
return True

def __build(self) -> bool:
def _build(self) -> bool:
"""
First, patch source materials if not already patched.
Then, for each architecture, run the build commands if the output files don't already exist.
Expand All @@ -317,7 +317,7 @@ def __build(self) -> bool:
)
return True

if os.path.isdir(self.patches) == "":
if not os.path.isdir(self.patches):
self.logger.debug(f"No patch directory found.")
else:
# Patches exists for this recipe.
Expand Down Expand Up @@ -481,7 +481,7 @@ def __build(self) -> bool:
self.logger.info(f"{self.name}-{self.version} {build} build succeeded.")
os.chdir(cwd)

if self.__install(build) == False:
if self._install(build) == False:
return False

return True
1 change: 1 addition & 0 deletions mussels/recipes/Windows/bzip2/1.0.6/bzip2__1_0_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Recipe(BaseRecipe):
"lib": [os.path.join("libbz2.dll"), os.path.join("libbz2.lib")],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["visualstudio==2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/bzip2/1.0.7/bzip2__1_0_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Recipe(BaseRecipe):
"lib": [os.path.join("libbz2.dll"), os.path.join("libbz2.lib")],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["visualstudio==2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/bzip2/1.1.0/bzip2__1_1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Recipe(BaseRecipe):
"lib": [os.path.join("libbz2.dll"), os.path.join("libbz2.lib")],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["cmake", "visualstudio==2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/clamav/0.101.2/clamav__0_101_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = ["openssl"]
required_tools = ["visualstudio>=2015"]
build_script = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = [
"curl",
"json_c",
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/curl/1.2.11/curl__1_2_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = ["openssl", "nghttp2>=1.0.0", "libssh2", "zlib"]
required_tools = ["cmake", "visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/json_c/0.13.1/json_c__0_13_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["cmake", "visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/libssh2/1.8.1/libssh2__1_8_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = ["openssl>=1.1.0", "zlib"]
required_tools = ["cmake", "visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/libxml2/2.9.9/libxml2__2_9_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/nghttp2/1.36.0/nghttp2__1_36_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = ["openssl>=1.0.1", "zlib>=1.2.3"]
required_tools = ["cmake", "visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/openssl/1.1.0j/openssl__1_1_0j.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = ["zlib"]
required_tools = ["nasm", "perl", "visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/openssl/1.1.1b/openssl__1_1_1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = ["zlib"]
required_tools = ["nasm", "perl", "visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/pcre2/10.33/pcre2__10_33.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = ["bzip2", "zlib"]
required_tools = ["cmake", "visualstudio>=2017"]
build_script = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Recipe(BaseRecipe):
"lib": ["pthreadVC1.dll", "pthreadVC1.lib"],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["visualstudio>=2017"]
build_script = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Recipe(BaseRecipe):
"lib": ["pthreadVC2.dll", "pthreadVC2.lib"],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["visualstudio>=2017"]
build_script = {
Expand Down
1 change: 1 addition & 0 deletions mussels/recipes/Windows/zlib/1.2.11/zlib__1_2_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Recipe(BaseRecipe):
],
},
}
platform = ["Windows"]
dependencies = []
required_tools = ["cmake", "visualstudio>=2017"]
build_script = {
Expand Down
4 changes: 2 additions & 2 deletions mussels/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def __init__(self, data_dir: str = ""):
self.logs_dir = os.path.join(os.path.abspath(data_dir), "logs", "tools")
os.makedirs(self.logs_dir, exist_ok=True)

self.__init_logging()
self._init_logging()

def __init_logging(self):
def _init_logging(self):
"""
Initializes the logging parameters
"""
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Darwin/clang/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Tool(BaseTool):
name = "clang"
version = "10"
url = ""
platform = ["Darwin"]

path_mods = {
"usr": {"host": []},
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Darwin/cmake/cmake__3_14.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Tool(BaseTool):
name = "cmake"
version = "3.14"
url = ""
platform = ["Darwin"]

path_mods = {
"usr": {"host": []},
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Darwin/make/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Tool(BaseTool):
name = "make"
version = "3"
url = ""
platform = ["Darwin"]

path_mods = {
"usr": {"host": []},
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Darwin/meson/meson__0_51.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Tool(BaseTool):
name = "meson"
version = "0.51.0"
url = ""
platform = ["Darwin"]

path_mods = {
"system": {"host": []},
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Windows/cmake/cmake__3_14_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Tool(BaseTool):
name = "cmake"
version = "3.14.1"
url = "https://github.com/Kitware/CMake/releases/download/v3.14.1/cmake-3.14.1-win64-x64.zip"
platform = ["Windows"]

path_mods = {
"system": {
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Windows/nasm/nasm__2_14_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Tool(BaseTool):
name = "nasm"
version = "2.14.02"
url = "https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/win64/nasm-2.14.02-win64.zip"
platform = ["Windows"]

path_mods = {
"system": {
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Windows/perl/perl__5_26_3_2603.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Tool(BaseTool):
name = "perl"
version = "5.26.3.2603"
url = "https://downloads.activestate.com/ActivePerl/releases/5.26.3.2603/ActivePerl-5.26.3.2603-MSWin32-x64-a95bce075.exe"
platform = ["Windows"]

path_mods = {
"system": {
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Windows/visualstudio/visualstudio__2015.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Tool(BaseTool):
name = "visualstudio"
version = "2015"
url = ""
platform = ["Windows"]

path_mods = {
"system": {
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Windows/visualstudio/visualstudio__2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Tool(BaseTool):
name = "visualstudio"
version = "2017"
url = "https://download.visualstudio.microsoft.com/download/pr/cb4bb895-e020-49e0-8cb0-1cdeeb1bfc2f/0224f1b33e9624fd445c582b375c4076/vs_community.exe"
platform = ["Windows"]

path_mods = {
"system": {
Expand Down
1 change: 1 addition & 0 deletions mussels/tools/Windows/visualstudio/visualstudio__2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Tool(BaseTool):
name = "visualstudio"
version = "2019"
url = "https://github.com/Kitware/CMake/releases/download/v3.14.1/cmake-3.14.1-win64-x64.zip"
platform = ["Windows"]

path_mods = {
"system": {
Expand Down
9 changes: 5 additions & 4 deletions mussels/utils/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def recipes(recipe_path):
Collect all Recipes in a directory.
"""
recipes = defaultdict(dict)
platform_ = platform.system()

if not os.path.exists(recipe_path):
return recipes
Expand All @@ -37,9 +38,8 @@ def recipes(recipe_path):
[os.path.join(root, directory)]
):
_module = loader.find_module(module_name).load_module(module_name)
globals()[module_name] = _module
if "Recipe" in dir(_module):
if platform.system() in _module.Recipe.platform:
if platform_ in _module.Recipe.platform:
recipes[_module.Recipe.name][
_module.Recipe.version
] = _module.Recipe
Expand All @@ -52,6 +52,7 @@ def tools(tool_path):
Collect all Tools in a directory.
"""
tools = defaultdict(dict)
platform_ = platform.system()

if not os.path.exists(tool_path):
return tools
Expand All @@ -62,8 +63,8 @@ def tools(tool_path):
[os.path.join(root, directory)]
):
_module = loader.find_module(module_name).load_module(module_name)
globals()[module_name] = _module
if "Tool" in dir(_module):
tools[_module.Tool.name][_module.Tool.version] = _module.Tool
if platform_ in _module.Tool.platform:
tools[_module.Tool.name][_module.Tool.version] = _module.Tool

return tools
Loading

0 comments on commit 5a4b0b8

Please sign in to comment.