Convert .json config files to .yaml (#284)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
diff --git a/pkgs/unix_api/constants.json b/pkgs/unix_api/constants.json
deleted file mode 100644
index 2592a56..0000000
--- a/pkgs/unix_api/constants.json
+++ /dev/null
@@ -1,83 +0,0 @@
-{
- "<sys/stat.h>": [
- "AT_SYMLINK_NOFOLLOW",
- "AT_RESOLVE_BENEATH",
- "AT_EMPTY_PATH",
- "S_IEXEC",
- "S_IFBLK",
- "S_IFCHR",
- "S_IFDIR",
- "S_IFIFO",
- "S_IFLNK",
- "S_IFMT",
- "S_IFREG",
- "S_IFSOCK",
- "S_IFWHT",
- "S_IREAD",
- "S_IRGRP",
- "S_IROTH",
- "S_IRUSR",
- "S_IRWXG",
- "S_IRWXO",
- "S_IRWXU",
- "S_ISGID",
- "S_ISTXT",
- "S_ISUID",
- "S_ISVTX",
- "S_IWGRP",
- "S_IWOTH",
- "S_IWRITE",
- "S_IWUSR",
- "S_IXGRP",
- "S_IXOTH",
- "S_IXUSR",
- "UF_APPEND",
- "UF_HIDDEN"
- ],
- "<errno.h>": [
- "EACCES",
- "EDOM",
- "EEXIST",
- "EINTR",
- "EMFILE",
- "ENOENT",
- "ENOSPC",
- "ENOTDIR",
- "ENOTEMPTY",
- "EPERM"
- ],
- "<fcntl.h>": [
- "AT_FDCWD",
- "AT_REMOVEDIR",
- "O_APPEND",
- "O_CLOEXEC",
- "O_CREAT",
- "O_DIRECTORY",
- "O_EXCL",
- "O_RDONLY",
- "O_TRUNC",
- "O_WRONLY"
- ],
- "<limits.h>": [
- "PATH_MAX"
- ],
- "<dirent.h>" : [
- "DT_BLK",
- "DT_CHR",
- "DT_DIR",
- "DT_FIFO",
- "DT_LNK",
- "DT_REG",
- "DT_SOCK",
- "DT_UNKNOWN"
- ],
- "<stdio.h>": [
- "L_ctermid"
- ],
- "<unistd.h>": [
- "F_OK",
- "R_OK",
- "W_OK",
- "X_OK"
- ]
-}
\ No newline at end of file
diff --git a/pkgs/unix_api/constants.yaml b/pkgs/unix_api/constants.yaml
new file mode 100644
index 0000000..924f999
--- /dev/null
+++ b/pkgs/unix_api/constants.yaml
@@ -0,0 +1,74 @@
+"<sys/stat.h>":
+ - AT_SYMLINK_NOFOLLOW
+ - AT_RESOLVE_BENEATH
+ - AT_EMPTY_PATH
+ - S_IEXEC
+ - S_IFBLK
+ - S_IFCHR
+ - S_IFDIR
+ - S_IFIFO
+ - S_IFLNK
+ - S_IFMT
+ - S_IFREG
+ - S_IFSOCK
+ - S_IFWHT
+ - S_IREAD
+ - S_IRGRP
+ - S_IROTH
+ - S_IRUSR
+ - S_IRWXG
+ - S_IRWXO
+ - S_IRWXU
+ - S_ISGID
+ - S_ISTXT
+ - S_ISUID
+ - S_ISVTX
+ - S_IWGRP
+ - S_IWOTH
+ - S_IWRITE
+ - S_IWUSR
+ - S_IXGRP
+ - S_IXOTH
+ - S_IXUSR
+ - UF_APPEND
+ - UF_HIDDEN
+"<errno.h>":
+ - EACCES
+ - EDOM
+ - EEXIST
+ - EINTR
+ - EMFILE
+ - ENOENT
+ - ENOSPC
+ - ENOTDIR
+ - ENOTEMPTY
+ - EPERM
+"<fcntl.h>":
+ - AT_FDCWD
+ - AT_REMOVEDIR
+ - O_APPEND
+ - O_CLOEXEC
+ - O_CREAT
+ - O_DIRECTORY
+ - O_EXCL
+ - O_RDONLY
+ - O_TRUNC
+ - O_WRONLY
+"<limits.h>":
+ - PATH_MAX
+"<dirent.h>":
+ - DT_BLK
+ - DT_CHR
+ - DT_DIR
+ - DT_FIFO
+ - DT_LNK
+ - DT_REG
+ - DT_SOCK
+ - DT_UNKNOWN
+"<stdio.h>":
+ - L_ctermid
+"<unistd.h>":
+ - F_OK
+ - R_OK
+ - W_OK
+ - X_OK
diff --git a/pkgs/unix_api/functions.json b/pkgs/unix_api/functions.json
deleted file mode 100644
index 7ac1901..0000000
--- a/pkgs/unix_api/functions.json
+++ /dev/null
@@ -1,159 +0,0 @@
-{
- "<fcntl.h>": [
- {
- "comment": "Opens a file.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html",
- "prototype": "int open(const char *, int, mode_t)",
- "error_value": "-1"
- },
- {
- "comment": "Opens a file relative to a file descriptor.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/openat.html",
- "prototype": "int openat(int, const char *, int, mode_t)",
- "error_value": "-1"
- }
- ],
- "<stdio.h>": [
- {
- "comment": "Renames a file.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html",
- "prototype": "int rename(const char *, const char *)"
- }
- ],
- "<stdlib.h>": [
- {
- "comment": "Create a temporary directory.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdtemp.html",
- "prototype": "char *mkdtemp(char *)"
- },
- {
- "comment": "Gets the value of an environment variable.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getenv.html",
- "prototype": "char * getenv(const char *)"
- }
- ],
- "<string.h>": [
- {
- "comment": "Formats an error code as a string.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html",
- "prototype": "char *strerror(int)"
- }
- ],
- "<sys/stat.h>": [
- {
- "comment": "Changes the mode of a file.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html",
- "prototype": "int chmod(const char *, mode_t)",
- "error_value": "-1"
- },
- {
- "comment": "Creates a directory",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html",
- "prototype": "int mkdir(const char *, mode_t)",
- "error_value": "-1"
- }
- ],
- "<unistd.h>": [
- {
- "comment": "Determines the accessibility of a file.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html",
- "prototype": "int access(const char *, int)"
- },
- {
- "comment": "Schedules an alarm signal.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/alarm.html",
- "prototype": "unsigned alarm(unsigned)"
- },
- {
- "comment": "Changes the working directory.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html",
- "prototype": "int chdir(const char *)"
- },
- {
- "comment": "Closes a file descriptor.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html",
- "prototype": "int close(int)"
- },
- {
- "comment": "Encrypts a string.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/crypt.html",
- "prototype": "char * crypt(const char *, const char *)",
- "available_android": false,
- "error_value": "NULL"
- },
- {
- "comment": "Generates a path name for the controlling terminal.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctermid.html",
- "prototype": "char * ctermid(char *)",
- "available_android": false,
- "error_value": "\"\""
- },
- {
- "comment": "Duplicates an open file descriptor.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html",
- "prototype": "int dup(int)"
- },
- {
- "comment": "Copies an open file descriptor into another.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html",
- "prototype": "int dup2(int, int)"
- },
- {
- "comment": "Determines the accessibility of a file descriptor.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/faccessat.html",
- "prototype": "int faccessat(int, const char *, int, int)"
- },
- {
- "comment": "Changes the current directory.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html",
- "prototype": "int fchdir(int)"
- },
- {
- "comment": "Forces all queued I/O operations to complete.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html",
- "prototype": "int fdatasync(int)",
- "available_ios": false,
- "error_value": "-1"
- },
- {
- "comment": "Gets the current working directory.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html",
- "prototype": "char * getcwd(char *, size_t)",
- "error_value": "NULL"
- },
- {
- "comment": "Gets the current process id.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html",
- "prototype": "pid_t getpid(void)",
- "error_value": "-1"
- },
- {
- "comment": "Gets the parent process id.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getppid.html",
- "prototype": "pid_t getppid(void)",
- "error_value": "-1"
- },
- {
- "comment": "Reads from a file.",
- "url": "https://pubs.opengroup.org/onlinepubs/009696699/functions/read.html",
- "prototype": "ssize_t read(int, void *, size_t)",
- "error_value": "-1"
- },
- {
- "comment": "Writes to a file.",
- "url": "https://pubs.opengroup.org/onlinepubs/009696699/functions/write.html",
- "prototype": "ssize_t write(int, const void *, size_t)",
- "error_value": "-1"
- },
- {
- "comment": "Removes a directory entry.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/linkat.html",
- "prototype": "int unlink(const char *)"
- },
- {
- "comment": "Removes a directory entry relative to another file.",
- "url": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlinkat.html",
- "prototype": "int unlinkat(int, const char *, int)"
- }
- ]
-}
\ No newline at end of file
diff --git a/pkgs/unix_api/functions.yaml b/pkgs/unix_api/functions.yaml
new file mode 100644
index 0000000..9e5df21
--- /dev/null
+++ b/pkgs/unix_api/functions.yaml
@@ -0,0 +1,99 @@
+"<fcntl.h>":
+ - prototype: "int open(const char *, int, mode_t)"
+ comment: "Opens a file."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html"
+ error_value: "-1"
+ - prototype: "int openat(int, const char *, int, mode_t)"
+ comment: "Opens a file relative to a file descriptor."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/openat.html"
+ error_value: "-1"
+"<stdio.h>":
+ - prototype: "int rename(const char *, const char *)"
+ comment: "Renames a file."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html"
+"<stdlib.h>":
+ - prototype: "char * getenv(const char *)"
+ comment: "Gets the value of an environment variable."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getenv.html"
+"<string.h>":
+ - prototype: "char *mkdtemp(char *)"
+ comment: "Create a temporary directory."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdtemp.html"
+ - prototype: "char *strerror(int)"
+ comment: "Formats an error code as a string."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html"
+"<sys/stat.h>":
+ - prototype: "int chmod(const char *, mode_t)"
+ comment: "Changes the mode of a file."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html"
+ error_value: "-1"
+ - prototype: "int mkdir(const char *, mode_t)"
+ comment: "Creates a directory"
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html"
+ error_value: "-1"
+"<unistd.h>":
+ - prototype: "int access(const char *, int)"
+ comment: "Determines the accessibility of a file."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html"
+ - prototype: "unsigned alarm(unsigned)"
+ comment: "Schedules an alarm signal."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/alarm.html"
+ - prototype: "int chdir(const char *)"
+ comment: "Changes the working directory."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html"
+ - prototype: "int close(int)"
+ comment: "Closes a file descriptor."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html"
+ - prototype: "char * crypt(const char *, const char *)"
+ comment: "Encrypts a string."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/crypt.html"
+ available_android: false
+ error_value: "NULL"
+ - prototype: "char * ctermid(char *)"
+ comment: "Generates a path name for the controlling terminal."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctermid.html"
+ available_android: false
+ error_value: "\"\""
+ - prototype: "int dup(int)"
+ comment: "Duplicates an open file descriptor."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html"
+ - prototype: "int dup2(int, int)"
+ comment: "Copies an open file descriptor into another."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html"
+ - prototype: "int faccessat(int, const char *, int, int)"
+ comment: "Determines the accessibility of a file descriptor."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/faccessat.html"
+ - prototype: "int fchdir(int)"
+ comment: "Changes the current directory."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html"
+ - prototype: "int fdatasync(int)"
+ comment: "Forces all queued I/O operations to complete."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html"
+ available_ios: false
+ error_value: "-1"
+ - prototype: "char * getcwd(char *, size_t)"
+ comment: "Gets the current working directory."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html"
+ error_value: "NULL"
+ - prototype: "pid_t getpid(void)"
+ comment: "Gets the current process id."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html"
+ error_value: "-1"
+ - prototype: "pid_t getppid(void)"
+ comment: "Gets the parent process id."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getppid.html"
+ error_value: "-1"
+ - prototype: "ssize_t read(int, void *, size_t)"
+ comment: "Reads from a file."
+ url: "https://pubs.opengroup.org/onlinepubs/009696699/functions/read.html"
+ error_value: "-1"
+ - prototype: "ssize_t write(int, const void *, size_t)"
+ comment: "Writes to a file."
+ url: "https://pubs.opengroup.org/onlinepubs/009696699/functions/write.html"
+ error_value: "-1"
+ - prototype: "int unlink(const char *)"
+ comment: "Removes a directory entry."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/linkat.html"
+ - prototype: "int unlinkat(int, const char *, int)"
+ comment: "Removes a directory entry relative to another file."
+ url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlinkat.html"
diff --git a/pkgs/unix_api/lib/src/function_bindings.g.dart b/pkgs/unix_api/lib/src/function_bindings.g.dart
index e579049..dc28162 100644
--- a/pkgs/unix_api/lib/src/function_bindings.g.dart
+++ b/pkgs/unix_api/lib/src/function_bindings.g.dart
@@ -64,7 +64,7 @@
@ffi.Native<
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Int>)
>()
-external ffi.Pointer<ffi.Char> libc_shim_mkdtemp(
+external ffi.Pointer<ffi.Char> libc_shim_getenv(
ffi.Pointer<ffi.Char> arg0,
ffi.Pointer<ffi.Int> arg1,
);
@@ -72,7 +72,7 @@
@ffi.Native<
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Int>)
>()
-external ffi.Pointer<ffi.Char> libc_shim_getenv(
+external ffi.Pointer<ffi.Char> libc_shim_mkdtemp(
ffi.Pointer<ffi.Char> arg0,
ffi.Pointer<ffi.Int> arg1,
);
diff --git a/pkgs/unix_api/lib/src/functions.g.dart b/pkgs/unix_api/lib/src/functions.g.dart
index 5119925..4f6384c 100644
--- a/pkgs/unix_api/lib/src/functions.g.dart
+++ b/pkgs/unix_api/lib/src/functions.g.dart
@@ -24,18 +24,18 @@
int rename(ffi.Pointer<ffi.Char> arg0, ffi.Pointer<ffi.Char> arg1) =>
libc_shim_rename(arg0, arg1, errnoPtr);
-/// Create a temporary directory.
-///
-/// See the [POSIX specification for `mkdtemp`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdtemp.html).
-ffi.Pointer<ffi.Char> mkdtemp(ffi.Pointer<ffi.Char> arg0) =>
- libc_shim_mkdtemp(arg0, errnoPtr);
-
/// Gets the value of an environment variable.
///
/// See the [POSIX specification for `getenv`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getenv.html).
ffi.Pointer<ffi.Char> getenv(ffi.Pointer<ffi.Char> arg0) =>
libc_shim_getenv(arg0, errnoPtr);
+/// Create a temporary directory.
+///
+/// See the [POSIX specification for `mkdtemp`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdtemp.html).
+ffi.Pointer<ffi.Char> mkdtemp(ffi.Pointer<ffi.Char> arg0) =>
+ libc_shim_mkdtemp(arg0, errnoPtr);
+
/// Formats an error code as a string.
///
/// See the [POSIX specification for `strerror`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html).
diff --git a/pkgs/unix_api/pubspec.yaml b/pkgs/unix_api/pubspec.yaml
index 7fc22cd..2cf509c 100644
--- a/pkgs/unix_api/pubspec.yaml
+++ b/pkgs/unix_api/pubspec.yaml
@@ -22,3 +22,4 @@
mustache_template: ^2.0.1
path: ^1.9.1
test: ^1.24.0
+ yaml: ^3.1.2
diff --git a/pkgs/unix_api/src/functions.g.c b/pkgs/unix_api/src/functions.g.c
index 5415923..75ce032 100644
--- a/pkgs/unix_api/src/functions.g.c
+++ b/pkgs/unix_api/src/functions.g.c
@@ -51,19 +51,19 @@
}
-char * libc_shim_mkdtemp(char * arg0, int * err) {
+char * libc_shim_getenv(const char * arg0, int * err) {
char * r;
errno = *err;
- r = mkdtemp(arg0);
+ r = getenv(arg0);
*err = errno;
return r;
}
-char * libc_shim_getenv(const char * arg0, int * err) {
+char * libc_shim_mkdtemp(char * arg0, int * err) {
char * r;
errno = *err;
- r = getenv(arg0);
+ r = mkdtemp(arg0);
*err = errno;
return r;
}
diff --git a/pkgs/unix_api/src/functions.g.h b/pkgs/unix_api/src/functions.g.h
index 04c9b1f..4bb8d43 100644
--- a/pkgs/unix_api/src/functions.g.h
+++ b/pkgs/unix_api/src/functions.g.h
@@ -18,11 +18,11 @@
__attribute__((visibility("default"))) __attribute__((used))
-char * libc_shim_mkdtemp(char *, int *);
+char * libc_shim_getenv(const char *, int *);
__attribute__((visibility("default"))) __attribute__((used))
-char * libc_shim_getenv(const char *, int *);
+char * libc_shim_mkdtemp(char *, int *);
__attribute__((visibility("default"))) __attribute__((used))
diff --git a/pkgs/unix_api/tool/build_constants.dart b/pkgs/unix_api/tool/build_constants.dart
index 5ae1a9d..e8c38e8 100644
--- a/pkgs/unix_api/tool/build_constants.dart
+++ b/pkgs/unix_api/tool/build_constants.dart
@@ -2,9 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'dart:convert';
import 'dart:io';
+import 'package:yaml/yaml.dart';
+
const _cSourceTemplate = '''
// AUTO GENERATED FILE, DO NOT EDIT.
// Regenerate with `dart run tool/build_constants.dart`.
@@ -70,9 +71,9 @@
''');
}
-/// Generates Dart and C source from "constants.json"
+/// Generates Dart and C source from "constants.yaml"
///
-/// Generates the following files based on "constants.json":
+/// Generates the following files based on "constants.yaml":
/// o lib/src/constants.g.dart
/// o src/constants.g.c
/// o src/constants.g.h
@@ -81,7 +82,7 @@
/// `dart run ffigen --config constants-ffigen.yaml`
void main() {
final headerToConstants =
- (json.decode(File('constants.json').readAsStringSync()) as Map)
+ (loadYaml(File('constants.yaml').readAsStringSync()) as Map)
.cast<String, Object>();
final cSourceBuffer = StringBuffer(_cSourceTemplate);
diff --git a/pkgs/unix_api/tool/build_functions.dart b/pkgs/unix_api/tool/build_functions.dart
index c2846c3..9aaae63 100644
--- a/pkgs/unix_api/tool/build_functions.dart
+++ b/pkgs/unix_api/tool/build_functions.dart
@@ -2,9 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'dart:convert';
import 'dart:io';
+import 'package:yaml/yaml.dart';
import 'cfunction.dart';
import 'package:mustache_template/mustache_template.dart';
@@ -126,16 +126,16 @@
return renderTemplate(dart, function);
}
-/// Generates Dart and C source from "functions.json"
+/// Generates Dart and C source from "functions.yaml"
///
-/// Generates the following files based on "functions.json":
+/// Generates the following files based on "functions.yaml":
/// o src/functions.g.c
/// o src/functions.g.h
///
/// Run as part of `generate.dart`.
void main() {
final headerToConstants =
- (json.decode(File('functions.json').readAsStringSync()) as Map)
+ (loadYaml(File('functions.yaml').readAsStringSync()) as Map)
.cast<String, Object>();
final cSourceBuffer = StringBuffer(_cSourceTemplate);