mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
build-all: --num_build_procs cli arg
This commit is contained in:
+23
-7
@@ -3,6 +3,8 @@
|
|||||||
# dependencies = [
|
# dependencies = [
|
||||||
# "typing_extensions",
|
# "typing_extensions",
|
||||||
# ]
|
# ]
|
||||||
|
# [tool.ty.environment]
|
||||||
|
# root = ["."]
|
||||||
# ///
|
# ///
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# #
|
# #
|
||||||
@@ -135,12 +137,11 @@ from pathlib import Path
|
|||||||
from typing import Literal, NamedTuple, TypeAlias
|
from typing import Literal, NamedTuple, TypeAlias
|
||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
|
|
||||||
|
from common import ColorFormatter, HelpStrings, resolve_cli_or_env
|
||||||
from typing_extensions import assert_never
|
from typing_extensions import assert_never
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
# `common` configures the root logger on import, so reuse it here.
|
||||||
logger.setLevel(logging.INFO)
|
logger = logging.getLogger()
|
||||||
ch = logging.StreamHandler()
|
|
||||||
logger.addHandler(ch)
|
|
||||||
|
|
||||||
|
|
||||||
def is_on_off(value: str | None, *, default: bool) -> bool:
|
def is_on_off(value: str | None, *, default: bool) -> bool:
|
||||||
@@ -208,6 +209,7 @@ class Args(NamedTuple):
|
|||||||
occt_shared: bool
|
occt_shared: bool
|
||||||
mac_cross_compile_intel: bool
|
mac_cross_compile_intel: bool
|
||||||
wasm: bool
|
wasm: bool
|
||||||
|
num_build_procs: int
|
||||||
|
|
||||||
|
|
||||||
class DynamicArgs(NamedTuple):
|
class DynamicArgs(NamedTuple):
|
||||||
@@ -310,7 +312,20 @@ def parse_args() -> tuple[Args, DynamicArgs]:
|
|||||||
help="Cross compile for Intel Mac on Apple Silicon host.",
|
help="Cross compile for Intel Mac on Apple Silicon host.",
|
||||||
)
|
)
|
||||||
arg_parser.add_argument("-wasm", "--wasm", action="store_true", default=False, help="Compile for wasm.")
|
arg_parser.add_argument("-wasm", "--wasm", action="store_true", default=False, help="Compile for wasm.")
|
||||||
|
arg_parser.add_argument(
|
||||||
|
"--num-build-procs",
|
||||||
|
dest="num_build_procs",
|
||||||
|
type=int,
|
||||||
|
default=argparse.SUPPRESS,
|
||||||
|
help=HelpStrings.NUM_BUILD_PROCS,
|
||||||
|
)
|
||||||
namespace, unknown_flags = arg_parser.parse_known_args()
|
namespace, unknown_flags = arg_parser.parse_known_args()
|
||||||
|
num_build_procs = resolve_cli_or_env(
|
||||||
|
getattr(namespace, "num_build_procs", None),
|
||||||
|
"IFCOS_NUM_BUILD_PROCS",
|
||||||
|
multiprocessing.cpu_count() + 1,
|
||||||
|
arg_type="int",
|
||||||
|
)
|
||||||
args = Args(
|
args = Args(
|
||||||
explicit_targets=namespace.explicit_targets,
|
explicit_targets=namespace.explicit_targets,
|
||||||
build_examples=namespace.build_examples,
|
build_examples=namespace.build_examples,
|
||||||
@@ -322,6 +337,7 @@ def parse_args() -> tuple[Args, DynamicArgs]:
|
|||||||
occt_shared=namespace.occt_shared or namespace.shared,
|
occt_shared=namespace.occt_shared or namespace.shared,
|
||||||
mac_cross_compile_intel=namespace.mac_cross_compile_intel,
|
mac_cross_compile_intel=namespace.mac_cross_compile_intel,
|
||||||
wasm=namespace.wasm,
|
wasm=namespace.wasm,
|
||||||
|
num_build_procs=num_build_procs,
|
||||||
)
|
)
|
||||||
|
|
||||||
dynamic_args = DynamicArgs.from_unknown_flags(unknown_flags, arg_parser)
|
dynamic_args = DynamicArgs.from_unknown_flags(unknown_flags, arg_parser)
|
||||||
@@ -409,7 +425,7 @@ if APPLE:
|
|||||||
# /Users/runner/work/IfcOpenShell/IfcOpenShell/src/ifcparse/IfcFile.cpp:539:14: error: 'exists' is unavailable: introduced in macOS 10.15
|
# /Users/runner/work/IfcOpenShell/IfcOpenShell/src/ifcparse/IfcFile.cpp:539:14: error: 'exists' is unavailable: introduced in macOS 10.15
|
||||||
TOOLSET = "10.15"
|
TOOLSET = "10.15"
|
||||||
|
|
||||||
IFCOS_NUM_BUILD_PROCS = os.getenv("IFCOS_NUM_BUILD_PROCS", multiprocessing.cpu_count() + 1)
|
IFCOS_NUM_BUILD_PROCS = ARGS.num_build_procs
|
||||||
|
|
||||||
SCRIPT_PATH = Path(__file__).parent
|
SCRIPT_PATH = Path(__file__).parent
|
||||||
REPO_PATH = SCRIPT_PATH.parent
|
REPO_PATH = SCRIPT_PATH.parent
|
||||||
@@ -508,8 +524,8 @@ def gather_dependencies(dep: str) -> Generator[str]:
|
|||||||
|
|
||||||
if ARGS.verbose:
|
if ARGS.verbose:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
|
formatter = ColorFormatter("%(asctime)s - %(levelname)s - %(message)s")
|
||||||
ch.setFormatter(formatter)
|
logger.handlers[0].setFormatter(formatter)
|
||||||
else:
|
else:
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../win/common.py
|
||||||
+1
-1
@@ -38,7 +38,6 @@ from common import (
|
|||||||
REPO_ROOT,
|
REPO_ROOT,
|
||||||
SCRIPT_DIR,
|
SCRIPT_DIR,
|
||||||
BuildCfg,
|
BuildCfg,
|
||||||
BuildDepsCache,
|
|
||||||
BuildType,
|
BuildType,
|
||||||
C,
|
C,
|
||||||
HelpStrings,
|
HelpStrings,
|
||||||
@@ -49,6 +48,7 @@ from common import (
|
|||||||
resolve_cli_or_env,
|
resolve_cli_or_env,
|
||||||
validate_cmake_version,
|
validate_cmake_version,
|
||||||
)
|
)
|
||||||
|
from common_win import BuildDepsCache
|
||||||
from installers import (
|
from installers import (
|
||||||
install_boost,
|
install_boost,
|
||||||
install_ccache,
|
install_ccache,
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ from common import (
|
|||||||
ensure_script_dir,
|
ensure_script_dir,
|
||||||
logger,
|
logger,
|
||||||
resolve_cli_or_env,
|
resolve_cli_or_env,
|
||||||
resolve_generator,
|
|
||||||
run_streamed,
|
run_streamed,
|
||||||
)
|
)
|
||||||
|
from common_win import resolve_generator
|
||||||
from vs_cfg import vs_cfg
|
from vs_cfg import vs_cfg
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-47
@@ -27,10 +27,7 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast, get_args
|
from typing import Any, Literal, TypeVar, cast, get_args
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from vs_cfg import VsCfgResult
|
|
||||||
|
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
@@ -195,46 +192,3 @@ def validate_cmake_version() -> None:
|
|||||||
if not match or tuple(map(int, match.groups())) < MIN_CMAKE_VERSION:
|
if not match or tuple(map(int, match.groups())) < MIN_CMAKE_VERSION:
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
class BuildDepsCache:
|
|
||||||
def __init__(self, vs_cfg_vars: VsCfgResult) -> None:
|
|
||||||
if vs_cfg_vars.vs_toolset_override:
|
|
||||||
self.path = SCRIPT_DIR / f"BuildDepsCache-{vs_cfg_vars.vs_platform}-{vs_cfg_vars.vs_toolset_override}.txt"
|
|
||||||
else:
|
|
||||||
self.path = SCRIPT_DIR / f"BuildDepsCache-{vs_cfg_vars.vs_platform}.txt"
|
|
||||||
self.path.write_text("")
|
|
||||||
|
|
||||||
def add_entry(self, key: str, value: str) -> None:
|
|
||||||
with self.path.open("a") as f:
|
|
||||||
f.write(f"{key}={value}\n")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def parse(path: Path) -> dict[str, str]:
|
|
||||||
entries: dict[str, str] = {}
|
|
||||||
for line in path.read_text().splitlines():
|
|
||||||
key, _, value = line.partition("=")
|
|
||||||
entries[key] = value
|
|
||||||
return entries
|
|
||||||
|
|
||||||
|
|
||||||
def resolve_generator(generator: str | None) -> str:
|
|
||||||
"""Return `generator` as-is, or fall back to the GEN_SHORTHAND from the most recently modified
|
|
||||||
BuildDepsCache-*.txt. Exits if neither is available.
|
|
||||||
"""
|
|
||||||
if generator is not None:
|
|
||||||
return generator
|
|
||||||
|
|
||||||
cache_files = sorted(SCRIPT_DIR.glob("BuildDepsCache-*.txt"), key=lambda p: p.stat().st_mtime, reverse=True)
|
|
||||||
cached_generator = None
|
|
||||||
if cache_files:
|
|
||||||
cache_file = cache_files[0]
|
|
||||||
logger.info(f"Found {cache_file.name}, reading GEN_SHORTHAND from it.")
|
|
||||||
cached_generator = BuildDepsCache.parse(cache_file).get("GEN_SHORTHAND")
|
|
||||||
|
|
||||||
if cached_generator is None:
|
|
||||||
logger.error(
|
|
||||||
"BuildDepsCache file does not exist and/or GEN_SHORTHAND missing from it. Run build-deps.py to create it."
|
|
||||||
)
|
|
||||||
sys.exit(1)
|
|
||||||
return cached_generator
|
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
###############################################################################
|
||||||
|
# #
|
||||||
|
# This file is part of IfcOpenShell. #
|
||||||
|
# #
|
||||||
|
# IfcOpenShell is free software: you can redistribute it and/or modify #
|
||||||
|
# it under the terms of the Lesser GNU General Public License as published by #
|
||||||
|
# the Free Software Foundation, either version 3.0 of the License, or #
|
||||||
|
# (at your option) any later version. #
|
||||||
|
# #
|
||||||
|
# IfcOpenShell is distributed in the hope that it will be useful, #
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
|
# Lesser GNU General Public License for more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the Lesser GNU General Public License #
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from common import SCRIPT_DIR, logger
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from vs_cfg import VsCfgResult
|
||||||
|
|
||||||
|
|
||||||
|
class BuildDepsCache:
|
||||||
|
def __init__(self, vs_cfg_vars: VsCfgResult) -> None:
|
||||||
|
if vs_cfg_vars.vs_toolset_override:
|
||||||
|
self.path = SCRIPT_DIR / f"BuildDepsCache-{vs_cfg_vars.vs_platform}-{vs_cfg_vars.vs_toolset_override}.txt"
|
||||||
|
else:
|
||||||
|
self.path = SCRIPT_DIR / f"BuildDepsCache-{vs_cfg_vars.vs_platform}.txt"
|
||||||
|
self.path.write_text("")
|
||||||
|
|
||||||
|
def add_entry(self, key: str, value: str) -> None:
|
||||||
|
with self.path.open("a") as f:
|
||||||
|
f.write(f"{key}={value}\n")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse(path: Path) -> dict[str, str]:
|
||||||
|
entries: dict[str, str] = {}
|
||||||
|
for line in path.read_text().splitlines():
|
||||||
|
key, _, value = line.partition("=")
|
||||||
|
entries[key] = value
|
||||||
|
return entries
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_generator(generator: str | None) -> str:
|
||||||
|
"""Return `generator` as-is, or fall back to the GEN_SHORTHAND from the most recently modified
|
||||||
|
BuildDepsCache-*.txt. Exits if neither is available.
|
||||||
|
"""
|
||||||
|
if generator is not None:
|
||||||
|
return generator
|
||||||
|
|
||||||
|
cache_files = sorted(SCRIPT_DIR.glob("BuildDepsCache-*.txt"), key=lambda p: p.stat().st_mtime, reverse=True)
|
||||||
|
cached_generator = None
|
||||||
|
if cache_files:
|
||||||
|
cache_file = cache_files[0]
|
||||||
|
logger.info(f"Found {cache_file.name}, reading GEN_SHORTHAND from it.")
|
||||||
|
cached_generator = BuildDepsCache.parse(cache_file).get("GEN_SHORTHAND")
|
||||||
|
|
||||||
|
if cached_generator is None:
|
||||||
|
logger.error(
|
||||||
|
"BuildDepsCache file does not exist and/or GEN_SHORTHAND missing from it. Run build-deps.py to create it."
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
return cached_generator
|
||||||
+1
-1
@@ -34,7 +34,6 @@ from common import (
|
|||||||
REPO_ROOT,
|
REPO_ROOT,
|
||||||
SCRIPT_DIR,
|
SCRIPT_DIR,
|
||||||
BuildCfg,
|
BuildCfg,
|
||||||
BuildDepsCache,
|
|
||||||
BuildType,
|
BuildType,
|
||||||
debug_or_release,
|
debug_or_release,
|
||||||
logger,
|
logger,
|
||||||
@@ -42,6 +41,7 @@ from common import (
|
|||||||
run,
|
run,
|
||||||
run_streamed,
|
run_streamed,
|
||||||
)
|
)
|
||||||
|
from common_win import BuildDepsCache
|
||||||
from vs_cfg import CMAKE_GENERATORS, VS_TOOLSET_TO_VS_VER, VsCfgResult, get_vs_var
|
from vs_cfg import CMAKE_GENERATORS, VS_TOOLSET_TO_VS_VER, VsCfgResult, get_vs_var
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -33,17 +33,16 @@ from common import (
|
|||||||
OFF_ON,
|
OFF_ON,
|
||||||
PROJECT_NAME,
|
PROJECT_NAME,
|
||||||
REPO_ROOT,
|
REPO_ROOT,
|
||||||
BuildDepsCache,
|
|
||||||
C,
|
C,
|
||||||
HelpStrings,
|
HelpStrings,
|
||||||
colorize,
|
colorize,
|
||||||
ensure_script_dir,
|
ensure_script_dir,
|
||||||
logger,
|
logger,
|
||||||
resolve_cli_or_env,
|
resolve_cli_or_env,
|
||||||
resolve_generator,
|
|
||||||
run,
|
run,
|
||||||
run_streamed,
|
run_streamed,
|
||||||
)
|
)
|
||||||
|
from common_win import BuildDepsCache, resolve_generator
|
||||||
from vs_cfg import VsCfgResult, vs_cfg
|
from vs_cfg import VsCfgResult, vs_cfg
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user