Skip to content

Commit

Permalink
Use doit as leading build system rather than CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSWolf committed Dec 27, 2024
1 parent 1275d57 commit 8993c87
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 105 deletions.
26 changes: 21 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,33 @@ jobs:
BOOST_ROOT: ${{ github.workspace }}/lib/boost
BOOST_URL: https://sourceforge.net/projects/boost/files/boost/1.76.0/boost_1_76_0.tar.bz2/download
steps:
- name: Install Deno
uses: denoland/setup-deno@v2
- name: Deactivate EOL conversion
shell: bash
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install Python wheels
shell: bash
run: pip install -r requirements.txt
- name: Restore Boost from cache
uses: actions/cache@v4
id: cache-boost
with:
path: ${{ env.BOOST_ROOT }}
key: ${{ env.BOOST_URL }}
- name: Lint
shell: bash
run: doit check-formatted
- name: Download Boost
if: steps.cache-boost.outputs.cache-hit != 'true'
shell: bash
Expand All @@ -49,14 +66,13 @@ jobs:
fi
mkdir -p $BOOST_ROOT
curl --insecure -L $BOOST_URL | tar -xj --strip-components=1 -C $BOOST_ROOT
- name: Build Rhubarb
- name: Build and package
shell: bash
run: |
JAVA_HOME=$JAVA_HOME_11_X64
mkdir build
cd build
cmake ${{ matrix.cmakeOptions }} ..
cmake --build . --config Release --target package
mkdir rhubarb/build
(cd rhubarb/build && cmake ${{ matrix.cmakeOptions }} ..)
doit package
- name: Run tests
shell: bash
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vs/
.vscode/
*.user
artifacts/
build/
venv/

Expand Down
38 changes: 0 additions & 38 deletions CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions app-info.cmake

This file was deleted.

4 changes: 4 additions & 0 deletions app-info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
appName = "Rhubarb Lip Sync"

# Can be any valid SemVer version, including suffixes
appVersion = "1.13.0"
123 changes: 120 additions & 3 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
from gitignore_parser import parse_gitignore
from typing import Dict, Optional, List
from enum import Enum

from shutil import rmtree, copy, copytree, make_archive
import platform
import tomllib

root_dir = Path(__file__).parent
rhubarb_dir = root_dir / 'rhubarb'
rhubarb_build_dir = rhubarb_dir / 'build'
extras_dir = root_dir / 'extras'


def task_format():
Expand Down Expand Up @@ -48,8 +52,11 @@ class Formatter(Enum):
def format(files: List[Path], formatter: Formatter, *, check_only: bool = False):
match formatter:
case Formatter.CLANG_FORMAT:
# Pass relative paths to avoid exceeding the maximum command line length
relative_paths = [file.relative_to(root_dir) for file in files]
subprocess.run(
['clang-format', '--dry-run' if check_only else '-i', '--Werror', *files],
['clang-format', '--dry-run' if check_only else '-i', '--Werror', *relative_paths],
cwd=root_dir,
check=True,
)
case Formatter.GERSEMI:
Expand All @@ -71,6 +78,100 @@ def format(files: List[Path], formatter: Formatter, *, check_only: bool = False)
raise ValueError(f'Unknown formatter: {formatter}')


def task_configure_rhubarb():
"""Configure CMake for the Rhubarb binary"""

def configure_rhubarb():
ensure_dir(rhubarb_build_dir)
subprocess.run(['cmake', '..'], cwd=rhubarb_build_dir, check=True)

return {'basename': 'configure-rhubarb', 'actions': [configure_rhubarb]}


def task_build_rhubarb():
"""Build the Rhubarb binary"""

def build_rhubarb():
subprocess.run(
['cmake', '--build', '.', '--config', 'Release'], cwd=rhubarb_build_dir, check=True
)

return {'basename': 'build-rhubarb', 'actions': [build_rhubarb]}


def task_build_spine():
"""Build Rhubarb for Spine"""

def build_spine():
onWindows = platform.system() == 'Windows'
subprocess.run(
['gradlew.bat' if onWindows else './gradlew', 'build'],
cwd=extras_dir / 'esoteric-software-spine',
check=True,
shell=onWindows,
)

return {'basename': 'build-spine', 'actions': [build_spine]}


def task_package():
"""Package all artifacts into an archive file"""

with open(root_dir / 'app-info.toml', 'rb') as file:
appInfo = tomllib.load(file)

os_name = 'macOS' if platform.system() == 'Darwin' else platform.system()
file_name = f"{appInfo['appName'].replace(' ', '-')}-{appInfo['appVersion']}-{os_name}"

artifacts_dir = ensure_empty_dir(root_dir / 'artifacts')
tree_dir = ensure_dir(artifacts_dir.joinpath(file_name))

def collect_artifacts():
# Misc. files
copy(root_dir / 'README.adoc', tree_dir)
copy(root_dir / 'LICENSE.md', tree_dir)
copy(root_dir / 'CHANGELOG.md', tree_dir)
copytree(root_dir / 'img', tree_dir / 'img')

# Rhubarb
subprocess.run(
['cmake', '--install', '.', '--prefix', tree_dir], cwd=rhubarb_build_dir, check=True
)

# Adobe After Effects script
src = extras_dir / 'adobe-after-effects'
dst_extras_dir = ensure_dir(tree_dir / 'extras')
dst = ensure_dir(dst_extras_dir / 'adobe-after-effects')
copy(src / 'README.adoc', dst)
copy(src / 'Rhubarb Lip Sync.jsx', dst)

# Rhubarb for Spine
src = extras_dir / 'esoteric-software-spine'
dst = ensure_dir(dst_extras_dir / 'esoteric-software-spine')
copy(src / 'README.adoc', dst)
for file in (src / 'build' / 'libs').iterdir():
copy(file, dst)

# Magix Vegas
src = extras_dir / 'magix-vegas'
dst = ensure_dir(dst_extras_dir / 'magix-vegas')
copy(src / 'README.adoc', dst)
copy(src / 'Debug Rhubarb.cs', dst)
copy(src / 'Debug Rhubarb.cs.config', dst)
copy(src / 'Import Rhubarb.cs', dst)
copy(src / 'Import Rhubarb.cs.config', dst)

def pack_artifacts():
zip_base_name = tree_dir
format = 'gztar' if platform.system() == 'Linux' else 'zip'
make_archive(zip_base_name, format, tree_dir)

return {
'actions': [collect_artifacts, pack_artifacts],
'task_dep': ['build-rhubarb', 'build-spine'],
}


@cache
def get_files_by_formatters() -> Dict[Formatter, List[Path]]:
"""Returns a dict with all formattable code files grouped by formatter."""
Expand All @@ -81,7 +182,7 @@ def is_hidden(path: Path):
return path.name.startswith('.')

def is_third_party(path: Path):
return path.is_relative_to(rhubarb_dir / 'lib') or path.name == 'gradle'
return path.name == 'lib' or path.name == 'gradle'

result = {formatter: [] for formatter in Formatter}

Expand Down Expand Up @@ -115,3 +216,19 @@ def get_formatter(path: Path) -> Optional[Formatter]:
return Formatter.PRETTIER
case '.py':
return Formatter.RUFF


def ensure_dir(dir: Path) -> Path:
"""Makes sure the given directory exists."""

if not dir.exists():
dir.mkdir()
return dir


def ensure_empty_dir(dir: Path) -> Path:
"""Makes sure the given directory exists and is empty."""

if dir.exists():
rmtree(dir)
return ensure_dir(dir)
5 changes: 0 additions & 5 deletions extras/adobe-after-effects/CMakeLists.txt

This file was deleted.

13 changes: 0 additions & 13 deletions extras/esoteric-software-spine/CMakeLists.txt

This file was deleted.

8 changes: 2 additions & 6 deletions extras/esoteric-software-spine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ plugins {

fun getVersion(): String {
// Dynamically read version from CMake file
val file = File(rootDir.parentFile.parentFile, "app-info.cmake")
val file = File(rootDir.parentFile.parentFile, "app-info.toml")
val text = file.readText()
val major = Regex("""appVersionMajor\s+(\d+)""").find(text)!!.groupValues[1]
val minor = Regex("""appVersionMinor\s+(\d+)""").find(text)!!.groupValues[1]
val patch = Regex("""appVersionPatch\s+(\d+)""").find(text)!!.groupValues[1]
val suffix = Regex("""appVersionSuffix\s+"(.*?)"""").find(text)!!.groupValues[1]
return "$major.$minor.$patch$suffix"
return Regex("""appVersion\s*=\s*"(.*?)"(?:)""").find(text)!!.groupValues[1]
}

group = "com.rhubarb_lip_sync"
Expand Down
11 changes: 0 additions & 11 deletions extras/magix-vegas/CMakeLists.txt

This file was deleted.

6 changes: 0 additions & 6 deletions package-osx.sh

This file was deleted.

5 changes: 0 additions & 5 deletions package-win.bat

This file was deleted.

15 changes: 10 additions & 5 deletions rhubarb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 3.10)

include("../app-info.cmake")
# Parse app info
file(READ "../app-info.toml" tomlContent)
string(REGEX MATCH "appName *= *\"[^\"]+\"" appName "${tomlContent}")
string(REGEX REPLACE ".*\"([^\"]+)\"" "\\1" appName "${appName}")
string(REGEX MATCH "appVersion *= *\"[^\"]+\"" appVersion "${tomlContent}")
string(REGEX REPLACE ".*\"([^\"]+)\"" "\\1" appVersion "${appVersion}")

project("${appName}")

# Support legacy OS X versions
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING "Minimum OS X deployment version")
Expand Down Expand Up @@ -94,6 +101,7 @@ set_target_properties(pocketSphinx PROPERTIES FOLDER lib)
include_directories(SYSTEM "lib/tclap-1.2.1/include")

# ... Google Test
set(INSTALL_GTEST OFF) # Prevent library files from ending up in our artifacts
add_subdirectory("lib/googletest")
target_compile_options(gmock PRIVATE ${disableWarningsFlags})
set_target_properties(gmock PROPERTIES FOLDER lib)
Expand Down Expand Up @@ -327,7 +335,7 @@ target_link_libraries(
)

# ... rhubarb-core
configure_file(src/core/app-info.cpp.in app-info.cpp ESCAPE_QUOTES)
configure_file(src/core/app-info.cpp.in app-info.cpp)
add_library(
rhubarb-core
${CMAKE_CURRENT_BINARY_DIR}/app-info.cpp
Expand Down Expand Up @@ -560,7 +568,4 @@ endfunction()

copy_and_install("lib/pocketsphinx-rev13216/model/en-us/*" "res/sphinx")
copy_and_install("lib/cmusphinx-en-us-5.2/*" "res/sphinx/acoustic-model")

copy_and_install("tests/resources/*" "tests/resources")

install(TARGETS rhubarb RUNTIME DESTINATION .)

0 comments on commit 8993c87

Please sign in to comment.