Start working on basic package framework.

This commit is contained in:
Kyle Isom 2023-10-23 22:17:05 -07:00
parent c1629dda81
commit 4f7c5519e2
12 changed files with 348 additions and 17 deletions

67
.clang-format Normal file
View File

@ -0,0 +1,67 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -8
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: TopLevel
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 8
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
QualifierAlignment: Left
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 8
UseTab: ForContinuationAndIndentation

31
.clang-tidy Normal file
View File

@ -0,0 +1,31 @@
Checks: >-
bugprone-*,
cppcoreguidelines-*,
google-*,
misc-*,
modernize-*,
performance-*,
readability-*,
-bugprone-lambda-function-name,
-bugprone-easily-swappable-parameters,
-bugprone-reserved-identifier,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-vararg,
-google-readability-braces-around-statements,
-google-readability-function-size,
-misc-no-recursion,
-modernize-return-braced-init-list,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-performance-unnecessary-value-param,
-readability-identifier-length,
-readability-magic-numbers
CheckOptions:
readability-function-cognitive-complexity.Threshold: 100
readability-function-cognitive-complexity.IgnoreMacros: true
readability-identifier-naming.ClassCase: CamelCase

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,45 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C>
<option name="INDENT_NAMESPACE_MEMBERS" value="0" />
<option name="INDENT_C_STRUCT_MEMBERS" value="8" />
<option name="INDENT_CLASS_MEMBERS" value="8" />
<option name="FUNCTION_BRACE_PLACEMENT" value="2" />
<option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="2" />
</Objective-C>
<clangFormatSettings>
<option name="ENABLED" value="true" />
</clangFormatSettings>
<files>
<extensions>
<pair source="cc" header="h" fileNamingConvention="PASCAL_CASE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
<pair source="cu" header="cuh" fileNamingConvention="NONE" />
<pair source="ixx" header="" fileNamingConvention="NONE" />
<pair source="mxx" header="" fileNamingConvention="NONE" />
<pair source="cppm" header="" fileNamingConvention="NONE" />
<pair source="ccm" header="" fileNamingConvention="NONE" />
<pair source="cxxm" header="" fileNamingConvention="NONE" />
<pair source="c++m" header="" fileNamingConvention="NONE" />
</extensions>
</files>
<codeStyleSettings language="ObjectiveC">
<option name="BLANK_LINES_BEFORE_IMPORTS" value="2" />
<option name="BLANK_LINES_AFTER_IMPORTS" value="2" />
<option name="BLANK_LINES_AROUND_METHOD" value="0" />
<option name="BLANK_LINES_AROUND_METHOD_IN_INTERFACE" value="0" />
<option name="INDENT_CASE_FROM_SWITCH" value="false" />
<option name="ALIGN_GROUP_FIELD_DECLARATIONS" value="true" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<indentOptions>
<option name="INDENT_SIZE" value="8" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="8" />
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/sc3dev.iml" filepath="$PROJECT_DIR$/.idea/sc3dev.iml" />
</modules>
</component>
</project>

2
.idea/sc3dev.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -9,6 +9,14 @@ set(CMAKE_VERBOSE_MAKEFILES ON)
find_package(scsl REQUIRED)
include(FindPkgConfig)
pkg_check_modules(CURLPP REQUIRED curlpp)
if (CURLPP_FOUND)
message(STATUS "Found CURL version: ${CURLPP_VERSION_STRING}")
message(STATUS "Using CURL include dir(s): ${CURLPP_INCLUDE_DIRS}")
message(STATUS "Using CURL lib(s): ${CURLPP_LIBRARIES}")
endif ()
include(CTest)
enable_testing()
@ -34,11 +42,13 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
else ()
# nothing special for gcc at the moment
endif ()
add_compile_definitions(SCSL_DESKTOP_BUILD)
set(HEADERS)
set(SOURCES)
include_directories(SYSTEM include)
include_directories(SYSTEM ${CURLPP_INCLUDE_DIRS})
### THE REAL TARGETS ###

18
cmake-package.sh Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eux
BUILD_TYPE="${BUILD_TYPE:-RelWithDebInfo}"
if [ "${USE_CLANG:-}" == "yes" ]
then
export CC=$(command -v clang)
export CXX=$(command -v clang++)
fi
[[ -d build ]] && rm -rf build
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} .. && make all package
sc3dev-packager --owner ${OWNER:-sc} debian --comp ${COMPONENT:-dev} put *.deb
sc3dev-packager --owner ${OWNER:-sc} generic put *.sh *.tar.gz

View File

@ -5,37 +5,164 @@
/// \brief Packaging tools for shimmering-clarity.
///
#include <filesystem>
#include <iostream>
#include <string>
#include <scsl/Commander.h>
#include <scsl/Flag.h>
#include <scsl/Flags.h>
#include <scsl/SimpleConfig.h>
static struct {
scsl::Flags *flags;
std::string owner;
std::string distribution;
std::string component;
std::string password;
std::string username;
std::string version;
} config;
void
usage(std::ostream &outs, int exc)
{
outs << "sc3dev-packager: manage packages on gitea\n";
outs << "usage:\n";
outs << "\tsc3dev-packager [--component component] [--owner owner] \n";
outs << "\t\t[--distribution distribution] debian command packages ...\n";
outs << "\tsc3dev-packager [--owner owner] generic command packages ...\n";
outs << "\nCommands:\n";
outs << "\t- delete: remove a package\n";
outs << "\t- put: upload a package\n";
exit(exc);
}
std::string
getDefaultConfigFile()
{
auto userEnv = getenv("USER");
auto user = std::string(userEnv);
if (user == "root") {
return std::filesystem::path("/etc/sc3dev/packager.conf");
}
if (user.empty()) {
return "";
}
userEnv = getenv("HOME");
auto userHome = std::filesystem::path(userEnv);
userHome /= std::filesystem::path(".config");
userHome /= std::filesystem::path("sc3dev-packager.conf");
return userHome;
}
static bool
putDebian(std::vector<std::string> args)
{
std::cout << "[+] put Debian package\n";
for (auto &arg: args) {
std::cout << "\t[*] " << arg << "\n";
}
return false;
}
static bool
debianPackager(std::vector<std::string> args)
{
scsl::Commander commander;
commander.Register(scsl::Subcommand("put", 1, putDebian));
std::cout << "[+] Debian packager invoked\n";
for (auto &arg: args) {
std::cout << "\t[*] " << arg << "\n";
}
auto command = args[0];
args.erase(args.cbegin());
return commander.Run(command, args) == scsl::Subcommand::Status::OK;
}
int
main(int argc, char *argv[])
{
config.flags = new scsl::Flags("sc3dev-packager", "package tooling for shimmering clarity");
config.flags->Register("--component", "main", "Debian package component");
config.flags->Register("--distribution", "ubuntu", "Debian package distribution");
config.flags->Register("--owner", "sc", "package repository owner");
int retc;
scsl::Flags *flags;
std::string configFile = getDefaultConfigFile();
std::string owner;
std::string distribution;
std::string component;
std::string version;
auto status = config.flags->Parse(argc, argv);
flags = new scsl::Flags("sc3dev-packager", "package tooling for shimmering clarity");
flags->Register("--config", configFile, "path to a configuration file");
flags->Register("--component", "main", "Debian package component");
flags->Register("--distribution", "ubuntu", "Debian package distribution");
flags->Register("--owner", "sc", "package repository owner");
flags->Register("--version", scsl::FlagType::String, "version to operate on (only matters for delete)");
auto status = flags->Parse(argc, argv);
if (status != scsl::Flags::ParseStatus::OK) {
std::cerr << "failed to parse flags: "
<< scsl::Flags::ParseStatusToString(status)
<< "\n";
<< scsl::Flags::ParseStatusToString(status)
<< "\n";
exit(1);
}
scsl::Commander commander;
commander.Register(scsl::Subcommand("debian", 1, debianPackager));
flags->GetString("--config", configFile);
if (std::filesystem::exists(std::filesystem::path(configFile))) {
if (scsl::SimpleConfig::LoadGlobal(configFile) != 0) {
std::cerr << "[!] failed to read config file " << configFile << ".\n";
exit(1);
}
}
if (flags->GetString("--owner", owner)) {
scsl::SimpleConfig::PutGlobal("owner", owner);
}
if (flags->GetString("--distribution", distribution)) {
scsl::SimpleConfig::PutGlobal("distribution", distribution);
}
if (flags->GetString("--component", component)) {
scsl::SimpleConfig::PutGlobal("component", component);
}
if (flags->GetString("--version", version)) {
scsl::SimpleConfig::PutGlobal("version", version);
}
if (flags->NumArgs() < 1) {
std::cerr << "[!] not enough arguments provided.\n";
exit(1);
}
auto command = flags->Arg(0);
auto args = flags->Args();
args.erase(args.begin());
auto result = commander.Run(command, args);
delete flags;
switch (result) {
case scsl::Subcommand::Status::OK:
std::cout << "[+] OK\n";
retc = 0;
break;
case scsl::Subcommand::Status::NotEnoughArgs:
usage(std::cerr, 1);
break;
case scsl::Subcommand::Status::Failed:
std::cerr << "[!] '" << command << "' failed\n";
break;
case scsl::Subcommand::Status::CommandNotRegistered:
std::cerr << "[!] '" << command << "' not registered.\n";
usage(std::cerr, 1);
break;
default:
abort();
}
return retc;
}