Skip to content

Commit

Permalink
Setting up the tooling.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Aug 29, 2024
1 parent 9cbfd57 commit 0d1b42a
Show file tree
Hide file tree
Showing 22 changed files with 430 additions and 511 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev/* linguist-vendored
27 changes: 27 additions & 0 deletions .github/workflows/check-darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Checks (Darwin)

on: [push, pull_request]

jobs:
build-all:
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.11'

- name: Set up the build environment
run: ./vaev.sh tools setup && ./vaev.sh tools doctor

- name: Build Userspace (Host)
run: ./vaev.sh builder build

- name: Test Userspace (Host)
run: ./vaev.sh builder test
32 changes: 32 additions & 0 deletions .github/workflows/checks-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Checks (Ubuntu)

on: [push, pull_request]

jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.11'

- name: Set up the build environment
run: ./vaev.sh tools setup && ./vaev.sh tools doctor

- name: Download third-party dependencies
run: ./vaev.sh model install

- name: Build Userspace (Host)
run: ./vaev.sh builder build

- name: Test Userspace (Host)
run: ./vaev.sh builder test

- name: Check for formatting errors
run: ./meta/scripts/style-check.sh || echo "Please run ./meta/scripts/style-fix.sh"
4 changes: 2 additions & 2 deletions license.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
# MIT License

Copyright © 2018-2024, the skiftOS Developers
Copyright © 2018-2024, the skiftOS Developers<br>
Copyright © 2024, Odoo S.A.

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:
Expand Down
5 changes: 5 additions & 0 deletions meta/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cutekit import ensure

ensure((0, 8, 0))

from . import tools # noqa E402, F401: Needed for side effect
2 changes: 2 additions & 0 deletions meta/plugins/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-magic ~= 0.4.27
git+https://github.com/cute-engineering/cutekit.git@0.7.3
241 changes: 241 additions & 0 deletions meta/plugins/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
from cutekit import shell, vt100, cli
import subprocess
import re


def isVersionAtLeastOrEqual(
actualVersion: tuple[int, ...], expectedVersion: tuple[int, ...]
) -> bool:
if len(actualVersion) < len(expectedVersion):
return False

for i in range(len(expectedVersion)):
if actualVersion[i] < expectedVersion[i]:
return False

return True


def getVersionFromOutput(output: str, versionRegex: str) -> tuple[int, ...]:
versionMatch = re.search(versionRegex, output)
if versionMatch:
versionStr = versionMatch[0].split(".")
return tuple(map(int, versionStr))
else:
return ()


def checkVersion(
cmd: str, versionExpected: tuple[int, ...], versionCommand: str, versionRegex: str
) -> tuple[bool, tuple[int, ...]]:
try:
result = subprocess.check_output([cmd, versionCommand]).decode("utf-8")
actualVersion = getVersionFromOutput(result, versionRegex)
return isVersionAtLeastOrEqual(actualVersion, versionExpected), actualVersion
except Exception:
return False, ()


def commandIsAvailable(
cmd: str,
versionExpected: tuple[int, ...] = (0, 0, 0),
versionCommand: str = "--version",
versionRegex: str = r"\d+(\.\d+)+",
) -> bool:
print(f"Checking if {cmd} is available... ", end="")
result = True

try:
cmd = shell.latest(cmd)
path = shell.which(cmd) or cmd
versionMatch, version = checkVersion(
cmd, versionExpected, versionCommand, versionRegex
)
if not versionMatch:
if versionExpected == (0, 0, 0):
print(f"{vt100.RED}not found{vt100.RESET}")
else:
print(f"{vt100.RED}too old{vt100.RESET}")
print(
f"Expected: {'.'.join(map(str, versionExpected))}\nActual: {'.'.join(map(str, version))}"
)
result = False
else:
print(f"{vt100.GREEN}ok{vt100.RESET}")
print(
f"{vt100.BRIGHT_BLACK}Command: {cmd}\nLocation: {path}\nVersion: {'.'.join(map(str, version))}{vt100.RESET}\n"
)
except Exception as e:
print(f" {e}")
print(f"{vt100.RED}Error: {cmd} is not available{vt100.RESET}")
result = False

return result


def moduleIsAvailable(module: str) -> bool:
print(f"Checking if {module} is available...", end="")
try:
mod = __import__(module)
print(f"{vt100.GREEN} ok{vt100.RESET}")
version = "unknown"
path = mod.__file__

if hasattr(mod, "__version__"):
version = mod.__version__
print(
f"{vt100.BRIGHT_BLACK}Module: {module}\nVersion: {version}\nLocation: {path}{vt100.RESET}\n"
)

return True
except Exception as e:
print(f" {e}")
print(f"{vt100.RED}Error: {module} is not available{vt100.RESET}")
return False


def compileTest(what: str, code: str) -> bool:
print(f"Checking if {what} is available...", end="")
output = ""
try:
proc = subprocess.run(
[
shell.latest("clang++"),
"-x",
"c++",
"-std=c++20",
"-o",
"/dev/null",
"-",
],
input=code.encode("utf-8"),
stderr=subprocess.PIPE,
)
output = proc.stderr.decode("utf-8")
if proc.returncode != 0:
print(f" {vt100.RED}Failed{vt100.RESET}")
print(f"{vt100.BRIGHT_BLACK}{output}{vt100.RESET}")
return False
else:
print(f" {vt100.GREEN}ok{vt100.RESET}")
return True
except Exception:
print(f" {vt100.RED}Failed{vt100.RESET}")
return False


def checkForHeader(header: str) -> bool:
return compileTest(f"header <{header}>", f"#include <{header}>\nint main() {{}}")


def checkForSymbol(header: str, symbol: str) -> bool:
return compileTest(
f"symbol {symbol}", f"#include <{header}>\nint main() {{ {symbol}; }}"
)


@cli.command(None, "tools", "Manage the development tools")
def _():
pass


@cli.command("n", "tools/nuke", "Nuke the development tools")
@cli.command("s", "tools/setup", "Setup the development environment")
def _():
raise RuntimeError("Don't use ck directly, use ./skift.sh instead.")


@cli.command("d", "tools/doctor", "Check if all required commands are available")
def _():
everythingIsOk = True

everythingIsOk = everythingIsOk & moduleIsAvailable("requests")
everythingIsOk = everythingIsOk & moduleIsAvailable("graphviz")
everythingIsOk = everythingIsOk & moduleIsAvailable("magic")
everythingIsOk = everythingIsOk & moduleIsAvailable("cutekit")
everythingIsOk = everythingIsOk & moduleIsAvailable("chatty")
everythingIsOk = everythingIsOk & commandIsAvailable("qemu-system-x86_64")
everythingIsOk = everythingIsOk & commandIsAvailable("clang", versionExpected=(18,))
everythingIsOk = everythingIsOk & commandIsAvailable(
"clang++", versionExpected=(16,)
)
everythingIsOk = everythingIsOk & commandIsAvailable(
"llvm-ar", versionExpected=(16,)
)
everythingIsOk = everythingIsOk & commandIsAvailable(
"ld.lld", versionExpected=(16,)
)
everythingIsOk = everythingIsOk & commandIsAvailable("nasm")
everythingIsOk = everythingIsOk & commandIsAvailable("ninja")
everythingIsOk = everythingIsOk & commandIsAvailable(
"cutekit", versionCommand="version"
)
everythingIsOk = everythingIsOk & commandIsAvailable("chatty")
everythingIsOk = everythingIsOk & commandIsAvailable("pkg-config")

everythingIsOk = everythingIsOk & commandIsAvailable("sgdisk")
everythingIsOk = everythingIsOk & commandIsAvailable("mformat")
everythingIsOk = everythingIsOk & commandIsAvailable("mcopy")
everythingIsOk = everythingIsOk & commandIsAvailable("mmd")

HEADERS = {
"coroutine": [
"std::coroutine_handle",
],
"compare": [
"std::strong_ordering",
"std::weak_ordering",
"std::partial_ordering",
],
"initializer_list": [
"std::initializer_list",
],
"new": [],
"utility": [],
"memory": [],
"limits.h": [
"CHAR_BIT",
],
"math.h": [],
"cstddef": [
"size_t",
"ptrdiff_t",
"std::nullptr_t",
],
"stdint.h": [
"uint8_t",
"uint16_t",
"uint32_t",
"uint64_t",
"int8_t",
"int16_t",
"int32_t",
"int64_t",
],
"string.h": [
"memcpy",
"memmove",
"memset",
"memcmp",
],
}

headersOk = True

for header in HEADERS:
headersOk = headersOk & checkForHeader(header)

if not headersOk:
continue

for symbol in HEADERS[header]:
headersOk = headersOk & checkForSymbol(header, symbol)

if not headersOk:
print(
f"\n{vt100.RED}Error: Some headers are missing, please install the development packages for your distribution.{vt100.RESET}"
)
everythingIsOk = False

else:
print(f"\n{vt100.GREEN}Everythings looking good ​😉​👌​{vt100.RESET}\n")
3 changes: 3 additions & 0 deletions meta/scripts/env-darwin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

export PATH=$(brew --prefix llvm)/bin:$PATH
3 changes: 3 additions & 0 deletions meta/scripts/setup-darwin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

brew install nasm llvm sdl2 python3 ninja libmagic
9 changes: 9 additions & 0 deletions meta/scripts/setup-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

export DEBIAN_FRONTEND=noninteractive

apt update
apt install build-essential git ninja-build libsdl2-dev nasm gcc-multilib qemu-system-x86 mtools liburing-dev
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" llvm 18
5 changes: 5 additions & 0 deletions meta/scripts/style-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

find src/ -iname '*.h' -o -iname '*.cpp' | xargs clang-format --dry-run --Werror
5 changes: 5 additions & 0 deletions meta/scripts/style-fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

find src/ -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i
1 change: 1 addition & 0 deletions meta/scripts/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"0.1"
4 changes: 2 additions & 2 deletions project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "The vaev browser engine",
"extern": {
"skift-org/skift": {
"git": "https://github.com/cute-engineering/ce-stdcpp.git",
"tag": "v1.3.0"
"git": "https://github.com/skift-org/skift",
"tag": "main"
}
}
}
4 changes: 0 additions & 4 deletions src/vaev-js/_mod.h

This file was deleted.

Loading

0 comments on commit 0d1b42a

Please sign in to comment.