mirror of
https://onedev.site.tesses.net/crosslang/crosslangextras
synced 2026-02-08 17:15:45 +00:00
Add publish to crosslang and add plugin_host support for packages
This commit is contained in:
46
Tesses.CrossLang.BuildEssentials/res/cml.txt
Normal file
46
Tesses.CrossLang.BuildEssentials/res/cml.txt
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(@<<short_name>>@)
|
||||||
|
|
||||||
|
option(@<<caps_version>>@_FETCHCONTENT "Whether to use fetchcontent" ON)
|
||||||
|
option(@<<caps_version>>@_SHARED_CROSSLANG "Whether to use shared crosslang" ON)
|
||||||
|
|
||||||
|
add_executable(@<<short_name>>@ src/main.cpp)
|
||||||
|
|
||||||
|
if(@<<caps_version>>@_FETCHCONTENT)
|
||||||
|
|
||||||
|
set(TESSESFRAMEWORK_ENABLE_EXAMPLES OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||||
|
set(TESSESFRAMEWORK_ENABLE_APPS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||||
|
|
||||||
|
set(TESSESFRAMEWORK_FETCHCONTENT ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||||
|
set(CROSSLANG_ENABLE_BINARIES OFF CACHE INTERNAL "For CrossLang" FORCE)
|
||||||
|
|
||||||
|
if(@<<caps_version>>@_SHARED_CROSSLANG)
|
||||||
|
set(TESSESFRAMEWORK_ENABLE_STATIC OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||||
|
set(TESSESFRAMEWORK_ENABLE_SHARED ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||||
|
else()
|
||||||
|
set(TESSESFRAMEWORK_ENABLE_STATIC ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||||
|
set(TESSESFRAMEWORK_ENABLE_SHARED OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||||
|
endif()
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
TessesCrossLang
|
||||||
|
GIT_REPOSITORY https://onedev.site.tesses.net/crosslang.git
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(TessesCrossLang)
|
||||||
|
if(@<<caps_version>>@_SHARED_CROSSLANG)
|
||||||
|
target_link_libraries(@<<short_name>>@ PUBLIC crosslang_shared)
|
||||||
|
else()
|
||||||
|
target_link_libraries(@<<short_name>>@ PUBLIC crosslang_static)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
find_package(TessesCrossLang REQUIRED)
|
||||||
|
if(@<<caps_version>>@_SHARED_CROSSLANG)
|
||||||
|
target_link_libraries(@<<short_name>>@ PUBLIC TessesCrossLang::crosslang_shared)
|
||||||
|
else()
|
||||||
|
target_link_libraries(@<<short_name>>@ PUBLIC TessesCrossLang::crosslang_static)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
install(TARGETS @<<short_name>>@ DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||||
|
|
||||||
76
Tesses.CrossLang.BuildEssentials/res/cppfiletemplate.cpp
Normal file
76
Tesses.CrossLang.BuildEssentials/res/cppfiletemplate.cpp
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#include <CrossLang.hpp>
|
||||||
|
#include "@<<HEADER>>@.h"
|
||||||
|
using namespace Tesses::Framework;
|
||||||
|
using namespace Tesses::CrossLang;
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
std::string name = argv[0];
|
||||||
|
Tesses::Framework::Filesystem::LocalFilesystem fs;
|
||||||
|
Tesses::Framework::Filesystem::VFSPath exePath=fs.SystemToVFSPath(name);
|
||||||
|
exePath.MakeAbsolute();
|
||||||
|
|
||||||
|
|
||||||
|
TF_InitWithConsole();
|
||||||
|
|
||||||
|
GC gc;
|
||||||
|
gc.Start();
|
||||||
|
GCList ls(gc);
|
||||||
|
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||||
|
|
||||||
|
TStd::RegisterStd(&gc,env);
|
||||||
|
{
|
||||||
|
auto ms = std::shared_ptr<Tesses::Framework::Streams::MemoryStream>(false);
|
||||||
|
auto& buff = ms->GetBuffer();
|
||||||
|
buff.resize(@<<CAPS_VERSION>>@_length);
|
||||||
|
memcpy(buff.data(),@<<CAPS_VERSION>>@_data,@<<CAPS_VERSION>>@_length);
|
||||||
|
auto file = TFile::Create(ls);
|
||||||
|
file->Load(&gc, &ms);
|
||||||
|
env->LoadFile(&gc,file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(env->HasVariable("WebAppMain"))
|
||||||
|
{
|
||||||
|
Args args(argc, argv);
|
||||||
|
int port = 4206;
|
||||||
|
for(auto& item : args.options)
|
||||||
|
{
|
||||||
|
if(item.first == "port")
|
||||||
|
{
|
||||||
|
port = std::stoi(item.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TList* args2 = TList::Create(ls);
|
||||||
|
args2->Add(exePath.ToString());
|
||||||
|
for(auto& item : args.positional)
|
||||||
|
{
|
||||||
|
args2->Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto res = env->CallFunction(ls, "WebAppMain", {args2});
|
||||||
|
TObjectHttpServer http(&gc, res);
|
||||||
|
Tesses::Framework::Http::HttpServer svr(port,http,false);
|
||||||
|
|
||||||
|
svr.StartAccepting();
|
||||||
|
TF_RunEventLoop();
|
||||||
|
TDictionary* _dict;
|
||||||
|
if(GetObjectHeap(res,_dict))
|
||||||
|
{
|
||||||
|
_dict->CallMethod(ls,"Close",{});
|
||||||
|
}
|
||||||
|
TF_Quit();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TList* args = TList::Create(ls);
|
||||||
|
args->Add(exePath.ToString());
|
||||||
|
for(int arg=1;arg<argc;arg++)
|
||||||
|
args->Add(argv[arg]);
|
||||||
|
auto res = env->CallFunction(ls,"main",{args});
|
||||||
|
int64_t iresult;
|
||||||
|
if(GetObject(res,iresult))
|
||||||
|
return (int)iresult;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -10,9 +10,9 @@ class Tesses.CrossLang.PackageManager
|
|||||||
public PackageManager()
|
public PackageManager()
|
||||||
{
|
{
|
||||||
this.configRoot = Env.CrossLangConfig;
|
this.configRoot = Env.CrossLangConfig;
|
||||||
this.packageCache = configRoot / "PackageCache";
|
this.packageCache = this.configRoot / "PackageCache";
|
||||||
|
|
||||||
FS.Local.CreateDirectory(packageCache);
|
FS.Local.CreateDirectory(this.packageCache);
|
||||||
}
|
}
|
||||||
/^ Parse package filename ^/
|
/^ Parse package filename ^/
|
||||||
public ParseFileName(name)
|
public ParseFileName(name)
|
||||||
@@ -60,6 +60,7 @@ class Tesses.CrossLang.PackageManager
|
|||||||
var v = Version.Parse(version);
|
var v = Version.Parse(version);
|
||||||
var useCache = v.Stage != "dev";
|
var useCache = v.Stage != "dev";
|
||||||
var pkgFile = packageCache / name / v.ToString();
|
var pkgFile = packageCache / name / v.ToString();
|
||||||
|
|
||||||
if(useCache && FS.Local.RegularFileExists(pkgFile))
|
if(useCache && FS.Local.RegularFileExists(pkgFile))
|
||||||
{
|
{
|
||||||
return FS.ReadAllBytes(FS.Local,pkgFile);
|
return FS.ReadAllBytes(FS.Local,pkgFile);
|
||||||
|
|||||||
248
Tesses.CrossLang.BuildEssentials/src/Publisher.tcross
Normal file
248
Tesses.CrossLang.BuildEssentials/src/Publisher.tcross
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
class Tesses.CrossLang.Publisher
|
||||||
|
{
|
||||||
|
public Publisher(builder,project_dir)
|
||||||
|
{
|
||||||
|
|
||||||
|
this.ProjectBuilder = builder;
|
||||||
|
this.ProjectDirectory = project_dir;
|
||||||
|
this.ProjectInfo = Json.Decode(FS.ReadAllText(FS.Local, project_dir / "cross.json"));
|
||||||
|
}
|
||||||
|
/^
|
||||||
|
The project directory to publish
|
||||||
|
^/
|
||||||
|
public ProjectDirectory;
|
||||||
|
|
||||||
|
/^
|
||||||
|
The project builder
|
||||||
|
^/
|
||||||
|
public ProjectBuilder;
|
||||||
|
/^
|
||||||
|
The project cross.json contents
|
||||||
|
^/
|
||||||
|
public ProjectInfo;
|
||||||
|
|
||||||
|
|
||||||
|
/^
|
||||||
|
Where we output the published files
|
||||||
|
If null (which is default) we output at ProjectDirectory / "publish" / RuntimeIdentifier
|
||||||
|
^/
|
||||||
|
public OutputDirectory = null;
|
||||||
|
/^
|
||||||
|
The runtime identifier
|
||||||
|
|
||||||
|
builtins:
|
||||||
|
"crvm" (merge to one crvm)
|
||||||
|
"header" (merge to one crvm and generate C header)
|
||||||
|
"cmake" (merge to one crvm and generate C header and create a cmake project)
|
||||||
|
|
||||||
|
actual runtimes can be found here: https://cpkg.tesseslanguage.com/packages?q=Tesses.CrossLang.Runtime. (you need to strip the Tesses.CrossLang.Runtime. from the names)
|
||||||
|
|
||||||
|
^/
|
||||||
|
public RuntimeIdentifier="crvm";
|
||||||
|
/^
|
||||||
|
The prefix of the package (to prepend onto runtime identifier, we put the trailing period for you)
|
||||||
|
^/
|
||||||
|
public PackagePrefix = "Tesses.CrossLang.Runtime";
|
||||||
|
/^
|
||||||
|
Merge for runtimes (one crvm file)
|
||||||
|
^/
|
||||||
|
public MergeForRuntimes = false;
|
||||||
|
|
||||||
|
private Build()
|
||||||
|
{
|
||||||
|
var out = this.ProjectBuilder.BuildProject(this.ProjectDirectory).Output;
|
||||||
|
return FS.MakeFull(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Merge()
|
||||||
|
{
|
||||||
|
var path = this.Build();
|
||||||
|
var objDir = "obj";
|
||||||
|
if(TypeOf(ProjectInfo.obj_directory) == "String")
|
||||||
|
objDir = ProjectInfo.obj_directory;
|
||||||
|
|
||||||
|
var packPath = this.ProjectDirectory / objDir / "merge";
|
||||||
|
if(packPath.Count > 0 && FS.Local.DirectoryExists(packPath))
|
||||||
|
{
|
||||||
|
FS.Local.DeleteDirectoryRecurse(packPath);
|
||||||
|
}
|
||||||
|
FS.Local.CreateDirectory(packPath);
|
||||||
|
|
||||||
|
var pack_dir = new SubdirFilesystem(FS.Local, packPath);
|
||||||
|
|
||||||
|
return packPath / VM.Merge(FS.Local,path,pack_dir);
|
||||||
|
}
|
||||||
|
private CopyBuild(destPath)
|
||||||
|
{
|
||||||
|
func CopyCRVM(src,dest)
|
||||||
|
{
|
||||||
|
func copyFile(src,dest)
|
||||||
|
{
|
||||||
|
var _src = FS.Local.OpenFile(src,"rb");
|
||||||
|
var _dest = FS.Local.OpenFile(dest, "wb");
|
||||||
|
_src.CopyTo(_dest);
|
||||||
|
_src.Close();
|
||||||
|
_dest.Close();
|
||||||
|
Console.WriteLine($"{src} -> {dest}");
|
||||||
|
}
|
||||||
|
if(FS.Local.FileExists(dest)) return;
|
||||||
|
copyFile(src,dest);
|
||||||
|
|
||||||
|
|
||||||
|
var srcStrm = FS.Local.OpenFile(src,"rb");
|
||||||
|
var crvm = VM.LoadExecutable(srcStrm);
|
||||||
|
|
||||||
|
srcStrm.Close();
|
||||||
|
each(var dep : crvm.Dependencies)
|
||||||
|
{
|
||||||
|
var name = $"{dep.Name}-{dep.Version.ToString()}.crvm";
|
||||||
|
CopyCRVM(src.GetParent()/name, dest.GetParent()/name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CopyCRVM(this.Build(), destPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CreateCMake(dir, short_name)
|
||||||
|
{
|
||||||
|
FS.Local.CreateDirectory(dir / "src");
|
||||||
|
var path = this.Merge();
|
||||||
|
var bytes = FS.ReadAllBytes(FS.Local, path);
|
||||||
|
var caps_version = this.FixCHeaderName(short_name);
|
||||||
|
|
||||||
|
FS.WriteAllText(FS.Local, dir / "src" / $"{short_name}.h", bytes.ToCHeaderFile(caps_version));
|
||||||
|
|
||||||
|
if(!FS.Local.RegularFileExists(dir / "CMakeLists.txt"))
|
||||||
|
{
|
||||||
|
var cmake_file = embed("cml.txt").ToString().Replace("@<<caps_version>>@",caps_version).Replace("@<<short_name>>@",short_name);
|
||||||
|
FS.WriteAllText(FS.Local,dir / "CMakeLists.txt", cmake_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!FS.Local.RegularFileExists(dir / "src"/"main.cpp"))
|
||||||
|
{
|
||||||
|
|
||||||
|
var cppFile = embed("cppfiletemplate.cpp").ToString().Replace("@<<CAPS_VERSION>>@", caps_version).Replace("@<<HEADER>>@",short_name);
|
||||||
|
|
||||||
|
FS.WriteAllText(FS.Local,dir / "src"/"main.cpp", cppFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CopyFile(src,dest)
|
||||||
|
{
|
||||||
|
var srcStrm = FS.Local.OpenFile(src,"rb");
|
||||||
|
var destStrm = FS.Local.OpenFile(dest, "wb");
|
||||||
|
|
||||||
|
srcStrm.CopyTo(destStrm);
|
||||||
|
srcStrm.Close();
|
||||||
|
destStrm.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private FixCHeaderName(name)
|
||||||
|
{
|
||||||
|
var myStr = name.ToUpper();
|
||||||
|
name = "";
|
||||||
|
each(var item : myStr)
|
||||||
|
{
|
||||||
|
if((item >= 'A' && item <= 'Z') || (item >= '0' && item <= '9') || item == '_')
|
||||||
|
name += item;
|
||||||
|
}
|
||||||
|
if(name.Length == 0) return "NONAME";
|
||||||
|
else if(name[0] >= '0' && name[0] <= '9')
|
||||||
|
return $"_{name}";
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/^ Start the publishing process ^/
|
||||||
|
public Publish()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var outDir = TypeOf(this.OutputDirectory) == "Null" ? (this.ProjectDirectory / "publish" / this.RuntimeIdentifier) : this.OutputDirectory;
|
||||||
|
var short_name = TypeOf(this.ProjectInfo.info.short_name) == "String" ? this.ProjectInfo.info.short_name : this.ProjectInfo.name;
|
||||||
|
|
||||||
|
FS.Local.CreateDirectory(outDir);
|
||||||
|
|
||||||
|
switch(this.RuntimeIdentifier)
|
||||||
|
{
|
||||||
|
case "crvm":
|
||||||
|
{
|
||||||
|
var path = this.Merge();
|
||||||
|
FS.Local.MoveFile(path, outDir / $"{short_name}.crvm");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "header":
|
||||||
|
{
|
||||||
|
var path = this.Merge();
|
||||||
|
var bytes = FS.ReadAllBytes(FS.Local, path);
|
||||||
|
FS.WriteAllText(FS.Local, outDir / $"{short_name}.h", bytes.ToCHeaderFile(this.FixCHeaderName(short_name)));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "cmake":
|
||||||
|
{
|
||||||
|
this.CreateCMake(outDir, short_name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
var runtimePackageName = this.PackagePrefix;
|
||||||
|
|
||||||
|
if(runtimePackageName.Count > 0 && !runtimePackageName.EndsWith('.'))
|
||||||
|
runtimePackageName += ".";
|
||||||
|
|
||||||
|
runtimePackageName += this.RuntimeIdentifier;
|
||||||
|
|
||||||
|
var version = this.ProjectBuilder.PackageManager.GetLatest(runtimePackageName);
|
||||||
|
if(TypeOf(version) != "String")
|
||||||
|
{
|
||||||
|
throw {
|
||||||
|
Type="PackageNotFoundException",
|
||||||
|
Message=$"Could not find package {runtimePackageName}.",
|
||||||
|
ToString=(this)=>$"{this.Type} on line: {this.Line} {this.Message}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var pkgObj = this.ProjectBuilder.PackageManager.GetPackage(runtimePackageName, version);
|
||||||
|
var strm = new MemoryStream(true);
|
||||||
|
strm.WriteBlock(pkgObj,0,pkgObj.Length);
|
||||||
|
strm.Seek(0,0);
|
||||||
|
var sdfs = new SubdirFilesystem(FS.Local, outDir);
|
||||||
|
var archiveResponse = FS.ExtractArchive(strm,sdfs);
|
||||||
|
sdfs.Close();
|
||||||
|
|
||||||
|
var archiveInfo = Json.Decode(archiveResponse.Info);
|
||||||
|
|
||||||
|
if(archiveInfo.executable_can_be_renamed)
|
||||||
|
{
|
||||||
|
var executable_name_path = /archiveInfo.executable_name;
|
||||||
|
var executable_extension = executable_name_path.GetExtension();
|
||||||
|
var newName = outDir/short_name;
|
||||||
|
if(executable_extension.Length > 0) newName += executable_extension;
|
||||||
|
|
||||||
|
FS.Local.MoveFile(outDir/archiveInfo.executable_name,newName);
|
||||||
|
FS.Local.Chmod(newName, 0755);
|
||||||
|
if(this.MergeForRuntimes)
|
||||||
|
{
|
||||||
|
FS.Local.MoveFile(this.Merge(), outDir / short_name + ".crvm");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.CopyBuild(outDir / short_name + ".crvm");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var executable_name_path = /archiveInfo.executable_name;
|
||||||
|
FS.Local.Chmod(outDir/archiveInfo.executable_name, 0755);
|
||||||
|
var executable_name_no_ext = executable_name_path.ChangeExtension(null).GetFileName();
|
||||||
|
if(this.MergeForRuntimes)
|
||||||
|
{
|
||||||
|
FS.Local.MoveFile(this.Merge(), outDir / executable_name_no_ext + ".crvm");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.CopyBuild(outDir / executable_name_no_ext + ".crvm");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,16 +4,16 @@ class Tesses.CrossLang.BuildTool
|
|||||||
/^ Construct the build tool with Package Manager ^/
|
/^ Construct the build tool with Package Manager ^/
|
||||||
public BuildTool(pm)
|
public BuildTool(pm)
|
||||||
{
|
{
|
||||||
this.PacakgeManager = pm;
|
this.PackageManager = pm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private copyFile(src,dest)
|
private copyFile(src,dest)
|
||||||
{
|
{
|
||||||
var src = FS.Local.OpenFile(src,"rb");
|
var srcStrm = FS.Local.OpenFile(src,"rb");
|
||||||
var dest = FS.Local.OpenFile(dest, "wb");
|
var destStrm = FS.Local.OpenFile(dest, "wb");
|
||||||
src.CopyTo(dest);
|
srcStrm.CopyTo(destStrm);
|
||||||
src.Close();
|
srcStrm.Close();
|
||||||
dest.Close();
|
destStrm.Close();
|
||||||
}
|
}
|
||||||
/^ Package Manager Object ^/
|
/^ Package Manager Object ^/
|
||||||
public PackageManager;
|
public PackageManager;
|
||||||
@@ -22,9 +22,10 @@ class Tesses.CrossLang.BuildTool
|
|||||||
/^ Get the dependencies (don't use this directly unless you know what you are doing) ^/
|
/^ Get the dependencies (don't use this directly unless you know what you are doing) ^/
|
||||||
public GetPackageDependencies(name, version, dir)
|
public GetPackageDependencies(name, version, dir)
|
||||||
{
|
{
|
||||||
var dep = PackageManager.GetPackage(name,version);
|
var dep = this.PackageManager.GetPackage(name,version);
|
||||||
if(TypeOf(dep) == "Null") throw $"Package {name} with version {version} does not exist";
|
if(TypeOf(dep) == "Null") throw $"Package {name} with version {version} does not exist";
|
||||||
|
|
||||||
|
|
||||||
var pkgPath = dir / $"{name}-{version}.crvm";
|
var pkgPath = dir / $"{name}-{version}.crvm";
|
||||||
|
|
||||||
var strm = FS.Local.OpenFile(pkgPath,"wb");
|
var strm = FS.Local.OpenFile(pkgPath,"wb");
|
||||||
@@ -102,7 +103,7 @@ class Tesses.CrossLang.BuildTool
|
|||||||
outputDir = configData.bin_directory;
|
outputDir = configData.bin_directory;
|
||||||
|
|
||||||
if(TypeOf(configData.obj_directory) != "Undefined")
|
if(TypeOf(configData.obj_directory) != "Undefined")
|
||||||
outputDir = configData.obj_directory;
|
objDir = configData.obj_directory;
|
||||||
if(TypeOf(configData.source_directory) != "Undefined")
|
if(TypeOf(configData.source_directory) != "Undefined")
|
||||||
srcDir = configData.source_directory;
|
srcDir = configData.source_directory;
|
||||||
if(TypeOf(configData.resource_directory) != "Undefined")
|
if(TypeOf(configData.resource_directory) != "Undefined")
|
||||||
@@ -185,7 +186,7 @@ class Tesses.CrossLang.BuildTool
|
|||||||
FS.Local.CreateDirectory(newDir);
|
FS.Local.CreateDirectory(newDir);
|
||||||
var newFile = newDir / $"{item.Name}-{item.Version}.crvm";
|
var newFile = newDir / $"{item.Name}-{item.Version}.crvm";
|
||||||
|
|
||||||
copyFile(item.Output, newFile);
|
this.copyFile(item.Output, newFile);
|
||||||
each(var item2 : item.Dependencies)
|
each(var item2 : item.Dependencies)
|
||||||
{
|
{
|
||||||
walk_for_compiling(item2, newDir);
|
walk_for_compiling(item2, newDir);
|
||||||
@@ -205,7 +206,7 @@ class Tesses.CrossLang.BuildTool
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
copyFile(item.Output, dir2 / $"{item.Name}-{item.Version}.crvm");
|
this.copyFile(item.Output, dir2 / $"{item.Name}-{item.Version}.crvm");
|
||||||
each(var item2 : item.Dependencies)
|
each(var item2 : item.Dependencies)
|
||||||
{
|
{
|
||||||
walk_for_compiling(item2, dir2);
|
walk_for_compiling(item2, dir2);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func DB.Init(working)
|
|||||||
|
|
||||||
var dbCon = DB.Open();
|
var dbCon = DB.Open();
|
||||||
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS packages (id INTEGER PRIMARY KEY AUTOINCREMENT, packageName TEXT UNIQUE, accountId INTEGER);");
|
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS packages (id INTEGER PRIMARY KEY AUTOINCREMENT, packageName TEXT UNIQUE, accountId INTEGER);");
|
||||||
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT, uploadTime INTEGER);");
|
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT, uploadTime INTEGER, pluginHost TEXT);");
|
||||||
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT UNIQUE, accountName TEXT UNIQUE, password_hash TEXT, password_salt TEXT, motto TEXT, verifyKey TEXT UNIQUE, verifyExpire INTEGER, flags INTEGER);");
|
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT UNIQUE, accountName TEXT UNIQUE, password_hash TEXT, password_salt TEXT, motto TEXT, verifyKey TEXT UNIQUE, verifyExpire INTEGER, flags INTEGER);");
|
||||||
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, accountId INTEGER, key STRING UNIQUE);");
|
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, accountId INTEGER, key STRING UNIQUE);");
|
||||||
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS reserved_prefixes (id INTEGER PRIMARY KEY AUTOINCREMENT, accountId INTEGER, prefix STRING UNIQUE);");
|
Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS reserved_prefixes (id INTEGER PRIMARY KEY AUTOINCREMENT, accountId INTEGER, prefix STRING UNIQUE);");
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ func DB.GetPackageVersions(name)
|
|||||||
var list = [];
|
var list = [];
|
||||||
each(var item : res)
|
each(var item : res)
|
||||||
{
|
{
|
||||||
|
var pluginHost = item.pluginHost;
|
||||||
|
if(TypeOf(pluginHost) != "String") pluginHost = "";
|
||||||
var version = Version.FromLong(ParseLong(item.version)).ToString();
|
var version = Version.FromLong(ParseLong(item.version)).ToString();
|
||||||
var uploadTime = ParseLong(item.uploadTime);
|
var uploadTime = ParseLong(item.uploadTime);
|
||||||
list.Add({
|
list.Add({
|
||||||
@@ -39,6 +41,7 @@ func DB.GetPackageVersions(name)
|
|||||||
license = item.license,
|
license = item.license,
|
||||||
uploadTime,
|
uploadTime,
|
||||||
uploadDate=new DateTime(uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")
|
uploadDate=new DateTime(uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")
|
||||||
|
pluginHost
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@@ -63,7 +66,9 @@ func DB.UpdateVersion(pkgInfo)
|
|||||||
var homepage = info.homepage;
|
var homepage = info.homepage;
|
||||||
var repo = info.repo;
|
var repo = info.repo;
|
||||||
var license = info.license;
|
var license = info.license;
|
||||||
|
var pluginHost = info.plugin_host;
|
||||||
if(TypeOf(description) != "String") description="";
|
if(TypeOf(description) != "String") description="";
|
||||||
|
if(TypeOf(pluginHost) != "String") pluginHost = "";
|
||||||
|
|
||||||
if(TypeOf(type) != "String") type="";
|
if(TypeOf(type) != "String") type="";
|
||||||
|
|
||||||
@@ -77,7 +82,7 @@ func DB.UpdateVersion(pkgInfo)
|
|||||||
|
|
||||||
//CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT);
|
//CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT);
|
||||||
//VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)});
|
//VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)});
|
||||||
Sqlite.Exec(dbCon,$"UPDATE versions SET description = {Sqlite.Escape(description)}, type = {Sqlite.Escape(type)}, maintainer = {Sqlite.Escape(maintainer)}, homepage = {Sqlite.Escape(homepage)}, repo = {Sqlite.Escape(repo)}, license = {Sqlite.Escape(license)}, uploadTime = {DateTime.NowEpoch} WHERE packageId = {pkgId} AND version = {version};");
|
Sqlite.Exec(dbCon,$"UPDATE versions SET pluginHost = {Sqlite.Escape(pluginHost)}, description = {Sqlite.Escape(description)}, type = {Sqlite.Escape(type)}, maintainer = {Sqlite.Escape(maintainer)}, homepage = {Sqlite.Escape(homepage)}, repo = {Sqlite.Escape(repo)}, license = {Sqlite.Escape(license)}, uploadTime = {DateTime.NowEpoch} WHERE packageId = {pkgId} AND version = {version};");
|
||||||
Sqlite.Close(dbCon);
|
Sqlite.Close(dbCon);
|
||||||
DB.Unlock();
|
DB.Unlock();
|
||||||
|
|
||||||
@@ -101,6 +106,8 @@ func DB.AddVersion(pkgInfo)
|
|||||||
var homepage = info.homepage;
|
var homepage = info.homepage;
|
||||||
var repo = info.repo;
|
var repo = info.repo;
|
||||||
var license = info.license;
|
var license = info.license;
|
||||||
|
var pluginHost = info.plugin_host;
|
||||||
|
if(TypeOf(pluginHost) != "String") pluginHost = "";
|
||||||
if(TypeOf(description) != "String") description="";
|
if(TypeOf(description) != "String") description="";
|
||||||
|
|
||||||
if(TypeOf(type) != "String") type="";
|
if(TypeOf(type) != "String") type="";
|
||||||
@@ -115,7 +122,7 @@ func DB.AddVersion(pkgInfo)
|
|||||||
|
|
||||||
//CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT);
|
//CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT);
|
||||||
|
|
||||||
Sqlite.Exec(dbCon,$"INSERT INTO versions (packageId,version,description,type,maintainer,homepage,repo,license,uploadTime) VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)},{DateTime.NowEpoch});");
|
Sqlite.Exec(dbCon,$"INSERT INTO versions (packageId,version,description,type,maintainer,homepage,repo,license,uploadTime,pluginHost) VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)},{DateTime.NowEpoch},Sqlite.Escape(pluginHost));");
|
||||||
Sqlite.Close(dbCon);
|
Sqlite.Close(dbCon);
|
||||||
DB.Unlock();
|
DB.Unlock();
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ func Pages.Package(ctx,name)
|
|||||||
<li>Last updated: {new DateTime(package[0].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}</li>
|
<li>Last updated: {new DateTime(package[0].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}</li>
|
||||||
<li>Latest version: {package[0].version}</li>
|
<li>Latest version: {package[0].version}</li>
|
||||||
<li>Type: {package[0].type}</li>
|
<li>Type: {package[0].type}</li>
|
||||||
|
<if(packages[0].pluginHost.Length>0)>
|
||||||
|
<true>
|
||||||
|
<li>PluginHost: {package[0].pluginHost}</li>
|
||||||
|
</true>
|
||||||
|
</if>
|
||||||
<li><a href={package[0].download}>Download</a></li>
|
<li><a href={package[0].download}>Download</a></li>
|
||||||
<li><a href={package[0].docs}>View Docs</a></li>
|
<li><a href={package[0].docs}>View Docs</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -153,6 +158,11 @@ func Pages.Package(ctx,name)
|
|||||||
</if>
|
</if>
|
||||||
<li>Uploaded: {new DateTime(package[i].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}</li>
|
<li>Uploaded: {new DateTime(package[i].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}</li>
|
||||||
<li>Type: {package[i].type}</li>
|
<li>Type: {package[i].type}</li>
|
||||||
|
<if(packages[i].pluginHost.Length>0)>
|
||||||
|
<true>
|
||||||
|
<li>PluginHost: {package[i].pluginHost}</li>
|
||||||
|
</true>
|
||||||
|
</if>
|
||||||
<li><a href={package[i].download}>Download</a></li>
|
<li><a href={package[i].download}>Download</a></li>
|
||||||
|
|
||||||
<li><a href={package[i].docs}>View Docs</a></li>
|
<li><a href={package[i].docs}>View Docs</a></li>
|
||||||
|
|||||||
@@ -71,13 +71,19 @@ func main(args)
|
|||||||
}
|
}
|
||||||
if(ctx.Path == "/api/v1/search")
|
if(ctx.Path == "/api/v1/search")
|
||||||
{
|
{
|
||||||
var filter = ctx.QueryParams.TryGetFirst("filter");
|
var filter = "";
|
||||||
if(TypeOf(filter) != "String") filter = "";
|
var type = ctx.QueryParams.TryGetFirst("type");
|
||||||
var filters = filter.Length > 0 ? filter.Split(",") : [];
|
if(TypeOf(type) != "String") type = "";
|
||||||
|
var types = type.Length > 0 ? type.Split(",") : [];
|
||||||
|
|
||||||
if(filters.Length > 0)
|
var pluginHost = ctx.QueryParams.TryGetFirst("pluginHost");
|
||||||
|
if(TypeOf(pluginHost) == "String")
|
||||||
{
|
{
|
||||||
filter = " AND (";
|
filter += $" AND v.pluginHost = {Sqlite.Escape(pluginHost)}";
|
||||||
|
}
|
||||||
|
if(types.Length > 0)
|
||||||
|
{
|
||||||
|
filter += " AND (";
|
||||||
var first = true;
|
var first = true;
|
||||||
each(var item : filters)
|
each(var item : filters)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ func main(args)
|
|||||||
case "docs":
|
case "docs":
|
||||||
return Tesses.CrossLang.Shell.Docs(dd);
|
return Tesses.CrossLang.Shell.Docs(dd);
|
||||||
break;
|
break;
|
||||||
|
case "publish":
|
||||||
|
return Tesses.CrossLang.Shell.Publish(dd);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return Tesses.CrossLang.Shell.Default(dd);
|
return Tesses.CrossLang.Shell.Default(dd);
|
||||||
}
|
}
|
||||||
|
|||||||
80
Tesses.CrossLang.Shell/src/publish.tcross
Normal file
80
Tesses.CrossLang.Shell/src/publish.tcross
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
func Tesses.CrossLang.Shell.Publish(dd)
|
||||||
|
{
|
||||||
|
var offline=false;
|
||||||
|
var allowFullCompTime=false;
|
||||||
|
var buildPath = ".";
|
||||||
|
var merge=false;
|
||||||
|
var packagePrefix = "Tesses.CrossLang.Runtime";
|
||||||
|
var out = null;
|
||||||
|
var identifier = "crvm";
|
||||||
|
if(dd.Arguments.Count > 1)
|
||||||
|
{
|
||||||
|
identifier = dd.Arguments[1];
|
||||||
|
if(dd.Arguments.Length > 2)
|
||||||
|
{
|
||||||
|
buildPath = dd.Arguments[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
each(var flag : dd.Flags)
|
||||||
|
{
|
||||||
|
if(flag == "offline")
|
||||||
|
{
|
||||||
|
offline = true;
|
||||||
|
}
|
||||||
|
if(flag == "allow-insecure-comptime")
|
||||||
|
{
|
||||||
|
allowFullCompTime=true;
|
||||||
|
}
|
||||||
|
if(flag == "merge")
|
||||||
|
{
|
||||||
|
merge = true;
|
||||||
|
}
|
||||||
|
if(flag == "help")
|
||||||
|
{
|
||||||
|
Console.WriteLine("USAGE: crosslang publish [publish-flags-and-options] identifier projectDir");
|
||||||
|
Console.WriteLine("FLAGS:");
|
||||||
|
Console.WriteLine("offline: build with no internet (don't fetch files)");
|
||||||
|
Console.WriteLine("help: this help");
|
||||||
|
Console.WriteLine("allow-insecure-comptime: Allow full comptime");
|
||||||
|
Console.WriteLine("merge: Merge the crvms into one (when bundling a runtime)");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("OPTIONS:");
|
||||||
|
Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config");
|
||||||
|
Console.WriteLine("runtime-package-prefix=PREFIX: prefix the identifier (defaults to Tesses.CrossLang.Runtime, we add the dot automaticly unless you provide empty string)");
|
||||||
|
Console.WriteLine("out=DIR: where to output the published artifact, defaults to projectDir/publish/identifier");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var conf = "";
|
||||||
|
each(var option : dd.Options)
|
||||||
|
{
|
||||||
|
if(option.Key == "conf")
|
||||||
|
{
|
||||||
|
conf = option.Value;
|
||||||
|
}
|
||||||
|
if(option.Key == "runtime-package-prefix")
|
||||||
|
{
|
||||||
|
packagePrefix = option.Value;
|
||||||
|
}
|
||||||
|
if(option.Key == "out")
|
||||||
|
{
|
||||||
|
out = option.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var pm = new Tesses.CrossLang.PackageManager();
|
||||||
|
pm.Offline = offline;
|
||||||
|
var bt = new Tesses.CrossLang.BuildTool(pm);
|
||||||
|
bt.Config = conf;
|
||||||
|
bt.AllowFullCompTime = allowFullCompTime;
|
||||||
|
var publisher = new Tesses.CrossLang.Publisher(bt, FS.MakeFull(buildPath));
|
||||||
|
publisher.OutputDirectory = out;
|
||||||
|
publisher.RuntimeIdentifier = identifier;
|
||||||
|
publisher.PackagePrefix = packagePrefix;
|
||||||
|
publisher.MergeForRuntimes = merge;
|
||||||
|
|
||||||
|
publisher.Publish();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ func cmd(name, args)
|
|||||||
func main(args)
|
func main(args)
|
||||||
{
|
{
|
||||||
|
|
||||||
var args2=["-o","./Tesses.CrossLang.BuildEssentials/bin-tmp","-n","Tesses.CrossLang.BuildEssentials","-v","1.0.0.0-prod","Tesses.CrossLang.BuildEssentials/main.tcross"];
|
var args2=["-o","./Tesses.CrossLang.BuildEssentials/bin-tmp","-r","./Tesses.CrossLang.BuildEssentials/res","-n","Tesses.CrossLang.BuildEssentials","-v","1.0.0.0-prod","Tesses.CrossLang.BuildEssentials/main.tcross"];
|
||||||
each(var f : FS.Local.EnumeratePaths("./Tesses.CrossLang.BuildEssentials/src"))
|
each(var f : FS.Local.EnumeratePaths("./Tesses.CrossLang.BuildEssentials/src"))
|
||||||
{
|
{
|
||||||
if(f.GetExtension() == ".tcross")
|
if(f.GetExtension() == ".tcross")
|
||||||
|
|||||||
Reference in New Issue
Block a user