From ce1763f9c0996af672f8b31be7021d82a5f5f6a3 Mon Sep 17 00:00:00 2001 From: Eric Froemling Date: Fri, 11 Oct 2019 16:56:18 -0700 Subject: [PATCH] more project tidying --- .idea/dictionaries/ericf.xml | 2 ++ Makefile | 26 ++++++++++++++++++++++++++ tools/efrotools/__init__.py | 7 ++++++- tools/efrotools/efrocache.py | 23 +++++++++++++++++++++++ tools/snippets | 14 ++++++++++++-- tools/update_project | 22 ++++++++++++++++++++++ 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 tools/efrotools/efrocache.py diff --git a/.idea/dictionaries/ericf.xml b/.idea/dictionaries/ericf.xml index 027db5c4..0940eb31 100644 --- a/.idea/dictionaries/ericf.xml +++ b/.idea/dictionaries/ericf.xml @@ -1,6 +1,8 @@ + maxdepth + efrocache packagedir priv aaaa diff --git a/Makefile b/Makefile index 2c0db9c6..109539e1 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,24 @@ +# Copyright (c) 2011-2019 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. +# ------------------------------------------------------------------------------ + # This Makefile encompasses most high level functionality you should need when # working with Ballistica. These build rules are also handy as reference or a # starting point if you need specific funtionality beyond that exposed here. @@ -13,6 +34,11 @@ all: help # Tell make which of these targets don't represent files. .PHONY: all +# EFROCACHE_TARGET +build/testfile: + mkdir -p $(dir $@) + echo foobar > $@ + ################################################################################ # # diff --git a/tools/efrotools/__init__.py b/tools/efrotools/__init__.py index 2eaf03a4..faf4089d 100644 --- a/tools/efrotools/__init__.py +++ b/tools/efrotools/__init__.py @@ -90,7 +90,7 @@ def set_config(projroot: Path, config: Dict[str, Any]) -> None: def get_public_license(style: str) -> str: """Return the MIT license as used for our public facing stuff. - 'style' arg can be 'python', 'c++', or 'raw'. + 'style' arg can be 'python', 'c++', or 'makefile, or 'raw'. """ raw = MIT_LICENSE if style == 'raw': @@ -98,6 +98,11 @@ def get_public_license(style: str) -> str: if style == 'python': return ('\n'.join('#' + (' ' if l else '') + l for l in raw.splitlines()) + '\n' + '# ' + '-' * 77) + if style == 'makefile': + # Basically same as python except one char wider + # (Pep8 specifies 79 char lines vs more standard 80) + return ('\n'.join('#' + (' ' if l else '') + l + for l in raw.splitlines()) + '\n' + '# ' + '-' * 78) if style == 'c++': return '\n'.join('//' + (' ' if l else '') + l for l in raw.splitlines()) diff --git a/tools/efrotools/efrocache.py b/tools/efrotools/efrocache.py new file mode 100644 index 00000000..1f0a4751 --- /dev/null +++ b/tools/efrotools/efrocache.py @@ -0,0 +1,23 @@ +# Copyright (c) 2011-2019 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. +# ----------------------------------------------------------------------------- +"""A simple cloud caching system for making built binaries/assets available.""" + +from __future__ import annotations diff --git a/tools/snippets b/tools/snippets index f7c991d0..b43c7473 100755 --- a/tools/snippets +++ b/tools/snippets @@ -511,7 +511,7 @@ def python_gather() -> None: def clean_orphaned_assets() -> None: - """Remove assets that are no longer part of the build.""" + """Remove asset files that are no longer part of the build.""" import json # Operate from dist root.. @@ -523,7 +523,7 @@ def clean_orphaned_assets() -> None: fpath = os.path.join(root, fname) fpathrel = fpath[13:] # paths are relative to assets/build if fpathrel not in manifest: - print(f"Removing orphaned asset: {fpath}") + print(f"Removing orphaned asset file: {fpath}") os.unlink(fpath) # Lastly, clear empty dirs. @@ -597,5 +597,15 @@ def capitalize() -> None: print(' '.join(w.capitalize() for w in sys.argv[2:])) +def efrocache_update() -> None: + """Build & push files to efrocache for public access.""" + print('WOULD UPDATE EFROCACHE') + + +def efrocache_get() -> None: + """Get a file from efrocache.""" + print('WOULD GET FROM EFROCACHE') + + if __name__ == '__main__': snippets_main(globals()) diff --git a/tools/update_project b/tools/update_project index cea1f2a2..cdc8043b 100755 --- a/tools/update_project +++ b/tools/update_project @@ -39,6 +39,7 @@ from __future__ import annotations import os import sys +import subprocess from dataclasses import dataclass from typing import TYPE_CHECKING @@ -95,6 +96,7 @@ class App: self._update_generated_code_makefile() self._update_assets_makefile() + self._check_makefiles() self._check_python_files() self._check_sync_states() @@ -307,6 +309,26 @@ class App: expected=line, can_auto_update=allow_auto) + def _check_makefiles(self) -> None: + from efrotools import get_public_license + + # Run a few sanity checks on whatever makefiles we come across. + fnames = subprocess.run('find . -maxdepth 3 -name Makefile', + shell=True, + capture_output=True, + check=True).stdout.decode().split() + fnames = [n for n in fnames if '/build/' not in n] + + for fname in fnames: + with open(fname) as infile: + makefile = infile.read() + if LEGAL_NOTICE_PRIVATE not in makefile: + raise RuntimeError(f'Priv legal not found in {fname}') + if self._public: + public_license = get_public_license('makefile') + if public_license not in makefile: + raise RuntimeError(f'Pub license not found in {fname}') + def _check_python_file(self, fname: str) -> None: from efrotools import get_public_license with open(fname) as infile: