1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

feat: Adaptations to support OpenBSD port (#19153)

This commit is contained in:
VlkrS 2023-06-12 12:14:27 +02:00 committed by GitHub
parent 7f15126f23
commit ea97af312f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 188 additions and 4 deletions

View file

@ -244,7 +244,7 @@ function createByteStruct(types) {
// types can be "date", "bool" or "u64".
let offset = 0;
let str =
'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux"; return {';
'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux" || Deno.build.os === "openbsd" || Deno.build.os === "freebsd"; return {';
const typeEntries = ObjectEntries(types);
for (let i = 0; i < typeEntries.length; ++i) {
let { 0: name, 1: type } = typeEntries[i];
@ -309,7 +309,8 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
});
function parseFileInfo(response) {
const unix = core.build.os === "darwin" || core.build.os === "linux";
const unix = core.build.os === "darwin" || core.build.os === "linux" ||
core.build.os === "freebsd" || core.build.os === "openbsd";
return {
isFile: response.isFile,
isDirectory: response.isDirectory,

View file

@ -66,7 +66,11 @@ impl FileSystem for RealFs {
{
Ok(r.bits())
}
#[cfg(target_os = "macos")]
#[cfg(any(
target_os = "macos",
target_os = "openbsd",
target_os = "freebsd"
))]
{
Ok(r.bits() as u32)
}

View file

@ -2,7 +2,7 @@
const { ops } = globalThis.__bootstrap.core;
export type OSType = "windows" | "linux" | "darwin" | "freebsd";
export type OSType = "windows" | "linux" | "darwin" | "freebsd" | "openbsd";
export const osType: OSType = ops.op_node_build_os();

View file

@ -395,6 +395,95 @@ const errorToCodeFreebsd: CodeMapData = codeToErrorFreebsd.map((
[status, [code]],
) => [code, status]);
const codeToErrorOpenBSD: ErrorMapData = [
[-7, ["E2BIG", "argument list too long"]],
[-13, ["EACCES", "permission denied"]],
[-48, ["EADDRINUSE", "address already in use"]],
[-49, ["EADDRNOTAVAIL", "address not available"]],
[-47, ["EAFNOSUPPORT", "address family not supported"]],
[-35, ["EAGAIN", "resource temporarily unavailable"]],
[-3000, ["EAI_ADDRFAMILY", "address family not supported"]],
[-3001, ["EAI_AGAIN", "temporary failure"]],
[-3002, ["EAI_BADFLAGS", "bad ai_flags value"]],
[-3013, ["EAI_BADHINTS", "invalid value for hints"]],
[-3003, ["EAI_CANCELED", "request canceled"]],
[-3004, ["EAI_FAIL", "permanent failure"]],
[-3005, ["EAI_FAMILY", "ai_family not supported"]],
[-3006, ["EAI_MEMORY", "out of memory"]],
[-3007, ["EAI_NODATA", "no address"]],
[-3008, ["EAI_NONAME", "unknown node or service"]],
[-3009, ["EAI_OVERFLOW", "argument buffer overflow"]],
[-3014, ["EAI_PROTOCOL", "resolved protocol is unknown"]],
[-3010, ["EAI_SERVICE", "service not available for socket type"]],
[-3011, ["EAI_SOCKTYPE", "socket type not supported"]],
[-37, ["EALREADY", "connection already in progress"]],
[-9, ["EBADF", "bad file descriptor"]],
[-16, ["EBUSY", "resource busy or locked"]],
[-88, ["ECANCELED", "operation canceled"]],
[-4080, ["ECHARSET", "invalid Unicode character"]],
[-53, ["ECONNABORTED", "software caused connection abort"]],
[-61, ["ECONNREFUSED", "connection refused"]],
[-54, ["ECONNRESET", "connection reset by peer"]],
[-39, ["EDESTADDRREQ", "destination address required"]],
[-17, ["EEXIST", "file already exists"]],
[-14, ["EFAULT", "bad address in system call argument"]],
[-27, ["EFBIG", "file too large"]],
[-65, ["EHOSTUNREACH", "host is unreachable"]],
[-4, ["EINTR", "interrupted system call"]],
[-22, ["EINVAL", "invalid argument"]],
[-5, ["EIO", "i/o error"]],
[-56, ["EISCONN", "socket is already connected"]],
[-21, ["EISDIR", "illegal operation on a directory"]],
[-62, ["ELOOP", "too many symbolic links encountered"]],
[-24, ["EMFILE", "too many open files"]],
[-40, ["EMSGSIZE", "message too long"]],
[-63, ["ENAMETOOLONG", "name too long"]],
[-50, ["ENETDOWN", "network is down"]],
[-51, ["ENETUNREACH", "network is unreachable"]],
[-23, ["ENFILE", "file table overflow"]],
[-55, ["ENOBUFS", "no buffer space available"]],
[-19, ["ENODEV", "no such device"]],
[-2, ["ENOENT", "no such file or directory"]],
[-12, ["ENOMEM", "not enough memory"]],
[-4056, ["ENONET", "machine is not on the network"]],
[-42, ["ENOPROTOOPT", "protocol not available"]],
[-28, ["ENOSPC", "no space left on device"]],
[-78, ["ENOSYS", "function not implemented"]],
[-57, ["ENOTCONN", "socket is not connected"]],
[-20, ["ENOTDIR", "not a directory"]],
[-66, ["ENOTEMPTY", "directory not empty"]],
[-38, ["ENOTSOCK", "socket operation on non-socket"]],
[-45, ["ENOTSUP", "operation not supported on socket"]],
[-87, ["EOVERFLOW", "value too large for defined data type"]],
[-1, ["EPERM", "operation not permitted"]],
[-32, ["EPIPE", "broken pipe"]],
[-95, ["EPROTO", "protocol error"]],
[-43, ["EPROTONOSUPPORT", "protocol not supported"]],
[-41, ["EPROTOTYPE", "protocol wrong type for socket"]],
[-34, ["ERANGE", "result too large"]],
[-30, ["EROFS", "read-only file system"]],
[-58, ["ESHUTDOWN", "cannot send after transport endpoint shutdown"]],
[-29, ["ESPIPE", "invalid seek"]],
[-3, ["ESRCH", "no such process"]],
[-60, ["ETIMEDOUT", "connection timed out"]],
[-26, ["ETXTBSY", "text file is busy"]],
[-18, ["EXDEV", "cross-device link not permitted"]],
[-4094, ["UNKNOWN", "unknown error"]],
[-4095, ["EOF", "end of file"]],
[-6, ["ENXIO", "no such device or address"]],
[-31, ["EMLINK", "too many links"]],
[-64, ["EHOSTDOWN", "host is down"]],
[-4030, ["EREMOTEIO", "remote I/O error"]],
[-25, ["ENOTTY", "inappropriate ioctl for device"]],
[-79, ["EFTYPE", "inappropriate file type or format"]],
[-84, ["EILSEQ", "illegal byte sequence"]],
[-44, ["ESOCKTNOSUPPORT", "socket type not supported"]],
];
const errorToCodeOpenBSD: CodeMapData = codeToErrorOpenBSD.map((
[status, [code]],
) => [code, status]);
export const errorMap = new Map<number, [string, string]>(
osType === "windows"
? codeToErrorWindows
@ -404,6 +493,8 @@ export const errorMap = new Map<number, [string, string]>(
? codeToErrorLinux
: osType === "freebsd"
? codeToErrorFreebsd
: osType === "openbsd"
? codeToErrorOpenBSD
: unreachable(),
);
@ -416,6 +507,8 @@ export const codeMap = new Map<string, number>(
? errorToCodeLinux
: osType === "freebsd"
? errorToCodeFreebsd
: osType === "openbsd"
? errorToCodeOpenBSD
: unreachable(),
);

View file

@ -172,6 +172,7 @@ export function homedir(): string | null {
case "linux":
case "darwin":
case "freebsd":
case "openbsd":
return Deno.env.get("HOME") || null;
default:
throw Error("unreachable");
@ -299,6 +300,8 @@ export function type(): string {
return "Darwin";
case "freebsd":
return "FreeBSD";
case "openbsd":
return "OpenBSD";
default:
throw Error("unreachable");
}

View file

@ -183,6 +183,85 @@ pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
}
}
#[cfg(target_os = "openbsd")]
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
match s {
"SIGHUP" => Ok(1),
"SIGINT" => Ok(2),
"SIGQUIT" => Ok(3),
"SIGILL" => Ok(4),
"SIGTRAP" => Ok(5),
"SIGIOT" => Ok(6),
"SIGABRT" => Ok(6),
"SIGEMT" => Ok(7),
"SIGFPE" => Ok(8),
"SIGKILL" => Ok(9),
"SIGBUS" => Ok(10),
"SIGSEGV" => Ok(11),
"SIGSYS" => Ok(12),
"SIGPIPE" => Ok(13),
"SIGALRM" => Ok(14),
"SIGTERM" => Ok(15),
"SIGURG" => Ok(16),
"SIGSTOP" => Ok(17),
"SIGTSTP" => Ok(18),
"SIGCONT" => Ok(19),
"SIGCHLD" => Ok(20),
"SIGTTIN" => Ok(21),
"SIGTTOU" => Ok(22),
"SIGIO" => Ok(23),
"SIGXCPU" => Ok(24),
"SIGXFSZ" => Ok(25),
"SIGVTALRM" => Ok(26),
"SIGPROF" => Ok(27),
"SIGWINCH" => Ok(28),
"SIGINFO" => Ok(29),
"SIGUSR1" => Ok(30),
"SIGUSR2" => Ok(31),
"SIGTHR" => Ok(32),
_ => Err(type_error(format!("Invalid signal : {}", s))),
}
}
#[cfg(target_os = "openbsd")]
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
match s {
1 => Ok("SIGHUP"),
2 => Ok("SIGINT"),
3 => Ok("SIGQUIT"),
4 => Ok("SIGILL"),
5 => Ok("SIGTRAP"),
6 => Ok("SIGABRT"),
7 => Ok("SIGEMT"),
8 => Ok("SIGFPE"),
9 => Ok("SIGKILL"),
10 => Ok("SIGBUS"),
11 => Ok("SIGSEGV"),
12 => Ok("SIGSYS"),
13 => Ok("SIGPIPE"),
14 => Ok("SIGALRM"),
15 => Ok("SIGTERM"),
16 => Ok("SIGURG"),
17 => Ok("SIGSTOP"),
18 => Ok("SIGTSTP"),
19 => Ok("SIGCONT"),
20 => Ok("SIGCHLD"),
21 => Ok("SIGTTIN"),
22 => Ok("SIGTTOU"),
23 => Ok("SIGIO"),
24 => Ok("SIGXCPU"),
25 => Ok("SIGXFSZ"),
26 => Ok("SIGVTALRM"),
27 => Ok("SIGPROF"),
28 => Ok("SIGWINCH"),
29 => Ok("SIGINFO"),
30 => Ok("SIGUSR1"),
31 => Ok("SIGUSR2"),
32 => Ok("SIGTHR"),
_ => Err(type_error(format!("Invalid signal : {}", s))),
}
}
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
match s {

View file

@ -7,6 +7,8 @@ import exports from "../../cli/napi/sym/symbol_exports.json" assert {
const symbolExportLists = {
linux: `{ ${exports.symbols.map((s) => `"${s}"`).join("; ")}; };`,
openbsd: `{ ${exports.symbols.map((s) => `"${s}"`).join("; ")}; };`,
freebsd: `{ ${exports.symbols.map((s) => `"${s}"`).join("; ")}; };`,
windows: `LIBRARY\nEXPORTS\n${
exports.symbols
.map((symbol) => " " + symbol)

View file

@ -176,6 +176,8 @@ export async function generateRunInfo(): Promise<unknown> {
"windows": "win",
"darwin": "mac",
"linux": "linux",
"freebsd": "freebsd",
"openbsd": "openbsd",
};
const proc = await new Deno.Command("git", {
args: ["rev-parse", "HEAD"],