Skip to content

Commit

Permalink
Merge pull request #4 from miller-alex/ci
Browse files Browse the repository at this point in the history
Enable and fix CI on Windows
  • Loading branch information
0-wiz-0 authored Apr 6, 2024
2 parents ab8fd36 + 511a524 commit 45d222e
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 40 deletions.
43 changes: 22 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,34 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# os: [macos-latest, ubuntu-latest, windows-latest]
os: [macos-latest, ubuntu-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- name: checkout
uses: actions/checkout@v2
- name: install dependencies (Windows)
- name: Checkout source
uses: actions/checkout@v4
- name: 'Environment setup (Windows)'
if: ${{ runner.os == 'Windows' }}
uses: lukka/run-vcpkg@v10
id: runvcpkg
uses: actions/github-script@v7
with:
vcpkgGitCommitId: 8bb3f9e4a08a5b71ee93a6f1bcdd7a258bb48392
vcpkgTriplet: x64-windows
vcpkgArguments: zlib
- name: prepare build directory
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
core.exportVariable('CMAKE_TC_ARG', '-DCMAKE_TOOLCHAIN_FILE=' + (process.env.VCPKG_INSTALLATION_ROOT || '') + '\\scripts\\buildsystems\\vcpkg.cmake');
core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite');
- name: 'Install dependencies: zlib (Windows)'
if: ${{ runner.os == 'Windows' }}
run: |
cmake -E make_directory ${{runner.workspace}}/build
- name: configure (Unix)
if: ${{ runner.os != 'Windows' }}
working-directory: ${{runner.workspace}}/build
vcpkg install zlib:x64-windows
- name: 'Install test dependencies: nihtest'
run: |
cmake ${{github.workspace}}
- name: configure (Windows)
if: ${{ runner.os == 'Windows' }}
working-directory: ${{runner.workspace}}/build
pip install nihtest
- name: Configure
run: |
cmake -DCMAKE_TOOLCHAIN_FILE=${{env.VCPKG_ROOT}}/scripts/buildsystems/vcpkg.cmake ${{github.workspace}}
- name: build
cmake ${{env.CMAKE_TC_ARG}} -B ${{runner.workspace}}/build -S ${{github.workspace}}
- name: Build
working-directory: ${{runner.workspace}}/build
run: |
cmake --build . --config Release
- name: Run tests
working-directory: ${{runner.workspace}}/build
run: |
ctest -C Release --output-on-failure --timeout 99
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ if(RUN_REGRESS)
if (${NIHTEST_VERSION} VERSION_LESS ${NIHTEST_REQUIRED_VERSION})
message(WARNING "-- nihtest ${NIHTEST_VERSION} too old, at least ${NIHTEST_REQUIRED_VERSION} required, regression testing disabled")
set(RUN_REGRESS OFF)
else()
message(STATUS "Found nihtest: ${NIHTEST} (found suitable version \"${NIHTEST_VERSION}\", minimum required is \"${NIHTEST_REQUIRED_VERSION}\")")
endif()
endif()
endif()
Expand Down
13 changes: 13 additions & 0 deletions regress/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
set(XFAIL_TESTS
)
if(WIN32)
set(XFAIL_TESTS ${XFAIL_TESTS}
cli-q.test
cli-s.test
directories-2-d.test
recurse.test
recursive.test
)
endif()

if(RUN_REGRESS)
file(GLOB TEST_CASES ${CMAKE_CURRENT_SOURCE_DIR}/*.test)
Expand All @@ -14,4 +23,8 @@ if(RUN_REGRESS)
endforeach()
endif()

set(TEST_BINARY_PATH ${PROJECT_BINARY_DIR}/src)
foreach (cfg ${CMAKE_CONFIGURATION_TYPES})
set(TEST_BINARY_PATH "${TEST_BINARY_PATH}\n\t${PROJECT_BINARY_DIR}/src/${cfg}")
endforeach()
configure_file(nihtest.conf.in nihtest.conf @ONLY)
2 changes: 1 addition & 1 deletion regress/cli-e-2.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description test -e: write error log to file
return 0
arguments -e -l dupe.zip
arguments -e -l -g dupe.zip
file dupe.zip dupe.zip dupe.zip
stdout
Rezipping - dupe.zip
Expand Down
2 changes: 1 addition & 1 deletion regress/cli-e.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description test -e: write error log to file
return 0
arguments -eerror.log -l dupe.zip
arguments -eerror.log -l -g dupe.zip
file dupe.zip dupe.zip dupe.zip
stdout
Rezipping - dupe.zip
Expand Down
2 changes: 1 addition & 1 deletion regress/longername.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description torrentzip a zip with a too long entry name
return 0
arguments -l longername.zip
arguments -l -g longername.zip
file longername.zip longername.zip
stderr
Could not list contents of "longername.zip". File is corrupted or contains entries with bad names.
Expand Down
2 changes: 1 addition & 1 deletion regress/nihtest.conf.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[settings]
test-input-directories = @CMAKE_CURRENT_SOURCE_DIR@
program-directories = @PROJECT_BINARY_DIR@/src
program-directories = @TEST_BINARY_PATH@
default-program = trrntzip
default-stderr-replace = "^[^ :]*: " ""

Expand Down
2 changes: 1 addition & 1 deletion regress/truncated.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description skip tiny files without attempting to open
return 0
arguments -l truncated.zip
arguments -l -g truncated.zip
file truncated.zip truncated.zip
stderr
"truncated.zip" is too small (21 bytes). File may be corrupt.
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/minizip/*.c)
add_executable(trrntzip ${SOURCES})
target_compile_definitions(trrntzip PRIVATE "TZ_VERSION=\"${PROJECT_VERSION}\"")
target_link_libraries(trrntzip m ZLIB::ZLIB)
target_link_libraries(trrntzip ZLIB::ZLIB)
if (UNIX)
target_link_libraries(trrntzip m)
endif()
set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/minizip/unzip.c APPEND PROPERTY COMPILE_DEFINITIONS UNZ_MAXFILENAMEINZIP=1024)
install(TARGETS trrntzip EXPORT ${PROJECT_NAME}-targets DESTINATION bin)
7 changes: 5 additions & 2 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>

#include "logging.h"
#include "util.h"

#ifdef _WIN32
#include <conio.h>
#endif

static FILE *OpenLog(const char *szFileName);

// Global var to store if the logprint func is expecting more
Expand Down
57 changes: 53 additions & 4 deletions src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,59 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "platform.h"

#ifdef WIN32
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "platform.h"

struct dir_s {
intptr_t handle;
int unread;
struct _finddatai64_t entry;
};

DIR *opendir(const char *name) {
size_t sz = strlen(name) + 3;
char *spec = malloc(sz);
DIR *dirp = malloc(sizeof(DIR));

if (!spec || !dirp) {
free(spec);
free(dirp);
return NULL;
}
snprintf(spec, sz, "%s%c*", name, DIRSEP);
dirp->unread = 1;
dirp->handle = _findfirsti64(spec, &dirp->entry);
free(spec);
if (dirp->handle == -1) {
free(dirp);
return NULL;
}
return dirp;
}

int closedir(DIR *dirp) {
int rv = _findclose(dirp->handle);
free(dirp);
return rv;
}

struct dirent *readdir(DIR *dirp) {
if (dirp->unread) {
dirp->unread = 0;
return &dirp->entry;
}
if (_findnexti64(dirp->handle, &dirp->entry))
return NULL;
return &dirp->entry;
}

int mkstemp(char *ntemplate) {
int i, fd = -1;
Expand All @@ -30,7 +77,7 @@ int mkstemp(char *ntemplate) {
if (!mktemp(ntemplate))
break;

fd = open(ntemplate, O_RDWR | C_CREAT | O_EXCL, S_IREAD | S_IWRITE);
fd = open(ntemplate, O_RDWR | O_CREAT | O_EXCL, S_IREAD | S_IWRITE);
if (fd >= 0 || errno != EEXIST)
break;

Expand All @@ -50,6 +97,8 @@ int mkstemp(char *ntemplate) {
#include <termios.h>
#include <unistd.h>

#include "platform.h"

#if defined(__CYGWIN__)
/* Workaround for Cygwin, which is missing cfmakeraw */
/* Pasted from man page; added in serial.c arbitrarily */
Expand Down
11 changes: 11 additions & 0 deletions src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ int getch(void);
#define DIRSEP '\\'
#define stat _stati64
#define lstat stat
#define off64_t __int64
#define off_t off64_t
#define strcasecmp stricmp
#define strncasecmp strnicmp

typedef struct dir_s DIR;
#define dirent _finddatai64_t
#define d_name name

DIR *opendir(const char *name);
int closedir(DIR *dirp);
struct dirent *readdir(DIR *dirp);

int mkstemp(char *ntemplate);
#endif
Expand Down
30 changes: 25 additions & 5 deletions src/trrntzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,45 @@
#include "minizip.h"

#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>

#define NDEBUG
#include <assert.h>

#ifdef _WIN32
#include <conio.h>
#include <io.h>
#else
#include <dirent.h>
#include <unistd.h>
#endif

#include "global.h"
#include "logging.h"
#include "util.h"

// The following macros may be missing on Windows
#ifndef R_OK
#define R_OK 4
#endif
#ifndef W_OK
#define W_OK 2
#endif
#ifndef S_ISDIR
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
#ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif

#ifndef TZ_VERSION
#error "Build system must define TZ_VERSION"
#endif
Expand Down Expand Up @@ -767,7 +787,7 @@ int RecursiveMigrateDir(const char *pszRelPath, WORKSPACE *ws) {
int FileNameStartPos;

DIR *dirp = NULL;
MIGRATE mig = {};
MIGRATE mig = {0};

// Get our start time for the conversion process of this dir/zip
mig.StartTime = time(NULL);
Expand Down Expand Up @@ -883,7 +903,7 @@ int RecursiveMigrateTop(const char *pszRelPath, WORKSPACE *ws) {
char szRelPathBuf[MAX_PATH + 1];
int n;
struct stat istat;
MIGRATE mig = {};
MIGRATE mig = {0};

mig.StartTime = time(NULL);

Expand Down
10 changes: 8 additions & 2 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#define NDEBUG
#include <assert.h>

#include "global.h"
#include "util.h"

#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif

// The canonical order is case insensitive, but we need a tie-breaker
// to avoid ambiguity
int CanonicalCmp(const char *s1, const char *s2) {
Expand Down Expand Up @@ -221,7 +227,7 @@ const char *UpdateFile(const char *dest, const char *tmpfile) {
"Please replace the file manually.";
else
return "Unable to remove destination for replacement (temporary "
"file removed)."
"file removed).";
}
if (rename(tmpfile, dest))
return "The original file has already been deleted, so you must rename "
Expand Down

0 comments on commit 45d222e

Please sign in to comment.