Browse Source

Initial commit

master
Noah Petherbridge 4 years ago
commit
1722579d17
  1. 18
      README.md
  2. 142
      full-setup.py

18
README.md

@ -0,0 +1,18 @@
# Project: Doodle Full Setup
This repo provides a Python script, `full-setup.py` which will initialize and
release a build of Project: Doodle on your current Unix-like system
(Fedora, Debian, and macOS-like targets).
On macOS ensure you have installed homebrew first: https://brew.sh
The script automates the full process of cloning down all the repos, putting
release assets in place (fonts, doodads, levels, sounds) and building a release
tarball for your current system.
This is especially useful for systems not targeted by the Docker image, such
as macOS and Linux on ARM (Pinephone).
## See Also
* [doodle-docker](https://git.kirsle.net/apps/doodle-docker)

142
full-setup.py

@ -0,0 +1,142 @@
#!/usr/bin/env python
"""
Full setup, from scratch to distribution, of Project: Doodle.
Run this script from an empty working directory. All git repos will be cloned
here (or updated if already existing) and the app will be fully built including
fonts, default levels and doodads, sound effects and music for your current
system. Useful to quickly bootstrap a build on weird operating systems like
macOS or Linux on ARM (Pinephone).
First ensure that your SSH key is authorized on git.kirsle.net to download
the repos easily. This script will also handle installing the SDL2 dependencies
on Fedora, Debian and macOS type systems.
"""
import sys
import os
import os.path
import subprocess
import pathlib
# Git repositories.
repos = {
"git@git.kirsle.net:apps/doodle": "doodle",
"git@git.kirsle.net:apps/doodle-masters": "masters",
"git@git.kirsle.net:apps/doodle-vendor": "vendor",
"git@git.kirsle.net:apps/doodle-rtp": "rtp",
"git@git.kirsle.net:go/render": "render",
"git@git.kirsle.net:go/ui": "ui",
"git@git.kirsle.net:go/audio": "audio",
}
# Software dependencies.
dep_fedora = ["golang", "SDL2-devel", "SDL2_ttf-devel", "SDL2_mixer-devel"]
dep_debian = ["golang", "libsdl2-dev", "libsdl2-ttf-dev", "libsdl2-mixer-dev"]
dep_macos = ["golang", "sdl2", "sdl2_ttf", "sdl2_mixer", "pkg-config"]
# Absolute path to current working directory.
ROOT = pathlib.Path().absolute()
def main():
print(
"Project: Doodle Full Installer\n"
"Current working directory: {root}\n"
"Ensure your SSH keys are set up on git.kirsle.net to easily clone repos."
.format(root=ROOT)
)
input("Press Enter to begin.")
install_deps()
clone_repos()
patch_gomod()
copy_assets()
install_doodad()
build()
def install_deps():
"""Install system dependencies."""
if shell("which rpm") == 0 and shell("which dnf") == 0:
# Fedora-like.
if shell("rpm -q {}".format(' '.join(dep_fedora))) != 0:
must_shell("sudo dnf install {}".format(' '.join(dep_fedora)))
elif shell("which apt") == 0:
# Debian-like.
if shell("dpkg-query -l {}".format(' '.join(dep_debian))) != 0:
must_shell("sudo apt update && sudo apt install {}".format(' '.join(dep_debian)))
elif shell("which brew") == 0:
# MacOS
must_shell("brew install {}".format(' '.join(dep_macos)))
else:
print("Warning: didn't detect your package manager to install SDL2 and other dependencies")
# Get the bindata command.
shell("go get -u git.kirsle.net/go/bindata/...")
def clone_repos():
"""Clone or update all the git repos"""
for url, name in repos.items():
if os.path.isdir(name):
os.chdir(name)
must_shell("git pull --ff-only")
os.chdir("..")
else:
must_shell("git clone {} {}".format(url, name))
def patch_gomod():
"""Patch the doodle/go.mod to use local paths to other repos."""
os.chdir("doodle")
if shell("grep -e 'replace git.kirsle.net' go.mod") != 0:
with open("go.mod", "a") as fh:
fh.write(
"\n\nreplace git.kirsle.net/go/render => {root}/render\n"
"replace git.kirsle.net/go/ui => {root}/ui\n"
"replace git.kirsle.net/go/audio => {root}/audio\n"
.format(root=ROOT)
)
os.chdir("..")
def copy_assets():
"""Copy assets from other repos into doodle."""
if not os.path.isdir("doodle/assets/fonts"):
shell("cp -rv vendor/fonts doodle/assets/fonts")
if not os.path.isdir("doodle/assets/levels"):
shell("cp -rv masters/levels doodle/assets/levels")
if not os.path.isdir("doodle/rtp"):
shell("mkdir -p doodle/rtp && cp -rv rtp/* doodle/rtp/")
def install_doodad():
"""Install the doodad CLI tool from the doodle repo."""
os.chdir("doodle")
must_shell("make bindata-dev")
must_shell("go install git.kirsle.net/apps/doodle/cmd/doodad")
os.chdir("..")
def build():
"""Build the game."""
os.chdir("doodle")
must_shell("make dist")
def shell(cmd):
"""Echo and run a shell command"""
print("$ ", cmd)
return subprocess.call(cmd, shell=True)
def must_shell(cmd):
"""Run a shell command which MUST succeed."""
assert shell(cmd) == 0
if __name__ == "__main__":
main()
Loading…
Cancel
Save