Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
"""准备真实第三方锁,然后在搬移的开发包和空 HOME 中离线构建 Go/Node/Python。"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
BUSINESS = {
|
||||
"go": ("render.go", "github.com/yuin/goldmark@v1.7.8", '''package main
|
||||
import("context";"bytes";"github.com/yuin/goldmark")
|
||||
func Render(_ context.Context,input any,_ any)(any,error){var out bytes.Buffer;err:=goldmark.Convert([]byte(input.(map[string]any)["source"].(string)),&out);return map[string]any{"html":out.String()},err}
|
||||
'''),
|
||||
"npm": ("render.mjs", "marked@15.0.12", "import {marked} from 'marked'; export async function render(input){return {html:marked(input.source)}}\n"),
|
||||
"pip": ("render.py", "Markdown@3.8.2", "import markdown\nasync def render(payload,setting):\n return {'html':markdown.markdown(payload['source'])}\n"),
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("mode", choices=["prepare", "verify"])
|
||||
parser.add_argument("--compiler", type=Path, required=True)
|
||||
parser.add_argument("--work", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
compiler = args.compiler.resolve(strict=True)
|
||||
work = args.work.absolute()
|
||||
if args.mode == "prepare":
|
||||
work.mkdir()
|
||||
for ecosystem, (filename, library, source) in BUSINESS.items():
|
||||
project = work / ecosystem
|
||||
domain = project / "module/demo/service"
|
||||
native = domain / "native"
|
||||
native.mkdir(parents=True)
|
||||
(native / filename).write_text(source)
|
||||
(domain / "port.dever").write_text("render(source:Text) (html:Text)\n")
|
||||
(domain / "adapter.dever").write_text(f'external {ecosystem} "native/{filename}" {{ lib "{library}" }}\n')
|
||||
(domain / "app").mkdir()
|
||||
(domain / "app/main.dever").write_text('flow start() (html:Text)\n| step | kind | do |\n| html | port | port.render("# Hello") |\n')
|
||||
(domain / "api.dever").write_text("cmd start = app.start\n")
|
||||
for command in ["fmt", "check"]:
|
||||
subprocess.run([compiler, command, project], check=True)
|
||||
subprocess.run([compiler, "lib", "install", project], check=True)
|
||||
return
|
||||
home = work / "verify-home"
|
||||
home.mkdir()
|
||||
environment = {"PATH": "/usr/bin:/bin", "HOME": str(home), "LANG": "C.UTF-8", "CARGO_BUILD_JOBS": "2",
|
||||
"HTTP_PROXY": "http://127.0.0.1:1", "HTTPS_PROXY": "http://127.0.0.1:1"}
|
||||
results = []
|
||||
for ecosystem in BUSINESS:
|
||||
source = work / ecosystem
|
||||
project = work / f"clean-{ecosystem}"
|
||||
project.mkdir()
|
||||
shutil.copytree(source / "module", project / "module")
|
||||
shutil.copyfile(source / "dever.lock", project / "dever.lock")
|
||||
assert not (project / "target").exists(), "source-only checkout must not need build state"
|
||||
binary = work / f"published-{ecosystem}"
|
||||
subprocess.run([compiler, "build", project, "--profile", "dev", "--output", binary],
|
||||
check=True, env=environment, cwd=home)
|
||||
hidden = work / f"source-unavailable-{ecosystem}"
|
||||
project.rename(hidden)
|
||||
try:
|
||||
output = subprocess.check_output([binary, "demo.service.start", "{}"], env=environment, cwd=home, text=True)
|
||||
assert json.loads(output)["data"].strip() == "<h1>Hello</h1>", output
|
||||
results.append(ecosystem)
|
||||
finally:
|
||||
hidden.rename(project)
|
||||
print(json.dumps({"offline_native_ecosystems": results, "empty_home": True, "source_removed_during_execution": True}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user