Replace the Makefile with a python build script

Signed-off-by: Trivernis <trivernis@protonmail.com>
pull/15/head
Trivernis 3 years ago
parent dde9a1e4fb
commit 3b38f1a8c6
No known key found for this signature in database
GPG Key ID: EB543D89E02BC83F

@ -6,7 +6,7 @@ WORKDIR /usr/src
COPY mediarepo-api ./mediarepo-api COPY mediarepo-api ./mediarepo-api
COPY mediarepo-daemon ./mediarepo-daemon COPY mediarepo-daemon ./mediarepo-daemon
COPY mediarepo-ui ./mediarepo-ui COPY mediarepo-ui ./mediarepo-ui
COPY Makefile . COPY build.py .
RUN apt-get update RUN apt-get update
RUN apt-get install -y \ RUN apt-get install -y \
@ -24,22 +24,17 @@ RUN apt-get install -y \
libavcodec-dev \ libavcodec-dev \
libavfilter-dev \ libavfilter-dev \
libavdevice-dev \ libavdevice-dev \
libavresample-dev \
libpostproc-dev \
clang \ clang \
nodejs \ nodejs \
npm \ npm \
libsoup2.4-dev \ libsoup2.4-dev \
libwebkit2gtk-4.0-dev \ libwebkit2gtk-4.0-dev \
file file \
python
RUN apt remove cmdtest -y RUN apt remove cmdtest -y
RUN npm install -g yarn
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}" ENV PATH="/root/.cargo/bin:${PATH}"
RUN install_packages make RUN python3 build.py build
RUN make build_daemon
RUN make build_ui

@ -1,16 +0,0 @@
default: build
build: build_daemon build_ui
create_output_dir:
mkdir -p out
build_daemon: create_output_dir
$(MAKE) -C mediarepo-daemon build
cp mediarepo-daemon/target/release/mediarepo-daemon* out/
build_ui: create_output_dir
$(MAKE) -C mediarepo-ui build
cp mediarepo-ui/src-tauri/target/release/mediarepo-ui* out/
cp mediarepo-ui/src-tauri/target/release/bundle out/
cp mediarepo-ui/src-tauri/icons out/

@ -63,25 +63,27 @@ When installing manually the `mediarepo-daemon` binary needs to be accessible in
You need to have a working rust toolchain (e.g. via [rustup](https://rustup.rs/)) and [node.js](https://nodejs.org) installed. You need to have a working rust toolchain (e.g. via [rustup](https://rustup.rs/)) and [node.js](https://nodejs.org) installed.
For building the UI the required tauri build tooling needs to be installed as well. Please follow [their documentation](https://tauri.studio/docs/getting-started/prerequisites) for setup information. For building the UI the required tauri build tooling needs to be installed as well. Please follow [their documentation](https://tauri.studio/docs/getting-started/prerequisites) for setup information.
You also need to have a working `make` installation on your system. You also need to have a working [python](https://www.python.org/) installation on your system.
### Building mediarepo ### Building mediarepo
After all required dependencies are installed and tools are accessible in the `PATH`, you can build the project like follows: After all required dependencies are installed and tools are accessible in the `PATH`, you can build the project like follows:
> Note: On some systems you need to use the `python3` command instead of `python`.
All Componens: All Componens:
```sh ```sh
$ make build $ python build.py build
``` ```
Daemon only: Daemon only:
```sh ```sh
$ make build_daemon $ python build.py build --daemon
``` ```
UI only: UI only:
```sh ```sh
$ make build_ui $ python build.py build --ui
``` ```
After building the `out` directory contains all the built binaries and bundles. After building the `out` directory contains all the built binaries and bundles.

@ -0,0 +1,162 @@
import shutil as shut
import os
build_output = 'out'
def check_exec(name: str):
print('Checking {}...'.format(name))
if shut.which(name) is None:
raise Exception('{} not found'.format(name))
exec(name + ' --version')
def check_yarn():
print('Checking yarn...')
if shut.which('yarn') is None:
print('installing yarn...')
exec('npm install -g yarn')
check_exec('yarn')
exec('yarn --version')
def check_ng():
print('Checking ng...')
if shut.which('ng') is None:
print('installing ng...')
exec('npm install -g @angular/cli')
check_exec('ng')
exec('ng --version')
def exec(cmd: str, dir: str = None) -> str:
import subprocess
child = subprocess.run(cmd, shell=True, cwd=dir)
child.check_returncode()
def store_artifact(path: str):
print('Storing {}'.format(path))
if os.path.isdir(path):
shut.copytree(path, os.path.join(build_output, os.path.basename(path)), dirs_exist_ok=True)
else:
shut.copy(path, build_output)
def cargo(cmd: str, dir: str = None) -> str:
print('cargo {}'.format(cmd))
exec('cargo {}'.format(cmd), dir)
def yarn(cmd: str, dir: str = None):
print('yarn {}'.format(cmd))
exec('yarn {}'.format(cmd), dir)
def build_daemon():
cargo('fetch', 'mediarepo-daemon')
cargo('build --release --frozen --verbose', 'mediarepo-daemon')
if os.name == 'nt':
store_artifact('mediarepo-daemon/target/release/mediarepo-daemon.exe')
else:
store_artifact('mediarepo-daemon/target/release/mediarepo-daemon')
def build_ui():
cargo('install tauri-cli --version ^1.0.0-rc.4')
yarn('install', 'mediarepo-ui')
cargo('tauri build --verbose', 'mediarepo-ui')
if os.name == 'nt':
store_artifact('mediarepo-ui/src-tauri/target/release/mediarepo-ui.exe')
else:
store_artifact('mediarepo-ui/src-tauri/target/release/mediarepo-ui')
store_artifact('mediarepo-ui/src-tauri/target/release/bundle/')
def check_daemon():
check_exec('clang')
check_exec('cargo')
def check_ui():
check_exec('clang')
check_exec('cargo')
check_exec('wget')
check_exec('curl')
check_exec('file')
check_exec('node')
check_exec('npm')
check_yarn()
check_ng()
def check():
check_daemon()
check_ui()
print('All checks passed')
def create_output_dir():
if not os.path.exists(build_output):
os.mkdir(build_output)
def clean():
if os.path.exists(build_output):
shut.rmtree(build_output)
print('Cleaned')
def build(daemon=True, ui=True):
clean()
create_output_dir()
if daemon:
check_daemon()
build_daemon()
if ui:
check_ui()
build_ui()
print('Build complete')
def parse_args():
import argparse
parser = argparse.ArgumentParser(description='Build mediarepo')
subparsers = parser.add_subparsers(dest='command')
subparsers.required = True
subparsers.add_parser('check')
build_parser = subparsers.add_parser('build')
build_parser.add_argument('--daemon', action='store_true', help='Build daemon')
build_parser.add_argument('--ui', action='store_true', help='Build UI')
subparsers.add_parser('clean')
args = parser.parse_args()
return args
def main():
opts = parse_args()
print(opts)
if opts.command == 'build':
if opts.daemon:
build(True, False)
elif opts.ui:
build(False, True)
else:
build()
elif opts.command == 'check':
check()
elif opts.command == 'clean':
clean()
if __name__ == '__main__':
main()

@ -1,7 +0,0 @@
default: build
build: install_deps
cargo build --frozen --release --verbose
install_deps:
cargo fetch

@ -1,10 +0,0 @@
default: build
build: install_tauri install_angular
cargo tauri build --verbose
install_tauri:
cargo install tauri-cli --version ^1.0.0-rc.4
install_angular:
npm i --save-dev @angular/cli

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save