1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 04:17:33 +00:00

Build improvements (external libs, enable more options). (#498)

- Enable build options by default if they don't require external libraries.
 - Add as many external libraries to Docker and Travis builds as possible.
This commit is contained in:
Brenden Matthews 2018-05-13 13:33:18 -04:00 committed by GitHub
parent 8dbb623255
commit b9121daa89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 211 additions and 71 deletions

View File

@ -22,6 +22,22 @@ matrix:
- libcairo2-dev
- libimlib2-dev
- libxinerama-dev
- libmysqlclient-dev
- libical-dev
- libircclient-dev
- libcairo2-dev
- libmicrohttpd-dev
- ncurses-dev
- liblua5.1-dev
- librsvg2-dev
- libaudclient-dev
- libxmmsclient-dev
- libpulse-dev
- libcurl4-gnutls-dev
- audacious-dev
- libsystemd-journal-dev
- libxml2-dev
- tolua++
- gawk
env:
- MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
@ -46,6 +62,22 @@ matrix:
- libcairo2-dev
- libimlib2-dev
- libxinerama-dev
- libmysqlclient-dev
- libical-dev
- libircclient-dev
- libcairo2-dev
- libmicrohttpd-dev
- ncurses-dev
- liblua5.1-dev
- librsvg2-dev
- libaudclient-dev
- libxmmsclient-dev
- libpulse-dev
- libcurl4-gnutls-dev
- audacious-dev
- libsystemd-journal-dev
- libxml2-dev
- tolua++
- gawk
sonarcloud:
organization: "brndnmtthws-github"
@ -57,11 +89,44 @@ before_install:
- eval "${MATRIX_EVAL}"
before_script:
- mkdir build && cd build
- cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
- >
cmake
-DBUILD_MYSQL=ON
-DBUILD_LUA_CAIRO=ON
-DBUILD_LUA_IMLIB2=ON
-DBUILD_LUA_RSVG=ON
-DBUILD_LUA_CAIRO=ON
-DBUILD_AUDACIOUS=ON
-DBUILD_XMMS2=ON
-DBUILD_ICAL=ON
-DBUILD_IRC=ON
-DBUILD_HTTP=ON
-DBUILD_ICONV=ON
-DBUILD_PULSEAUDIO=ON
-DBUILD_JOURNAL=ON
-DBUILD_RSS=ON
..
- cd ..
- mkdir build-no-x11
- cd build-no-x11
- cmake -DBUILD_X11=OFF ..
- >
cmake
-DBUILD_X11=OFF
-DBUILD_MYSQL=ON
-DBUILD_LUA_CAIRO=ON
-DBUILD_LUA_IMLIB2=ON
-DBUILD_LUA_RSVG=ON
-DBUILD_LUA_CAIRO=ON
-DBUILD_AUDACIOUS=ON
-DBUILD_XMMS2=ON
-DBUILD_ICAL=ON
-DBUILD_IRC=ON
-DBUILD_HTTP=ON
-DBUILD_ICONV=ON
-DBUILD_PULSEAUDIO=ON
-DBUILD_JOURNAL=ON
-DBUILD_RSS=ON
..
- cd ..
script:
- cd build

View File

@ -1,22 +1,71 @@
FROM ubuntu:latest
RUN apt-get update \
&& apt-get install -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qy \
cmake \
git \
g++ \
libimlib2-dev \
liblua5.3-dev \
libxext-dev \
libxft-dev \
libxdamage-dev \
libxinerama-dev \
ncurses-dev
libmysqlclient-dev \
libical-dev \
libircclient-dev \
libcairo2-dev \
libmicrohttpd-dev \
ncurses-dev \
liblua5.1-dev \
librsvg2-dev \
libaudclient-dev \
libxmmsclient-dev \
libpulse-dev \
libcurl4-gnutls-dev \
audacious-dev \
libsystemd-dev \
libxml2-dev \
tolua++
COPY . /conky
WORKDIR /conky/build
ARG X11=yes
RUN sh -c 'if [ "$X11" = "yes" ] ; then cmake ../ ; else cmake -DBUILD_X11=OFF ../ ; fi' \
RUN sh -c 'if [ "$X11" = "yes" ] ; then \
cmake \
-DBUILD_MYSQL=ON \
-DBUILD_LUA_CAIRO=ON \
-DBUILD_LUA_IMLIB2=ON \
-DBUILD_LUA_RSVG=ON \
-DBUILD_LUA_CAIRO=ON \
-DBUILD_AUDACIOUS=ON \
-DBUILD_XMMS2=ON \
-DBUILD_ICAL=ON \
-DBUILD_IRC=ON \
-DBUILD_HTTP=ON \
-DBUILD_ICONV=ON \
-DBUILD_PULSEAUDIO=ON \
-DBUILD_JOURNAL=ON \
-DBUILD_RSS=ON \
../ \
; else \
cmake \
-DBUILD_X11=OFF \
-DBUILD_MYSQL=ON \
-DBUILD_LUA_CAIRO=ON \
-DBUILD_LUA_IMLIB2=ON \
-DBUILD_LUA_RSVG=ON \
-DBUILD_LUA_CAIRO=ON \
-DBUILD_AUDACIOUS=ON \
-DBUILD_XMMS2=ON \
-DBUILD_ICAL=ON \
-DBUILD_IRC=ON \
-DBUILD_HTTP=ON \
-DBUILD_ICONV=ON \
-DBUILD_PULSEAUDIO=ON \
-DBUILD_JOURNAL=ON \
-DBUILD_RSS=ON \
../ \
; fi' \
&& make -j5 all \
&& make -j5 install \
&& apt-get remove -y \
@ -24,12 +73,26 @@ RUN sh -c 'if [ "$X11" = "yes" ] ; then cmake ../ ; else cmake -DBUILD_X11=OFF .
git \
g++ \
libimlib2-dev \
liblua5.3-dev \
libxext-dev \
libxft-dev \
libxdamage-dev \
libxinerama-dev \
libmysqlclient-dev \
libical-dev \
libircclient-dev \
libcairo2-dev \
libmicrohttpd-dev \
ncurses-dev \
liblua5.1-dev \
librsvg2-dev \
audacious-dev \
libaudclient-dev \
libxmmsclient-dev \
libpulse-dev \
libcurl4-gnutls-dev \
libsystemd-dev \
libxml2-dev \
tolua++ \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /conky \

View File

@ -43,6 +43,8 @@ if(MAINTAINER_MODE)
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -Wall -W -Wextra -Wunused -pedantic -Werror -Wno-format ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
endif(MAINTAINER_MODE)
option(CHECK_CODE_QUALITY "Check code formatting/quality with clang" false)
option(RELEASE "Build release package" false)
mark_as_advanced(RELEASE)
@ -146,14 +148,14 @@ option(BUILD_MOC "Enable if you want MOC (music player) support" true)
option(BUILD_XMMS2 "Enable if you want XMMS2 (music player) support" false)
option(BUILD_EVE "Enable if you want Eve-Online skill monitoring support" false)
option(BUILD_EVE "Enable if you want Eve-Online skill monitoring support" true)
option(BUILD_CURL "Enable if you want Curl support" false)
option(BUILD_RSS "Enable if you want RSS support" false)
option(BUILD_WEATHER_METAR "Enable METAR weather support" false)
option(BUILD_WEATHER_XOAP "Enable XOAP weather support" false)
option(BUILD_WEATHER_METAR "Enable METAR weather support" true)
option(BUILD_WEATHER_XOAP "Enable XOAP weather support" true)
if(BUILD_WEATHER_METAR OR BUILD_WEATHER_XOAP OR BUILD_RSS)
set(BUILD_CURL true)
endif(BUILD_WEATHER_METAR OR BUILD_WEATHER_XOAP OR BUILD_RSS)
@ -174,10 +176,8 @@ endif(BUILD_HTTP)
option(BUILD_ICONV "Enable iconv support" false)
option(BUILD_CMUS "Enable support for cmus music player" false)
option(BUILD_CMUS "Enable support for cmus music player" true)
option(BUILD_JOURNAL "Enable support for reading from the systemd journal" false)
option(BUILD_PULSEAUDIO "Enable support for Pulseaudio's default sink and source" false)
option(CHECK_CODE_QUALITY "Check code formatting/quality with clang" false)

View File

@ -422,7 +422,7 @@ if(BUILD_IMLIB2)
endif(BUILD_IMLIB2)
if(BUILD_JOURNAL)
pkg_search_module(SYSTEMD REQUIRED libsystemd)
pkg_search_module(SYSTEMD REQUIRED libsystemd libsystemd-journal)
set(conky_libs ${conky_libs} ${SYSTEMD_LIB} ${SYSTEMD_LDFLAGS})
set(conky_includes ${conky_includes} ${SYSTEMD_INCLUDE_PATH})
endif(BUILD_JOURNAL)

View File

@ -27,11 +27,13 @@
#include <curl/curl.h>
#include "logging.h"
#include "update-cb.hh"
namespace priv {
// factored out stuff that does not depend on the template parameters
struct curl_internal {
class curl_internal {
public:
std::string last_modified;
std::string etag;
std::string data;
@ -47,7 +49,7 @@ struct curl_internal {
// it should populate the result variable
virtual void process_data() = 0;
curl_internal(const std::string &url);
explicit curl_internal(const std::string &url);
virtual ~curl_internal() {
if (curl) curl_easy_cleanup(curl);
}
@ -60,7 +62,7 @@ struct curl_internal {
*/
template <typename Result, typename... Keys>
class curl_callback : public conky::callback<Result, std::string, Keys...>,
protected priv::curl_internal {
public priv::curl_internal {
typedef conky::callback<Result, std::string, Keys...> Base1;
typedef priv::curl_internal Base2;

View File

@ -30,6 +30,7 @@
#include <ctype.h>
#include <string.h>
#include <systemd/sd-journal.h>
#include <time.h>
#include <unistd.h>
#include <memory>
#include "common.h"
@ -39,8 +40,13 @@
#include "text_object.h"
#define MAX_JOURNAL_LINES 200
#ifndef SD_JOURNAL_SYSTEM
// SD_JOURNAL_SYSTEM added and SD_JOURNAL_SYSTEM_ONLY deprecated in systemd-205
#define SD_JOURNAL_SYSTEM SD_JOURNAL_SYSTEM_ONLY
#endif /* SD_JOURNAL_SYSTEM */
struct journal {
class journal {
public:
int wantedlines;
int flags;
@ -48,7 +54,7 @@ struct journal {
};
void free_journal(struct text_object *obj) {
struct journal *j = (struct journal *)obj->data.opaque;
journal *j = (journal *)obj->data.opaque;
obj->data.opaque = nullptr;
delete j;
}
@ -56,7 +62,7 @@ void free_journal(struct text_object *obj) {
void init_journal(const char *type, const char *arg, struct text_object *obj,
void *free_at_crash) {
unsigned int args;
struct journal *j = new journal;
journal *j = new journal;
std::unique_ptr<char[]> tmp(new char[DEFAULT_TEXT_BUFFER_SIZE]);
memset(tmp.get(), 0, DEFAULT_TEXT_BUFFER_SIZE);
@ -73,8 +79,10 @@ void init_journal(const char *type, const char *arg, struct text_object *obj,
if (args > 1) {
if (strcmp(tmp.get(), "system") == 0) {
j->flags |= SD_JOURNAL_SYSTEM;
#ifdef SD_JOURNAL_CURRENT_USER // not present in older version of systemd
} else if (strcmp(tmp.get(), "user") == 0) {
j->flags |= SD_JOURNAL_CURRENT_USER;
#endif /* SD_JOURNAL_CURRENT_USER */
} else {
free_journal(obj);
CRIT_ERR(obj, free_at_crash,
@ -110,12 +118,38 @@ out:
return length ? length - fieldlen : 0;
}
bool read_log(size_t *read, size_t *length, time_t *time, uint64_t *timestamp,
sd_journal *jh, char *p, int p_max_size) {
struct tm tm;
if (sd_journal_get_realtime_usec(jh, timestamp) < 0) return false;
*time = *timestamp / 1000000;
localtime_r(time, &tm);
if ((*length =
strftime(p + *read, p_max_size - *read, "%b %d %H:%M:%S", &tm)) <= 0)
return false;
*read += *length;
p[*read++] = ' ';
if (print_field(jh, "_HOSTNAME", ' ', read, p, p_max_size) < 0) return false;
if (print_field(jh, "SYSLOG_IDENTIFIER", '[', read, p, p_max_size) < 0)
return false;
if (print_field(jh, "_PID", ']', read, p, p_max_size) < 0) return false;
p[*read++] = ':';
p[*read++] = ' ';
if (print_field(jh, "MESSAGE", '\n', read, p, p_max_size) < 0) return false;
return true;
}
void print_journal(struct text_object *obj, char *p, int p_max_size) {
size_t read = 0, length;
struct journal *j = (struct journal *)obj->data.opaque;
sd_journal *jh = nullptr;
struct tm *tm;
size_t read = 0;
size_t length;
time_t time;
uint64_t timestamp;
@ -123,7 +157,6 @@ void print_journal(struct text_object *obj, char *p, int p_max_size) {
NORM_ERR("unable to open journal");
goto out;
}
if (!j) return;
if (sd_journal_seek_tail(jh) < 0) {
NORM_ERR("unable to seek to end of journal");
@ -134,32 +167,11 @@ void print_journal(struct text_object *obj, char *p, int p_max_size) {
goto out;
}
do {
if (sd_journal_get_realtime_usec(jh, &timestamp) < 0) break;
time = timestamp / 1000000;
tm = localtime(&time);
if ((length =
strftime(p + read, p_max_size - read, "%b %d %H:%M:%S", tm)) <= 0)
break;
read += length;
p[read++] = ' ';
if (print_field(jh, "_HOSTNAME", ' ', &read, p, p_max_size) < 0) break;
if (print_field(jh, "SYSLOG_IDENTIFIER", '[', &read, p, p_max_size) < 0)
break;
if (print_field(jh, "_PID", ']', &read, p, p_max_size) < 0) break;
p[read++] = ':';
p[read++] = ' ';
if (print_field(jh, "MESSAGE", '\n', &read, p, p_max_size) < 0) break;
} while (sd_journal_next(jh));
while (read_log(&read, &length, &time, &timestamp, jh, p, p_max_size) &&
sd_journal_next(jh))
;
out:
if (jh) sd_journal_close(jh);
p[read] = '\0';
return;
}

View File

@ -26,9 +26,9 @@
*
*/
#include "mysql.h"
#include "conky.h"
#include "logging.h"
#include "mysql.h"
#include <mysql.h>
@ -44,6 +44,12 @@ conky::simple_config_setting<std::string> password("mysql_password",
conky::simple_config_setting<std::string> db("mysql_db", "mysql", false);
} // namespace
void mysql_finish(MYSQL *conn, MYSQL_RES *res) {
if (nullptr != res) { mysql_free_result(res); }
mysql_close(conn);
mysql_library_end();
}
void print_mysql(struct text_object *obj, char *p, int p_max_size) {
MYSQL *conn = mysql_init(nullptr);
MYSQL_RES *res = nullptr;
@ -58,16 +64,19 @@ void print_mysql(struct text_object *obj, char *p, int p_max_size) {
password.get(*state).c_str(), db.get(*state).c_str(),
port.get(*state), nullptr, 0)) {
NORM_ERR("MySQL: %s", mysql_error(conn));
goto error;
mysql_finish(conn, res);
return;
}
if (mysql_query(conn, obj->data.s)) {
NORM_ERR("MySQL: %s", mysql_error(conn));
goto error;
mysql_finish(conn, res);
return;
}
res = mysql_use_result(conn);
if (res == nullptr) {
NORM_ERR("MySQL: %s", mysql_error(conn));
goto error;
mysql_finish(conn, res);
return;
}
MYSQL_ROW row = mysql_fetch_row(res);
if (row) {
@ -75,12 +84,5 @@ void print_mysql(struct text_object *obj, char *p, int p_max_size) {
} else {
NORM_ERR("MySQL: '%s' returned no results", obj->data.s);
}
error:
if (nullptr != res) {
mysql_free_result(res);
}
mysql_close(conn);
mysql_library_end();
return;
mysql_finish(conn, res);
}

View File

@ -19,6 +19,7 @@
#define PRSS_H
#include <libxml/parser.h>
#include <string>
typedef struct PRSS_Item_ {
char *title;
@ -29,7 +30,8 @@ typedef struct PRSS_Item_ {
char *guid;
} PRSS_Item;
struct PRSS {
class PRSS {
public:
char *version;
char *title;
@ -48,7 +50,7 @@ struct PRSS {
PRSS_Item *items;
int item_count;
PRSS(const std::string &xml_data);
explicit PRSS(const std::string &xml_data);
~PRSS();
};

View File

@ -52,9 +52,7 @@ static void user_num(int *ptr) {
setutent();
while ((usr = getutent()) != nullptr) {
if (usr->ut_type == USER_PROCESS) {
++users_num;
}
if (usr->ut_type == USER_PROCESS) { ++users_num; }
}
*ptr = users_num;
}
@ -97,9 +95,7 @@ static void tty_user_time(char *ptr, char *tty) {
setutent();
strcpy(line.ut_line, tty);
usr = getutline(&line);
if (usr == nullptr) {
return;
}
if (usr == nullptr) { return; }
log_in = usr->ut_time;
@ -159,9 +155,7 @@ int update_users(void) {
}
user_num(&t);
if (t != 0) {
if (current_info->users.number) {
current_info->users.number = 0;
}
if (current_info->users.number) { current_info->users.number = 0; }
current_info->users.number = t;
} else {
current_info->users.number = 0;