From dc90942bb87391db9c34edca788b9b738276821c Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Thu, 10 Dec 2015 23:55:37 +0100 Subject: [PATCH] started background tool that compiles native project with gc or ldc --- cegdcldc/cegdcldc.coedit | 24 ++++++++++ cegdcldc/main.d | 72 +++++++++++++++++++++++++++++ cegdcldc/readme.md | 4 ++ lazproj/test/coeditproj/test.coedit | 16 +++---- lazproj/test/src/main.d | 2 +- src/ce_dubproject.pas | 8 ++-- src/ce_nativeproject.pas | 56 ++++++++++++---------- 7 files changed, 143 insertions(+), 39 deletions(-) create mode 100644 cegdcldc/cegdcldc.coedit create mode 100644 cegdcldc/main.d create mode 100644 cegdcldc/readme.md diff --git a/cegdcldc/cegdcldc.coedit b/cegdcldc/cegdcldc.coedit new file mode 100644 index 00000000..828099aa --- /dev/null +++ b/cegdcldc/cegdcldc.coedit @@ -0,0 +1,24 @@ +object CurrentProject: TCENativeProject + OptionsCollection = < + item + name = 'default' + outputOptions.boundsCheck = onAlways + pathsOptions.outputFilename = '../bin/cegdcldc' + runOptions.options = [poUsePipes, poStderrToOutPut] + runOptions.parameters.Strings = ( + '-main' + '-gdc' + ) + end + item + name = 'release' + outputOptions.inlining = True + outputOptions.boundsCheck = offAlways + outputOptions.optimizations = True + outputOptions.release = True + end> + Sources.Strings = ( + 'main.d' + ) + ConfigurationIndex = 0 +end diff --git a/cegdcldc/main.d b/cegdcldc/main.d new file mode 100644 index 00000000..31b64b06 --- /dev/null +++ b/cegdcldc/main.d @@ -0,0 +1,72 @@ +module cegdcldc; + +import + core.thread, std.stdio, std.process, std.file; + +void convertToGdc(string option, ref string[] options) +{ + // files + if (option.exists) + options ~= option; + // switches + else switch(option) + { + default: break; + case "w": break; + case "wi": break; + } +} + +void convertToLdc2(string option, ref string[] options) +{ + // files + if (option.exists) + options ~= option; + // switches + switch(option) + { + default: break; + case "w": break; + case "wi": break; + } +} + +int main(string[] args) +{ + string[] commandLine = [readln]; + + if (args.length == 1) + return 1; + + if (commandLine[0] != "gdc" && commandLine[0] != "ldc2") + return 2; + + switch(commandLine[0]) + { + case "gdc": + foreach(option; args[1..$]) + convertToGdc(option, commandLine); + break; + case "ldc2": + foreach(option; args[1..$]) + convertToLdc2(option, commandLine); + break; + default: break; + } + + ProcessPipes ppid = pipeProcess(commandLine); + while(true) + { + Thread.sleep(dur!"msecs"(250)); + auto result = tryWait(ppid.pid); + + foreach(line; ppid.stdout.byLine) + stdout.writeln(line); + foreach(line; ppid.stderr.byLine) + stderr.writeln(line); + + if (result.terminated) + return result.status; + } +} + diff --git a/cegdcldc/readme.md b/cegdcldc/readme.md new file mode 100644 index 00000000..f5e87878 --- /dev/null +++ b/cegdcldc/readme.md @@ -0,0 +1,4 @@ +Coedit Gdc - Ldc +================ + +This small program converts the options of a Coedit project (aka _native project_) to [LDC]() or [GDC]() options. \ No newline at end of file diff --git a/lazproj/test/coeditproj/test.coedit b/lazproj/test/coeditproj/test.coedit index 895deb81..bf54ed2f 100644 --- a/lazproj/test/coeditproj/test.coedit +++ b/lazproj/test/coeditproj/test.coedit @@ -3,7 +3,7 @@ object _1: TCENativeProject item name = 'default' documentationOptions.generateDocumentation = True - documentationOptions.DocumentationDirectory = '..\doc' + documentationOptions.DocumentationDirectory = '../doc' debugingOptions.debug = True debugingOptions.debugIdentifiers.Strings = ( 'a' @@ -16,18 +16,16 @@ object _1: TCENativeProject outputOptions.versionIdentifiers.Strings = ( 'revision_1' ) - pathsOptions.outputFilename = '..\output\main.exe' - preBuildProcess.executable = 'C:\Dev\pasproj\Coedit\lazproj\test\coeditproj\pre.bat' + pathsOptions.outputFilename = '../output/main' preBuildProcess.workingDirectory = '' preBuildProcess.options = [poWaitOnExit] - postBuildProcess.executable = 'C:\Dev\pasproj\Coedit\lazproj\test\coeditproj\post.bat' postBuildProcess.workingDirectory = '' postBuildProcess.options = [poWaitOnExit] end item name = 'alternative' documentationOptions.generateDocumentation = True - documentationOptions.DocumentationDirectory = '..\doc' + documentationOptions.DocumentationDirectory = '../doc' debugingOptions.debug = True debugingOptions.debugLevel = 3 messagesOptions.additionalWarnings = True @@ -38,12 +36,12 @@ object _1: TCENativeProject outputOptions.versionIdentifiers.Strings = ( 'revision_2' ) - pathsOptions.outputFilename = '..\output\main.exe' + pathsOptions.outputFilename = '../output/main' end> Sources.Strings = ( - '..\src\main.d' - '..\src\barclass.d' - '..\src\fooclass.d' + '../src/main.d' + '../src/barclass.d' + '../src/fooclass.d' ) ConfigurationIndex = 0 end diff --git a/lazproj/test/src/main.d b/lazproj/test/src/main.d index aad1af2d..9276bbf2 100644 --- a/lazproj/test/src/main.d +++ b/lazproj/test/src/main.d @@ -13,7 +13,7 @@ import std.stdio; import fooclass; import barclass; -void main(string args[]) +void main(string[] args) { auto foo = new Foo; auto bar = new Bar; diff --git a/src/ce_dubproject.pas b/src/ce_dubproject.pas index 27acbdf5..1a75258e 100644 --- a/src/ce_dubproject.pas +++ b/src/ce_dubproject.pas @@ -813,14 +813,14 @@ end; procedure setDubCompiler(value: TCECompiler); begin case value of - dmd: DubCompilerFilename := exeFullName('dmd'); - gdc: DubCompilerFilename := exeFullName('gdc'); - ldc: DubCompilerFilename := exeFullName('ldc2'); + dmd: DubCompilerFilename := exeFullName('dmd' + exeExt); + gdc: DubCompilerFilename := exeFullName('gdc' + exeExt); + ldc: DubCompilerFilename := exeFullName('ldc2' + exeExt); end; if (not fileExists(DubCompilerFilename)) or (DubCompilerFilename = '') then begin value := dmd; - DubCompilerFilename:= 'dmd'; + DubCompilerFilename:= 'dmd' + exeExt; end; DubCompiler := value; end; diff --git a/src/ce_nativeproject.pas b/src/ce_nativeproject.pas index 91e92b85..fffa76f7 100644 --- a/src/ce_nativeproject.pas +++ b/src/ce_nativeproject.pas @@ -44,12 +44,12 @@ type procedure updateOutFilename; procedure doChanged; procedure getBaseConfig; - procedure setLibAliases(const aValue: TStringList); + procedure setLibAliases(const value: TStringList); procedure subMemberChanged(sender : TObject); - procedure setOptsColl(const aValue: TCollection); - procedure setRoot(const aValue: string); - procedure setSrcs(const aValue: TStringList); - procedure setConfIx(aValue: Integer); + procedure setOptsColl(const value: TCollection); + procedure setRoot(const value: string); + procedure setSrcs(const value: TStringList); + procedure setConfIx(value: Integer); function getConfig(const ix: integer): TCompilerConfiguration; function getCurrConf: TCompilerConfiguration; function runPrePostProcess(const processInfo: TCompileProcOptions): Boolean; @@ -182,11 +182,11 @@ begin result.onChanged := @subMemberChanged; end; -procedure TCENativeProject.setOptsColl(const aValue: TCollection); +procedure TCENativeProject.setOptsColl(const value: TCollection); var i: nativeInt; begin - fConfigs.Assign(aValue); + fConfigs.Assign(value); for i:= 0 to fConfigs.Count-1 do Configuration[i].onChanged := @subMemberChanged; end; @@ -209,11 +209,11 @@ begin fSrcs.Add(relSrc); end; -procedure TCENativeProject.setRoot(const aValue: string); +procedure TCENativeProject.setRoot(const value: string); begin - if fRootFolder = aValue then exit; + if fRootFolder = value then exit; beginUpdate; - fRootFolder := aValue; + fRootFolder := value; endUpdate; end; @@ -240,27 +240,27 @@ begin endUpdate; end; -procedure TCENativeProject.setLibAliases(const aValue: TStringList); +procedure TCENativeProject.setLibAliases(const value: TStringList); begin beginUpdate; - fLibAliases.Assign(aValue); + fLibAliases.Assign(value); endUpdate; end; -procedure TCENativeProject.setSrcs(const aValue: TStringList); +procedure TCENativeProject.setSrcs(const value: TStringList); begin beginUpdate; - fSrcs.Assign(aValue); + fSrcs.Assign(value); patchPlateformPaths(fSrcs); endUpdate; end; -procedure TCENativeProject.setConfIx(aValue: Integer); +procedure TCENativeProject.setConfIx(value: Integer); begin beginUpdate; - if aValue < 0 then aValue := 0; - if aValue > fConfigs.Count-1 then aValue := fConfigs.Count-1; - fConfIx := aValue; + if value < 0 then value := 0; + if value > fConfigs.Count-1 then value := fConfigs.Count-1; + fConfIx := value; endUpdate; end; @@ -684,7 +684,7 @@ function TCENativeProject.compile: Boolean; var config: TCompilerConfiguration; compilproc: TProcess; - prjpath, oldCwd: string; + prjpath, oldCwd, str: string; prjname: string; msgs: ICEMessagesDisplay; begin @@ -728,6 +728,14 @@ begin compilproc.ShowWindow := swoHIDE; getOpts(compilproc.Parameters); compilproc.Execute; + if NativeProjectCompiler <> dmd then + begin + case NativeProjectCompiler of + gdc: begin str := 'gdc'; compilproc.Input.Write(str[1], 3) end; + ldc: begin str := 'ldc2'; compilproc.Input.Write(str[1], 4) end; + end; + compilproc.CloseInput; + end; while compilProc.Running do compProcOutput(compilproc); if compilproc.ExitStatus = 0 then begin @@ -978,17 +986,15 @@ end; procedure setNativeProjectCompiler(value: TCECompiler); begin case value of - // TODO-cfeature: a dmd2gdc and a dmd2ldc2 option translater. - // maybe done in D using getOpt, as a tool: ceLdcOpt, ceGDCOpt - dmd: NativeProjectCompilerFilename := exeFullName('dmd'); - gdc: NativeProjectCompilerFilename := ''; // need option translater dmd->gdc - ldc: NativeProjectCompilerFilename := ''; // need option translater dmd->ldc + dmd: NativeProjectCompilerFilename := exeFullName('dmd' + exeExt); + gdc: NativeProjectCompilerFilename := exeFullName('cegdcldc' + exeExt); + ldc: NativeProjectCompilerFilename := exeFullName('cegdcldc' + exeExt); end; if (not fileExists(NativeProjectCompilerFilename)) or (NativeProjectCompilerFilename = '') then begin value := dmd; - NativeProjectCompilerFilename:= 'dmd'; + NativeProjectCompilerFilename:= 'dmd' + exeExt; end; NativeProjectCompiler := value; end;