-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support libraries in decomp.me (#843)
* Add script to download libraries, and download directx * Add libraries endpoint * Allow compiling with a library * Add new libraries tab in frontend * Add libraries support in CI * Better look for the libraries * Give pretty names to libraries * Move Libraries to live under CompilerOpts * typechecking hackery * Make libraries trigger autorecomp and set the unsaved flag * Fix libraryVersions * Add new libraries download script to CI, docker and docs --------- Co-authored-by: Ethan Roseman <[email protected]>
- Loading branch information
Showing
23 changed files
with
558 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from dataclasses import dataclass | ||
from functools import cache | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from django.conf import settings | ||
|
||
if TYPE_CHECKING: | ||
LIBRARY_BASE_PATH: Path | ||
else: | ||
LIBRARY_BASE_PATH: Path = settings.LIBRARY_BASE_PATH | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Library: | ||
name: str | ||
version: str | ||
|
||
@property | ||
def path(self) -> Path: | ||
return LIBRARY_BASE_PATH / self.name / self.version | ||
|
||
@property | ||
def include_path(self) -> Path: | ||
return self.path / "include" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class LibraryVersions: | ||
name: str | ||
supported_versions: list[str] | ||
|
||
@property | ||
def path(self) -> Path: | ||
return LIBRARY_BASE_PATH / self.name | ||
|
||
|
||
@cache | ||
def available_libraries() -> list[LibraryVersions]: | ||
results = [] | ||
|
||
for lib_dir in LIBRARY_BASE_PATH.iterdir(): | ||
versions = [] | ||
if not lib_dir.is_dir(): | ||
continue | ||
for version_dir in lib_dir.iterdir(): | ||
if not version_dir.is_dir(): | ||
continue | ||
if not (version_dir / "include").exists(): | ||
continue | ||
|
||
versions.append(version_dir.name) | ||
|
||
if len(versions) > 0: | ||
results.append( | ||
LibraryVersions( | ||
name=lib_dir.name, | ||
supported_versions=versions, | ||
) | ||
) | ||
|
||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.3 on 2023-09-23 14:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("coreapp", "0037_rename_psyq43_to_psyq44"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="scratch", | ||
name="libraries", | ||
field=models.JSONField(default=list), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Dict | ||
|
||
from django.utils.timezone import now | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from coreapp import libraries | ||
|
||
from ..decorators.django import condition | ||
|
||
boot_time = now() | ||
|
||
|
||
class LibrariesDetail(APIView): | ||
@staticmethod | ||
def libraries_json() -> list[dict[str, object]]: | ||
return [ | ||
{"name": l.name, "supported_versions": l.supported_versions} | ||
for l in libraries.available_libraries() | ||
] | ||
|
||
@condition(last_modified_func=lambda request: boot_time) | ||
def head(self, request: Request) -> Response: | ||
return Response() | ||
|
||
@condition(last_modified_func=lambda request: boot_time) | ||
def get(self, request: Request) -> Response: | ||
return Response( | ||
{ | ||
"libraries": LibrariesDetail.libraries_json(), | ||
} | ||
) |
Oops, something went wrong.