Added batools package

This commit is contained in:
Eric Froemling 2020-04-16 14:47:58 -07:00
parent 085cb072ce
commit 3a02181e51
5 changed files with 51 additions and 20 deletions

View File

@ -5,6 +5,3 @@
- Original author
- BDFL (benevolent dictator for life).
### Dmitry450
- Modder
- Fixed some game modes

View File

@ -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} <category>}
# - add this dependency to it: ${shell ${BSOURCES} <category> $@}
# (where <category> 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).

25
tools/batools/__init__.py Normal file
View File

@ -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.
"""

View File

@ -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

View File

@ -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}')