From 7a1e74b1e7d9e0cb5ddce954df862db342626551 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Thu, 16 Jan 2020 09:08:02 +0700 Subject: [PATCH 1/3] --output-to-dir added --- dstep/Configuration.d | 7 +++++-- dstep/driver/Application.d | 8 ++++---- dstep/driver/CommandLine.d | 7 ++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dstep/Configuration.d b/dstep/Configuration.d index 3ea9ec1e..a0c717a1 100644 --- a/dstep/Configuration.d +++ b/dstep/Configuration.d @@ -34,8 +34,11 @@ struct Configuration /// array of parameters needed to be forwarded to clang driver string[] clangParams; - /// output file name or folder (in case there are many input files) - string output; + /// output file name or folder + string outputPath; + + /// in case there are many input files or dir output option provided + bool isOutputToDir; /// package name @("package", "Use as package name.") diff --git a/dstep/driver/Application.d b/dstep/driver/Application.d index 45ef1caa..2e4ccee3 100644 --- a/dstep/driver/Application.d +++ b/dstep/driver/Application.d @@ -125,16 +125,16 @@ class Application // when only one input file is supplied, -o argument is // interpreted as file path, otherwise as base directory path - if (inputFiles.length == 1) + if (!config.isOutputToDir) { - return [config.output.empty + return [config.outputPath.empty ? makeDefaultOutputFile(inputFiles.front, false) - : config.output]; + : config.outputPath]; } else { alias fmap = file => Path.buildPath( - config.output, + config.outputPath, makeDefaultOutputFile(file, false)); return inputFiles.map!fmap.array; diff --git a/dstep/driver/CommandLine.d b/dstep/driver/CommandLine.d index 346eca67..9ccc4e05 100644 --- a/dstep/driver/CommandLine.d +++ b/dstep/driver/CommandLine.d @@ -67,11 +67,15 @@ auto parseCommandLine(string[] args) args, std.getopt.config.passThrough, std.getopt.config.caseSensitive, - "output|o", &config.output, + "output|o", &config.outputPath, + "output-to-dir|O", &config.isOutputToDir, "objective-c", &forceObjectiveC, "language|x", &parseLanguage, makeGetOptArgs!config); + if(config.inputFiles.length == 1) + config.isOutputToDir = true; + // remove dstep binary name (args[0]) args = args[1 .. $]; @@ -239,6 +243,7 @@ void showHelp (Configuration config, GetoptResult getoptResult) auto customEntries = [ Entry("-o, --output ", "Write output to ."), Entry("-o, --output ", "Write all the files to , in case of multiple input files."), + Entry("-O, --output-to-dir", "Force write files to ."), Entry("-ObjC, --objective-c", "Treat source input file as Objective-C input."), Entry("-x, --language", "Treat subsequent input files as having type .")]; From 42a44340756aab7888fe44b7597522773f15964f Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Thu, 16 Jan 2020 10:26:49 +0700 Subject: [PATCH 2/3] --input-from-dir added --- dstep/Configuration.d | 3 +++ dstep/driver/CommandLine.d | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dstep/Configuration.d b/dstep/Configuration.d index a0c717a1..53cef86c 100644 --- a/dstep/Configuration.d +++ b/dstep/Configuration.d @@ -20,6 +20,9 @@ struct Configuration /// array of file names to translate to D string[] inputFiles; + /// in case if there are many input files in one dir + bool isInputFromDir; + /// expected programming language of input files Language language; diff --git a/dstep/driver/CommandLine.d b/dstep/driver/CommandLine.d index 9ccc4e05..1739d3ee 100644 --- a/dstep/driver/CommandLine.d +++ b/dstep/driver/CommandLine.d @@ -67,15 +67,13 @@ auto parseCommandLine(string[] args) args, std.getopt.config.passThrough, std.getopt.config.caseSensitive, + "input-from-dir|I", &config.isInputFromDir, "output|o", &config.outputPath, "output-to-dir|O", &config.isOutputToDir, "objective-c", &forceObjectiveC, "language|x", &parseLanguage, makeGetOptArgs!config); - if(config.inputFiles.length == 1) - config.isOutputToDir = true; - // remove dstep binary name (args[0]) args = args[1 .. $]; @@ -88,6 +86,28 @@ auto parseCommandLine(string[] args) config.inputFiles ~= arg; } + if(config.isInputFromDir) + { + import std.exception : enforce; + import std.file; + import std.algorithm; + import std.algorithm.iteration; + import std.array; + + enforce!DStepException(config.inputFiles.length == 1, + "dstep: error: must supply only one input directory\n"); + + config.inputFiles = dirEntries(config.inputFiles[0], SpanMode.depth) + .filter!(f => f.name.endsWith(".h")) + .map!(a => a.name).array; + + import std.stdio; + config.inputFiles.writeln; + } + + if(config.isInputFromDir || config.inputFiles.length > 1) + config.isOutputToDir = true; + // Post-processing of CLI import std.algorithm : canFind; @@ -244,6 +264,7 @@ void showHelp (Configuration config, GetoptResult getoptResult) Entry("-o, --output ", "Write output to ."), Entry("-o, --output ", "Write all the files to , in case of multiple input files."), Entry("-O, --output-to-dir", "Force write files to ."), + Entry("-I, --input-from-dir", "Force to treat as directory. Reads only *.h files."), Entry("-ObjC, --objective-c", "Treat source input file as Objective-C input."), Entry("-x, --language", "Treat subsequent input files as having type .")]; From 704db78d1919317e5bfa37b35de7cd3e9738ea7a Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Thu, 16 Jan 2020 11:04:30 +0700 Subject: [PATCH 3/3] debug output removed --- dstep/driver/CommandLine.d | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dstep/driver/CommandLine.d b/dstep/driver/CommandLine.d index 1739d3ee..7bb64d4d 100644 --- a/dstep/driver/CommandLine.d +++ b/dstep/driver/CommandLine.d @@ -99,10 +99,8 @@ auto parseCommandLine(string[] args) config.inputFiles = dirEntries(config.inputFiles[0], SpanMode.depth) .filter!(f => f.name.endsWith(".h")) - .map!(a => a.name).array; - - import std.stdio; - config.inputFiles.writeln; + .map!(a => a.name) + .array; } if(config.isInputFromDir || config.inputFiles.length > 1)