From 3a02181e51d4f79287df6335d2cc4d8d7d688e2f Mon Sep 17 00:00:00 2001 From: Eric Froemling Date: Thu, 16 Apr 2020 14:47:58 -0700 Subject: [PATCH] Added batools package --- CONTRIBUTORS.md | 3 --- Makefile | 12 ++++++------ tools/batools/__init__.py | 25 +++++++++++++++++++++++++ tools/efrotools/__init__.py | 3 +++ tools/snippets | 28 +++++++++++++++++----------- 5 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 tools/batools/__init__.py diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1f7aedbe..8e29bea2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -5,6 +5,3 @@ - Original author - BDFL (benevolent dictator for life). -### Dmitry450 -- Modder -- Fixed some game modes diff --git a/Makefile b/Makefile index ceb95143..c915050d 100644 --- a/Makefile +++ b/Makefile @@ -34,10 +34,10 @@ DOCPREFIX = "ballisticacore_" # time-consuming. To use these, do the following: # - create a physical file for the target: ${BFILEDIR}/targetname # (targets that are already physical files work too) -# - add this dependency to it: ${shell ${BSOURCES} } +# - add this dependency to it: ${shell ${BSOURCES} $@} # (where covers all files that could affect the target) # - always touch the target file as the last build step: -# mkdir -p `dirname ${@}` && touch ${@} +# mkdir -p `dirname $@` && touch $@ # (even if the build step usually does; the build may not actually run # which could leave one of the overly-broad dep files newer than it) # Note that this mechanism slows builds a bit if category contains a lot of @@ -105,15 +105,15 @@ assets-clean: # A bfile for the resources target so we don't always have to run it. RESOURCES_F = ${BFILEDIR}/resources -${RESOURCES_F}: ${PREREQS} resources/Makefile ${shell ${BSOURCES} resources} +${RESOURCES_F}: ${PREREQS} resources/Makefile ${shell ${BSOURCES} resources $@} @cd resources && $(MAKE) -j${CPUS} resources - @mkdir -p `dirname ${@}` && touch ${@} + @mkdir -p `dirname $@` && touch $@ # A bfile for the code target so we don't always have to run it. CODE_F = ${BFILEDIR}/code -${CODE_F}: ${PREREQS} ${shell ${BSOURCES} gen} +${CODE_F}: ${PREREQS} ${shell ${BSOURCES} gen $@} @cd src/generated_src && $(MAKE) -j${CPUS} generated_code - @mkdir -p `dirname ${@}` && touch ${@} + @mkdir -p `dirname $@` && touch $@ # Remove *ALL* files and directories that aren't managed by git # (except for a few things such as localconfig.json). diff --git a/tools/batools/__init__.py b/tools/batools/__init__.py new file mode 100644 index 00000000..2d3bd7fb --- /dev/null +++ b/tools/batools/__init__.py @@ -0,0 +1,25 @@ +# Copyright (c) 2011-2020 Eric Froemling +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# ----------------------------------------------------------------------------- +"""Build/tool functionality specific to the Ballistica project. + +This stuff can be a bit more sloppy/loosey-goosey since it is not used by the +game itself. +""" diff --git a/tools/efrotools/__init__.py b/tools/efrotools/__init__.py index 7262e580..56f4ca7d 100644 --- a/tools/efrotools/__init__.py +++ b/tools/efrotools/__init__.py @@ -24,6 +24,9 @@ This stuff can be a bit more sloppy/loosey-goosey since it is not used in live client or server code. """ +# FIXME: should migrate everything here into submodules since this adds +# overhead to anything importing from any efrotools submodule. + from __future__ import annotations import os diff --git a/tools/snippets b/tools/snippets index 5fd41c86..7aa6864a 100755 --- a/tools/snippets +++ b/tools/snippets @@ -876,12 +876,13 @@ def update_makebob() -> None: print('All builds complete!', flush=True) -def _printpaths(inpaths: List[str], category: str) -> None: - paths: List[str] = [] +def _printpaths(inpaths: List[str], category: str, + target: Optional[str]) -> None: + allpaths: List[str] = [] for inpath in inpaths: # Add files verbatim; recurse through dirs. if os.path.isfile(inpath): - paths.append(inpath) + allpaths.append(inpath) continue for root, _dnames, fnames in os.walk(inpath): # Always skip these.. @@ -905,8 +906,8 @@ def _printpaths(inpaths: List[str], category: str) -> None: path = os.path.join(root, fname) if ' ' in path: raise RuntimeError(f'Invalid path with space: {path}') - paths.append(path) - print(' '.join(paths)) + allpaths.append(path) + print(' '.join(allpaths)) def sources() -> None: @@ -915,20 +916,25 @@ def sources() -> None: These are used as broad, redundant filters for expensive build ops. For instance, when running a build through a VM we might want to skip even spinning up the VM if absolutely no source files have changed. + + With a single category arg, all input files for that category are printed. + If a target filename is passed as a second arg, sources older than the + target may be withheld to speed up the Make process. """ try: - if len(sys.argv) != 3: - raise CleanError('Expected one argument.') + if len(sys.argv) not in (3, 4): + raise CleanError('Expected one or two arguments.') category = sys.argv[2] + target = sys.argv[3] if len(sys.argv) > 3 else None if category == 'gen': - _printpaths(['tools', 'src/generated_src'], category) + _printpaths(['tools', 'src/generated_src'], category, target) elif category == 'assets': - _printpaths(['tools', 'assets/src'], category) + _printpaths(['tools', 'assets/src'], category, target) elif category in ('cmake', 'win'): - _printpaths(['tools', 'src'], category) + _printpaths(['tools', 'src'], category, target) elif category == 'resources': _printpaths(['tools', 'resources/src', 'resources/Makefile'], - category) + category, target) else: raise ValueError(f'Invalid source category: {category}')