Squash commits for public release
This commit is contained in:
3
build/third_party/BUILD.gn
vendored
Normal file
3
build/third_party/BUILD.gn
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
group("third_party") {
|
||||
deps = [ "//build/third_party/tinysh:tinysh" ]
|
||||
}
|
||||
27
build/third_party/PY_BRIDGE.gni
vendored
Normal file
27
build/third_party/PY_BRIDGE.gni
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import("//build/userland/USERLAND_FLAGS.gni")
|
||||
import("//toolchains/COMPILERS.gni")
|
||||
|
||||
if (uland_ld_flags == []) {
|
||||
port_ld_flags = [ "__EMPTY__" ]
|
||||
} else {
|
||||
port_ld_flags = uland_ld_flags
|
||||
}
|
||||
|
||||
py_bridging_args = [
|
||||
# outpath here is inserted
|
||||
rebase_path("//", root_build_dir), # rootdir
|
||||
"$target_arch", # target cpu
|
||||
"$host", # host compiler
|
||||
string_join(" ",
|
||||
[
|
||||
toolchain_ar,
|
||||
toolchain_cc,
|
||||
toolchain_cxx,
|
||||
toolchain_ld,
|
||||
toolchain_asm,
|
||||
toolchain_target,
|
||||
]), # compiler_toolchain
|
||||
string_join(" ", uland_c_flags), # c_flags
|
||||
string_join(" ", uland_cc_flags), # cc_flags
|
||||
string_join(" ", port_ld_flags), # ld_flags
|
||||
]
|
||||
109
build/third_party/PortingTools.py
vendored
Normal file
109
build/third_party/PortingTools.py
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from git import Repo
|
||||
|
||||
|
||||
class PortTools:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def set_env(name, val):
|
||||
os.environ[name] = str(val)
|
||||
|
||||
@staticmethod
|
||||
def run_command_impl(cmd, cwd="."):
|
||||
result = subprocess.run(
|
||||
cmd, stdout=subprocess.PIPE, shell=True, cwd=cwd)
|
||||
return (result.stdout.decode("ascii"), result.returncode)
|
||||
|
||||
@staticmethod
|
||||
def run_command(cmd, cwd="."):
|
||||
return PortTools.run_command_impl(cmd, cwd)
|
||||
|
||||
@staticmethod
|
||||
def apply_patch(location, patch_name):
|
||||
src_dir = location+"/src"
|
||||
if not os.path.exists(src_dir):
|
||||
return ("", -1)
|
||||
|
||||
patch_path = location+"/patches/"+patch_name
|
||||
if not os.path.exists(patch_path):
|
||||
return ("", -1)
|
||||
|
||||
applied_patch_path = location+"/patches/.applied_"+patch_name
|
||||
if os.path.exists(applied_patch_path):
|
||||
return ("", 0)
|
||||
|
||||
cmd = ["patch"]
|
||||
myinput = open(patch_path)
|
||||
result = subprocess.run(
|
||||
cmd, stdin=myinput, stdout=subprocess.PIPE, cwd=src_dir)
|
||||
if result.returncode == 0:
|
||||
Path(applied_patch_path).touch()
|
||||
return (result.stdout.decode("ascii"), result.returncode)
|
||||
|
||||
@staticmethod
|
||||
def clone_git(location, url):
|
||||
src_dir = location+"/src"
|
||||
if os.path.exists(src_dir):
|
||||
return
|
||||
Repo.clone_from(url, src_dir)
|
||||
|
||||
|
||||
class StaticBuiler:
|
||||
def check_libs_present(self, lib_name):
|
||||
lib_desc = StaticBuiler.libs.get(lib_name, None)
|
||||
if lib_desc is None:
|
||||
return False
|
||||
|
||||
if not os.path.exists(lib_desc["bin"]):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def __init__(self, rootdir, srcdir, libs):
|
||||
self.rootdir = rootdir
|
||||
self.srcdir = srcdir
|
||||
self.target_libs = libs
|
||||
self.libs = {
|
||||
"libc": {
|
||||
"include": self.rootdir + "/libs/libc/include",
|
||||
"bin": self.rootdir + "/out/base/libs/",
|
||||
}
|
||||
}
|
||||
|
||||
def libs_include_flags(self):
|
||||
flags = ""
|
||||
for lib_name in self.target_libs:
|
||||
lib_desc = self.libs.get(lib_name, None)
|
||||
assert(lib_desc is not None)
|
||||
|
||||
flags += "-I"
|
||||
flags += lib_desc["include"] + " "
|
||||
return flags
|
||||
|
||||
def libs_link_flags(self):
|
||||
flags = " "
|
||||
for lib_name in self.target_libs:
|
||||
lib_desc = self.libs.get(lib_name, None)
|
||||
assert(lib_desc is not None)
|
||||
|
||||
flags += "-L"
|
||||
flags += lib_desc["bin"] + " "
|
||||
flags += "-l" + lib_name[3:] + " "
|
||||
return flags
|
||||
|
||||
def run_command(self, cmd_str):
|
||||
return PortTools.run_command(cmd_str, self.srcdir)
|
||||
|
||||
def move_exec(self, execname, targetdir):
|
||||
if not os.path.exists(targetdir):
|
||||
os.makedirs(targetdir)
|
||||
return self.run_command("mv {0} {1}".format(execname, targetdir))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
34
build/third_party/PyBridgingTools.py
vendored
Normal file
34
build/third_party/PyBridgingTools.py
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class PyBridgingTools:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def build_descriptor():
|
||||
# Fixup for runtime libs.
|
||||
ldflags = sys.argv[8] + " " if sys.argv[8] != "__EMPTY__" else ""
|
||||
ldflags = ldflags.replace("../toolchains/", "../../../toolchains/")
|
||||
|
||||
desc = {
|
||||
"outpath": os.path.abspath(sys.argv[1]),
|
||||
"rootdir": os.path.abspath(sys.argv[2]),
|
||||
"target_arch": sys.argv[3],
|
||||
"host": sys.argv[4],
|
||||
"toolchain": {
|
||||
"ar": sys.argv[5].split(" ")[0],
|
||||
"cc": sys.argv[5].split(" ")[1],
|
||||
"cxx": sys.argv[5].split(" ")[2],
|
||||
"ld": sys.argv[5].split(" ")[3],
|
||||
"asm": sys.argv[5].split(" ")[4],
|
||||
"target": sys.argv[5].split(" ")[5],
|
||||
},
|
||||
"c_flags": sys.argv[6] + " " if sys.argv[6] != "__EMPTY__" else "",
|
||||
"cc_flags": sys.argv[7] + " " if sys.argv[7] != "__EMPTY__" else "",
|
||||
"ld_flags": ldflags,
|
||||
}
|
||||
return desc
|
||||
11
build/third_party/tinysh/BUILD.gn
vendored
Normal file
11
build/third_party/tinysh/BUILD.gn
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import("//build/third_party/PY_BRIDGE.gni")
|
||||
|
||||
gnstate = [ rebase_path("$root_out_dir/base/bin/tinysh", root_build_dir) ] +
|
||||
py_bridging_args
|
||||
|
||||
action("tinysh") {
|
||||
script = "//build/third_party/tinysh/package.py"
|
||||
outputs = [ "$root_out_dir/base/bin/tinysh" ]
|
||||
args = gnstate
|
||||
deps = [ "//libs/libc:libc" ]
|
||||
}
|
||||
97
build/third_party/tinysh/package.py
vendored
Normal file
97
build/third_party/tinysh/package.py
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
# fmt: off
|
||||
import sys
|
||||
from os import path
|
||||
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
|
||||
from PortingTools import *
|
||||
from PyBridgingTools import *
|
||||
# fmt: on
|
||||
|
||||
state = PyBridgingTools.build_descriptor()
|
||||
|
||||
|
||||
class TinyshPackage:
|
||||
version = "1.0"
|
||||
name = "tinysh"
|
||||
exec_name = "simple-c-shell"
|
||||
rootdir = state["rootdir"]
|
||||
target_dir = state["rootdir"] + "/third_party/tinysh"
|
||||
url = "https://github.com/jmreyes/simple-c-shell.git"
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def clean(self):
|
||||
src_dir = self.target_dir + "/src"
|
||||
PortTools.run_command("rm -rf {0}".format(src_dir))
|
||||
|
||||
def has_build(self):
|
||||
cache_location = self.target_dir + \
|
||||
"/bin_{0}/".format(state['target_arch'])
|
||||
file_in_cache = cache_location + TinyshPackage.exec_name
|
||||
return os.path.exists(file_in_cache)
|
||||
|
||||
def download(self):
|
||||
PortTools.clone_git(self.target_dir, self.url)
|
||||
|
||||
def apply_patches(self):
|
||||
txt, err = PortTools.apply_patch(
|
||||
self.target_dir, "0001-llvm_support.patch")
|
||||
if err:
|
||||
print(txt)
|
||||
exit(1)
|
||||
txt, err = PortTools.apply_patch(
|
||||
self.target_dir, "0002-disable_unsupported.patch")
|
||||
if err:
|
||||
print(txt)
|
||||
exit(1)
|
||||
|
||||
def build(self):
|
||||
cache_location = self.target_dir + \
|
||||
"/bin_{0}/".format(state['target_arch'])
|
||||
file_in_cache = cache_location + TinyshPackage.exec_name
|
||||
if self.has_build():
|
||||
return
|
||||
|
||||
src_dir = self.target_dir + "/src"
|
||||
|
||||
builder = StaticBuiler(state["rootdir"], src_dir, libs=["libc"])
|
||||
PortTools.set_env("CC", state["toolchain"]["cc"])
|
||||
PortTools.set_env("LD", state["toolchain"]["ld"])
|
||||
|
||||
cflags = ""
|
||||
ldflags = ""
|
||||
if state["host"] == "llvm":
|
||||
cflags += "-target " + state["toolchain"]["target"] + " "
|
||||
|
||||
cflags += state["c_flags"]
|
||||
cflags += builder.libs_include_flags()
|
||||
PortTools.set_env("CFLAGS", cflags)
|
||||
|
||||
ldflags += state["ld_flags"]
|
||||
ldflags += builder.libs_link_flags()
|
||||
PortTools.set_env("LDFLAGS", ldflags)
|
||||
|
||||
_, err = builder.run_command(
|
||||
"make CC=\"$CC\" LD=\"$LD\" CFLAGS=\"$CFLAGS\" LDFLAGS=\"$LDFLAGS\"")
|
||||
if err:
|
||||
exit(1)
|
||||
|
||||
exepath = src_dir + "/" + TinyshPackage.exec_name
|
||||
builder.move_exec(exepath, cache_location)
|
||||
builder.run_command("make clean")
|
||||
|
||||
def bin_is_ready(self):
|
||||
cache_location = self.target_dir + \
|
||||
"/bin_{0}/".format(state['target_arch'])
|
||||
file_in_cache = cache_location + TinyshPackage.exec_name
|
||||
if os.path.exists(state["outpath"]):
|
||||
return
|
||||
os.symlink(file_in_cache, state["outpath"])
|
||||
|
||||
|
||||
package = TinyshPackage()
|
||||
if not package.has_build():
|
||||
package.download()
|
||||
package.apply_patches()
|
||||
package.build()
|
||||
package.bin_is_ready()
|
||||
Reference in New Issue
Block a user