Skip to content

Commit

Permalink
Mass attempt at windows portability
Browse files Browse the repository at this point in the history
  • Loading branch information
jhunkeler committed May 20, 2024
1 parent 30c9945 commit 67975a5
Show file tree
Hide file tree
Showing 22 changed files with 389 additions and 127 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
add_compile_options(${win_cflags})
endif()

link_libraries(curl)
if (WIN32)
link_libraries(shlwapi)
endif ()
add_subdirectory(src)

set(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}")
Expand Down
106 changes: 53 additions & 53 deletions examples/template/example.ini
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
[meta]
; (string) Mission type: hst, jwst
mission =

; (string) Name of delivery
name =

; (string) A codename is only used when mission is set to "hst"
codename =

; (string) Version of the delivery
version =

; (string) Release Candidate of delivery.
; NOTE: Ignored when final is true.
rc =

; (boolean) Enable delivery finalization routines
final =

; (string) URL of Conda environment YAML
; NOTE: Generally the final release of a older delivery
based_on =

; (string) Target version of Python
python =

[conda]
installer_name = Miniforge3
installer_version = 23.3.1-1
installer_platform = ${OMC_CONDA_PLATFORM}
installer_arch = ${OMC_CONDA_ARCH}
installer_baseurl = https://github.com/conda-forge/miniforge/releases/latest/download

; (list) Conda packages to install
conda_packages =

; (list) Python packages to install
pip_packages =

[runtime]
; (string) Environment variable key pairs
; key=value

[test:name] ; where test:"name" denotes the package name
; (string) Version of tested package
version =

; (string) Git repository of tested package
repository =

; (list) Commands to execute against tested package
script =
[meta]
; (string) Mission type: hst, jwst
mission =

; (string) Name of delivery
name =

; (string) A codename is only used when mission is set to "hst"
codename =

; (string) Version of the delivery
version =

; (string) Release Candidate of delivery.
; NOTE: Ignored when final is true.
rc =

; (boolean) Enable delivery finalization routines
final =

; (string) URL of Conda environment YAML
; NOTE: Generally the final release of a older delivery
based_on =

; (string) Target version of Python
python =

[conda]
installer_name = Miniforge3
installer_version = 23.3.1-1
installer_platform = ${OMC_CONDA_PLATFORM}
installer_arch = ${OMC_CONDA_ARCH}
installer_baseurl = https://github.com/conda-forge/miniforge/releases/latest/download

; (list) Conda packages to install
conda_packages =

; (list) Python packages to install
pip_packages =

[runtime]
; (string) Environment variable key pairs
; key=value

[test:name] ; where test:"name" denotes the package name
; (string) Version of tested package
version =

; (string) Git repository of tested package
repository =

; (list) Commands to execute against tested package
script =
1 change: 1 addition & 0 deletions include/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#define OMC_OS_WINDOWS
#include "os_windows.h"

#elif defined(__linux__)
#define OMC_OS_LINUX
Expand Down
4 changes: 2 additions & 2 deletions include/deliverable.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/utsname.h>

#include "omc.h"

#define DELIVERY_PLATFORM_MAX 4
Expand Down Expand Up @@ -139,7 +139,7 @@ struct Delivery {
* \brief Global runtime variables
*/
struct Runtime {
RuntimeEnv *environ; ///< Environment variables
struct StrList *env; ///< Environment variables
} runtime;

/*! \struct Test
Expand Down
3 changes: 2 additions & 1 deletion include/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include "environment.h"
#include "omc.h"

typedef struct StrList RuntimeEnv;

Expand All @@ -20,4 +20,5 @@ char *runtime_expand_var(RuntimeEnv *env, char *input);
void runtime_export(RuntimeEnv *env, char **keys);
void runtime_apply(RuntimeEnv *env);
void runtime_free(RuntimeEnv *env);

#endif //OMC_ENVIRONMENT_H
10 changes: 5 additions & 5 deletions include/ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ struct INIFILE *ini_open(const char *filename);
struct INISection *ini_section_search(struct INIFILE **ini, unsigned mode, char *value);

/**
*
* @param ini
* @param section
* @param key
* @return
*
* @param ini
* @param section
* @param key
* @return
*/
int ini_has_key(struct INIFILE *ini, const char *section, const char *key);

Expand Down
12 changes: 6 additions & 6 deletions include/omc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@
#include <limits.h>
#include <unistd.h>
#include <time.h>
#include <sys/statvfs.h>
#include "config.h"

#define SYSERROR(MSG, ...) do { \
fprintf(stderr, "%s:%s:%d:%s - ", path_basename(__FILE__), __FUNCTION__, __LINE__, strerror(errno) ? "info" : strerror(errno)); \
fprintf(stderr, MSG LINE_SEP, __VA_ARGS__); \
} while (0)

#define OMC_BUFSIZ 8192
#define OMC_NAME_MAX 255
#define OMC_DIRSTACK_MAX 1024
#define OMC_TIME_STR_MAX 128
#define HTTP_ERROR(X) X >= 400

#include "config.h"
#include "template.h"

#include "strlist.h"
#include "str.h"
#include "environment.h"
#include "utils.h"
#include "copy.h"
#include "ini.h"
#include "conda.h"
#include "environment.h"
#include "artifactory.h"
#include "docker.h"
#include "deliverable.h"
#include "str.h"
#include "strlist.h"
#include "system.h"
#include "download.h"
#include "recipe.h"
#include "relocation.h"
#include "wheel.h"
#include "junitxml.h"
#include "deliverable.h"

#define guard_runtime_free(X) do { if (X) { runtime_free(X); X = NULL; } } while (0)
#define guard_strlist_free(X) do { if ((*X)) { strlist_free(X); (*X) = NULL; } } while (0)
Expand Down
1 change: 1 addition & 0 deletions include/os_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OMC_OS_DARWIN_H

#include <sys/mount.h>
#include <sys/utsname.h>

#ifndef __DARWIN_64_BIT_INO_T
#define statvfs statfs
Expand Down
2 changes: 2 additions & 0 deletions include/os_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define OMC_OS_LINUX_H

#include <limits.h>
#include <sys/statvfs.h>
#include <sys/utsname.h>

#ifndef PATH_MAX
#include <linux/limits.h>
Expand Down
22 changes: 22 additions & 0 deletions include/os_windows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by jhunk on 5/19/2024.
//

#ifndef OMC_OS_WINDOWS_H
#define OMC_OS_WINDOWS_H


#include <winsock2.h>
#include <windows.h>
#include <direct.h>
#define lstat stat
#define NAME_MAX 256
#define MAXNAMLEN 256
#define __environ _environ
#undef mkdir
#define mkdir(X, Y) _mkdir(X)

int setenv(const char *key, const char *value, int overwrite);
char *realpath(const char *path, char **dest);

#endif //OMC_OS_WINDOWS_H
2 changes: 1 addition & 1 deletion include/relocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string.h>
#if defined(OMC_OS_DARWIN)
#include <limits.h>
# else
#elif defined(OMC_OS_LINUX)
#include <linux/limits.h>
#endif
#include <unistd.h>
Expand Down
4 changes: 4 additions & 0 deletions include/str.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,9 @@ char *tolower_s(char *s);
* @return pointer to new string
*/
char *to_short_version(const char *s);
#if defined(OMC_OS_WINDOWS)
char *strsep(char **str, const char *delim);
char *strndup(const char *str, size_t nelem);
#endif

#endif //OMC_STR_H
2 changes: 2 additions & 0 deletions include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#if defined(OMC_OS_UNIX)
#include <sys/wait.h>
#endif
#include <sys/stat.h>

struct Process {
Expand Down
Empty file added rules/hst.ini
Empty file.
17 changes: 14 additions & 3 deletions src/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int copy2(const char *src, const char *dest, unsigned int op) {
}

stat(dname, &dnamest);
#if ! defined(OMC_OS_WINDOWS)
if (S_ISLNK(src_stat.st_mode)) {
char lpath[1024] = {0};
if (readlink(src, lpath, sizeof(lpath)) < 0) {
Expand All @@ -46,7 +47,9 @@ int copy2(const char *src, const char *dest, unsigned int op) {
perror(src);
return -1;
}
} else if (S_ISREG(src_stat.st_mode)) {
} else
#endif
if (S_ISREG(src_stat.st_mode)) {
fp1 = fopen(src, "rb");
if (!fp1) {
perror(src);
Expand All @@ -67,13 +70,15 @@ int copy2(const char *src, const char *dest, unsigned int op) {
fclose(fp2);

if (bytes_written != (size_t) src_stat.st_size) {
fprintf(stderr, "%s: SHORT WRITE (expected %zu bytes, but wrote %zu bytes)\n", dest, src_stat.st_size, bytes_written);
fprintf(stderr, "%s: SHORT WRITE (expected %li bytes, but wrote %zu bytes)\n", dest, src_stat.st_size, bytes_written);
return -1;
}

#if !defined(OMC_OS_WINDOWS)
if (op & CT_OWNER && chown(dest, src_stat.st_uid, src_stat.st_gid) < 0) {
perror(dest);
}
#endif

if (op & CT_PERM && chmod(dest, src_stat.st_mode) < 0) {
perror(dest);
Expand Down Expand Up @@ -173,7 +178,13 @@ int copytree(const char *srcdir, const char *destdir, unsigned int op) {
return -1;
}

if (d->d_type == DT_DIR) {
int is_dir = 0;
#if defined (OMC_OS_WINDOWS)
is_dir = S_ISDIR(st.st_mode);
#else
is_dir = DT_DIR == rec->d_type;
#endif
if (is_dir) {
if (strncmp(src, dest, strlen(src)) == 0) {
closedir(dir);
return -1;
Expand Down
Loading

0 comments on commit 67975a5

Please sign in to comment.