2024-01-28 15:16:11 +00:00
|
|
|
/* SPDX-FileCopyrightText: © 2023-2024 Decompollaborate */
|
2023-02-23 16:50:05 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks every the version numbers of every built package to be the same
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rabbitizer.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
|
|
const char *const tomlPaths[] = {
|
|
|
|
"pyproject.toml",
|
|
|
|
"Cargo.toml",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-09-13 13:45:11 +00:00
|
|
|
// returns negative value on error
|
2023-02-23 16:50:05 +00:00
|
|
|
long getFileSize(FILE *file) {
|
|
|
|
long current = ftell(file);
|
|
|
|
long totalSize;
|
2023-09-13 13:45:11 +00:00
|
|
|
int temp;
|
2023-02-23 16:50:05 +00:00
|
|
|
|
2023-09-13 13:45:11 +00:00
|
|
|
if (current == -1L) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = fseek(file, 0L, SEEK_END);
|
|
|
|
if (temp != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2023-02-23 16:50:05 +00:00
|
|
|
totalSize = ftell(file);
|
2023-09-13 13:45:11 +00:00
|
|
|
if (totalSize == -1L) {
|
|
|
|
return -1;
|
|
|
|
}
|
2023-02-23 16:50:05 +00:00
|
|
|
|
2023-09-13 13:45:11 +00:00
|
|
|
temp = fseek(file, current, SEEK_SET);
|
|
|
|
if (temp != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2023-02-23 16:50:05 +00:00
|
|
|
|
|
|
|
return totalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VERSION_STR_TOML "version = \""
|
|
|
|
|
|
|
|
int doVersionCheck(const char *filepath, char *buffer) {
|
|
|
|
char *versionStrPtr = strstr(buffer, VERSION_STR_TOML);
|
|
|
|
char *endVersionStrPtr;
|
|
|
|
|
|
|
|
if (versionStrPtr == NULL) {
|
|
|
|
fprintf(stderr, "Could not find version string in file '%s'\n", filepath);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip initial version stuff
|
|
|
|
versionStrPtr += strlen(VERSION_STR_TOML);
|
|
|
|
|
|
|
|
endVersionStrPtr = strstr(versionStrPtr, "\"");
|
|
|
|
if (endVersionStrPtr == NULL) {
|
|
|
|
fprintf(stderr, "Badly formatted version string in file '%s'\n", filepath);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*endVersionStrPtr = '\0';
|
|
|
|
|
|
|
|
printf("file: '%s', version: '%s'\n", filepath, versionStrPtr);
|
|
|
|
|
|
|
|
if (strcmp(RabVersion_Str, versionStrPtr) != 0) {
|
|
|
|
fprintf(stderr, "Version of file '%s' does not match\n", filepath);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
size_t i;
|
|
|
|
int errorCount = 0;
|
|
|
|
|
|
|
|
printf("C package version: '%s'\n", RabVersion_Str);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_COUNT(tomlPaths); i++) {
|
|
|
|
const char *path = tomlPaths[i];
|
|
|
|
FILE *file;
|
|
|
|
long fileSize;
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
assert(path != NULL);
|
|
|
|
|
|
|
|
file = fopen(path, "r");
|
|
|
|
if (file == NULL) {
|
|
|
|
fprintf(stderr, "Not able to open '%s'\n", path);
|
|
|
|
errorCount++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileSize = getFileSize(file);
|
2023-09-13 13:45:11 +00:00
|
|
|
if (fileSize < 0) {
|
|
|
|
fclose(file);
|
|
|
|
fprintf(stderr, "Failed to get the size of file '%s'\n", path);
|
|
|
|
errorCount++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-23 16:50:05 +00:00
|
|
|
buffer = malloc(fileSize * sizeof(char));
|
|
|
|
if (buffer == NULL) {
|
|
|
|
fclose(file);
|
|
|
|
fprintf(stderr, "Failed to malloc '%zu' bytes\n", fileSize * sizeof(char));
|
|
|
|
errorCount++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-04-03 15:41:26 +00:00
|
|
|
assert(fread(buffer, sizeof(char), fileSize, file) == (size_t)fileSize);
|
2023-02-23 16:50:05 +00:00
|
|
|
|
|
|
|
errorCount += doVersionCheck(path, buffer);
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
return errorCount;
|
|
|
|
}
|