2 Commit-ok 3a52c763a8 ... a01919bc6f

Szerző SHA1 Üzenet Dátum
  mio a01919bc6f Add meson build files 1 hónapja
  mio 7fab34f3fe Use OS 'state' directory for logs (XDG) 1 hónapja

+ 19 - 0
ChangeLog

@@ -1,3 +1,22 @@
+2024-10-12  mio  <stigma@disroot.org>
+
+	Add meson build files
+	(not tested on macOS yet)
+
+	This will probably take over the autoconf files that are currently
+	present.  Not that I have anything against autoconf, but meson supports
+	D out of the box.
+
+	There is still some more changes to the meson files that I need to work
+	out (such as vcs_tag).
+
+	The autoconf files will be removed after 2024.10 release.
+
+2024-10-12  mio  <stigma@disroot.org>
+
+	Use OS 'state' directory for logs (XDG)
+	See: https://codeberg.org/supercell/pixiv_down/issues/33
+
 2024-09-25  mio  <stigma@disroot.org>
 
 	Add docs/Makefile.am

+ 7 - 0
meson.build

@@ -0,0 +1,7 @@
+project('pixiv_down', 'd',
+	license: 'GPL-3.0-only',
+	version: '2024.09'
+)
+
+subdir('source')
+subdir('docs')

+ 2 - 72
source/app.d

@@ -20,8 +20,6 @@ import configuration;
 import std.experimental.logger;
 import pd_version : PIXIV_DOWN_VERSION;
 
-enum kPixivDownLogFileName = "pixiv_down.log";
-
 version(PD_USE_GAMUT)
 {
    pragma(msg, "NOTE: pixiv_down doesn't make proper use of gamut yet. GIFs won't download successfully.");
@@ -158,70 +156,6 @@ void logLibGMVersion()
 
 } // version(PD_USE_MAGICK)
 
-void setupLoggerFromEnvironment()
-{
-   import std.process : environment;
-   import std.stdio : stderr;
-   import std.uni : toLower;
-   import logger;
-
-   LogLevel level = LogLevel.warning;
-   if ("PIXIV_DOWN_LOG_LEVEL" in environment) {
-      const value = environment["PIXIV_DOWN_LOG_LEVEL"].toLower;
-      switch(value) {
-      case "all":
-         level = LogLevel.all;
-         break;
-      case "trace":
-         level = LogLevel.trace;
-         break;
-      case "info":
-         level = LogLevel.info;
-         break;
-      case "debug":
-         stderr.writeln("NOTE: The 'debug' log level is no longer supported.");
-         stderr.writeln("      Falling back to 'warning'.");
-         level = LogLevel.warning;
-         break;
-      case "warning":
-         level = LogLevel.warning;
-         break;
-      case "error":
-         level = LogLevel.error;
-         break;
-      case "fatal":
-         level = LogLevel.fatal;
-         break;
-      default:
-         stderr.writeln("Unknown log level: ", level);
-         stderr.writeln("Supported values are: trace, info, warning, error, and fatal.");
-         break;
-      }
-   }
-
-   static if (__VERSION__ < 2101L) {
-      sharedLog = new PDLogger(kPixivDownLogFileName, level);
-   } else {
-      sharedLog = cast(shared(PDLogger))new PDLogger(kPixivDownLogFileName, level);
-   }
-}
-
-void logCompilationInfo()
-{
-   const bits = (void*).sizeof == 8 ? "64" : "32";
-   version (linux)
-      const system = "Linux";
-   else version (Windows)
-      const system = "Windows";
-   else version (OSX)
-      const system = "macOS";
-   else
-      const system = "Unknown";
-
-   infof("pixiv_down %s started", PIXIV_DOWN_VERSION);
-   infof("Running on %s | %s-bit build | %s %,?d", system, bits, __VENDOR__, '.', __VERSION__);
-}
-
 /// Returns the two character locale set in the environment.
 string getLocale()
 {
@@ -257,6 +191,7 @@ int main(string[] args)
    import pixiv : fetchCSRFToken;
    import std.stdio : stderr, writeln, writefln;
    import std.file : exists, remove;
+   import logger: initializeLogger;
 
    auto subcmds = [
       "artist": &artistHandle,
@@ -345,12 +280,7 @@ int main(string[] args)
       return 2;
    }
 
-   if (exists(kPixivDownLogFileName)) {
-      remove(kPixivDownLogFileName);
-   }
-
-   setupLoggerFromEnvironment();
-   logCompilationInfo();
+   initializeLogger();
 
 version(PD_USE_MAGICK)
 {

+ 11 - 0
source/cmds/meson.build

@@ -0,0 +1,11 @@
+pixiv_down_files += files(
+	'artist.d',
+	'artwork.d',
+	'bookmarked.d',
+	'compact.d',
+	'daily.d',
+	'following.d',
+	'novel.d',
+	'package.d',
+	'prune.d'
+)

+ 13 - 0
source/gif_writer/meson.build

@@ -0,0 +1,13 @@
+if host_machine.system() == 'darwin'
+	pixiv_down_files += files(
+		'common.d',
+		'osx.d',
+		'package.d'
+	)
+else
+	pixiv_down_files += files(
+		'common.d',
+		'package.d',
+		'posix.d'
+	)
+endif

+ 11 - 0
source/image_reader/meson.build

@@ -0,0 +1,11 @@
+if host_machine.system() == 'darwin'
+	pixiv_down_files += files(
+		'osx.d',
+		'package.d'
+	)
+else
+	pixiv_down_files += files(
+		'package.d',
+		'posix.d'
+	)
+endif

+ 3 - 0
source/imaging/meson.build

@@ -0,0 +1,3 @@
+pixiv_down_files += files(
+	'magick.d'
+)

+ 82 - 2
source/logger.d

@@ -17,14 +17,94 @@
 module logger;
 
 import std.experimental.logger;
+import pd_version : PIXIV_DOWN_VERSION;
+
+void initializeLogger()
+{
+   import std.process : environment;
+   import std.stdio : stderr;
+   import std.uni : toLower;
+
+   LogLevel level = LogLevel.warning;
+   if ("PIXIV_DOWN_LOG_LEVEL" in environment) {
+      const value = environment["PIXIV_DOWN_LOG_LEVEL"].toLower;
+      switch(value) {
+      case "all":
+         level = LogLevel.all;
+         break;
+      case "trace":
+         level = LogLevel.trace;
+         break;
+      case "info":
+         level = LogLevel.info;
+         break;
+      case "debug":
+         stderr.writeln("NOTE: The 'debug' log level is no longer supported.");
+         stderr.writeln("      Falling back to 'warning'.");
+         level = LogLevel.warning;
+         break;
+      case "warning":
+         level = LogLevel.warning;
+         break;
+      case "error":
+         level = LogLevel.error;
+         break;
+      case "fatal":
+         level = LogLevel.fatal;
+         break;
+      default:
+         stderr.writeln("Unknown log level: ", level);
+         stderr.writeln("Supported values are: trace, info, warning, error, and fatal.");
+         break;
+      }
+   }
+
+   static if (__VERSION__ < 2101L) {
+      sharedLog = new PDLogger(level);
+   } else {
+      sharedLog = cast(shared(PDLogger))new PDLogger(level);
+   }
+
+   logCompilationInfo();
+}
+
+private void logCompilationInfo()
+{
+   const bits = (void*).sizeof == 8 ? "64" : "32";
+   version (linux)
+      const system = "Linux";
+   else version (Windows)
+      const system = "Windows";
+   else version (OSX)
+      const system = "macOS";
+   else
+      const system = "Unknown";
+
+   infof("pixiv_down %s started", PIXIV_DOWN_VERSION);
+   infof("Running on %s | %s-bit build | %s %,?d", system, bits, __VENDOR__, '.', __VERSION__);
+}
 
 class PDLogger : FileLogger {
    import std.concurrency : Tid;
    import std.datetime.systime : SysTime;
+   import mlib.directories;
+
+   private ProjectDirectories projectDirs;
+   const string fileName;
 
-   this(string filename, const LogLevel level = LogLevel.all) @safe
+   this(const LogLevel level = LogLevel.all) @safe
    {
-      super(filename, level);
+      import std.file: exists, remove;
+      import std.path: buildPath;
+
+      projectDirs = getProjectDirectories(null, "YumeNeru Software", "pixiv_down");
+      fileName = buildPath(projectDirs.stateDir, "pixiv_down.log");
+
+      if (exists(fileName))
+      {
+         remove(fileName);
+      }
+      super(fileName, level);
    }
 
    override protected void beginLogMsg(string file, int line, string funcName,

+ 29 - 0
source/meson.build

@@ -0,0 +1,29 @@
+pixiv_down_files = files(
+	'app.d',
+	'configuration.d',
+	'logger.d',
+	'pd_version.d',
+	'pixiv.d',
+	'pixiv_downloader.d',
+	'term.d',
+	'util.d'
+)
+
+subdir('cmds')
+subdir('gif_writer')
+subdir('image_reader')
+subdir('imaging')
+subdir('mlib')
+
+if host_machine.system() == 'darwin'
+	d_versions = []
+else
+	d_versions = ['PD_USE_MAGICK']
+endif
+
+executable(meson.project_name(),
+	sources: pixiv_down_files,
+	d_import_dirs: include_directories('res'),
+	d_module_versions: d_versions,
+	install: true
+)

+ 0 - 0
source/mlib/meson.build


Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott