Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions scripts/sync_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,13 @@
f"https://raw.githubusercontent.com/yhirose/cpp-httplib/{HTTPLIB_VERSION}/split.py": "split.py",
f"https://raw.githubusercontent.com/yhirose/cpp-httplib/{HTTPLIB_VERSION}/LICENSE": "vendor/cpp-httplib/LICENSE",

"https://raw.githubusercontent.com/sheredom/subprocess.h/8671cee1fc09f11a70ce3782a0ee13177c3aa387/subprocess.h": "vendor/sheredom/subprocess.h",
"https://raw.githubusercontent.com/sheredom/subprocess.h/9ce0d701b6fb10f8f8c4445edd31e7c60a1237e3/subprocess.h": "vendor/sheredom/subprocess.h",
}

# TODO @ngxson : this is temporary, to be removed in the future
patches = [
# https://github.com/sheredom/subprocess.h/pull/102
"vendor/sheredom/patch-bsd.patch",
# https://github.com/sheredom/subprocess.h/pull/101
"vendor/sheredom/patch-windows-quote-backslash.patch",
# https://github.com/sheredom/subprocess.h/pull/104
# note: must be applied after patch-bsd.patch, they touch adjacent lines
"vendor/sheredom/patch-glibc-older-than-2.29.patch",
]

for url, filename in vendor.items():
print(f"downloading {url} to {filename}") # noqa: NP100
urllib.request.urlretrieve(url, filename)

for patch in patches:
print(f"applying {patch}") # noqa: NP100
try:
subprocess.check_call([
"git", "apply", "--directory", os.path.dirname(patch), patch
])
except Exception as e:
print(f"Error: {e}") # noqa: NP100
sys.exit(1)

print("Splitting httplib.h...") # noqa: NP100
try:
subprocess.check_call([
Expand Down
19 changes: 0 additions & 19 deletions vendor/sheredom/patch-bsd.patch

This file was deleted.

47 changes: 0 additions & 47 deletions vendor/sheredom/patch-glibc-older-than-2.29.patch

This file was deleted.

107 changes: 0 additions & 107 deletions vendor/sheredom/patch-windows-quote-backslash.patch

This file was deleted.

38 changes: 35 additions & 3 deletions vendor/sheredom/subprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ enum subprocess_error_e {
subprocess_error_permission_denied = -5,
subprocess_error_no_memory = -6,
subprocess_error_pipe = -7,
subprocess_error_spawn = -8
subprocess_error_spawn = -8,
subprocess_error_not_supported = -9
};

#if defined(__cplusplus)
Expand Down Expand Up @@ -275,20 +276,38 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process);
#endif

/* Whether subprocess_create_ex can honour process_cwd. glibc only gained
posix_spawn_file_actions_addchdir_np in 2.29. Define this yourself to
override the detection, for instance on musl older than 1.1.24. */
posix_spawn_file_actions_addchdir_np in 2.29, and macOS in 10.15; the SDKs
mark it unavailable on iOS, tvOS and watchOS, where the undefined version
macro folds to 0 and so answers correctly. Define this yourself to override
the detection, for instance on musl older than 1.1.24. */
#if !defined(SUBPROCESS_HAVE_CWD)
#if defined(__GLIBC__)
#if __GLIBC_PREREQ(2, 29)
#define SUBPROCESS_HAVE_CWD 1
#else
#define SUBPROCESS_HAVE_CWD 0
#endif
#elif defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < 101500
#define SUBPROCESS_HAVE_CWD 0
#else
#define SUBPROCESS_HAVE_CWD 1
#endif
#endif

/* Whether posix_spawn reports a failed exec back to the caller. glibc only
started doing so in 2.24; before that the child silently exits with 127. */
#if !defined(SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS)
#if defined(__GLIBC__)
#if __GLIBC_PREREQ(2, 24)
#define SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS 1
#else
#define SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS 0
#endif
#else
#define SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS 1
#endif
#endif

#if defined(_WIN32)

#include <wchar.h>
Expand Down Expand Up @@ -554,6 +573,8 @@ int subprocess_error_from_errno(int error) {
case ENFILE:
case ENOMEM:
return subprocess_error_no_memory;
case ENOSYS:
return subprocess_error_not_supported;
default:
return subprocess_error_unknown;
}
Expand Down Expand Up @@ -1358,6 +1379,17 @@ int subprocess_create_ex(const char *const commandLine[], int options,
goto cleanup;
}
} else {
#if !SUBPROCESS_SPAWN_REPORTS_EXEC_ERRORS
/* posix_spawn cannot tell us the exec failed, so check up front */
if (0 != access(commandLine[0], X_OK)) {
saved_errno = errno;
result = subprocess_error_from_errno(saved_errno);
if (subprocess_error_unknown == result) {
result = subprocess_error_spawn;
}
goto cleanup;
}
#endif
posix_error = posix_spawn(&child, commandLine[0], &actions,
SUBPROCESS_NULL,
SUBPROCESS_CONST_CAST(char *const *, commandLine),
Expand Down
Loading