From 1a50442c13bfc19fe314df0a0fec87dd1b3c5d48 Mon Sep 17 00:00:00 2001 From: Paul Tan Date: Fri, 18 Aug 2017 20:42:16 +0800 Subject: Generate deps file during C compilation The "genDepend" command was previously taught how to generate a "deps" file in 4910a87c6 (gendepend improvements; refs #5144). Such a deps file is useful in integrating the Nim compiler with an external build system or watch daemon, such that it's possible to only run the Nim compiler when any of the source files are modified. It's also useful to generate the deps file in the nimcache directory during C compilation, without needing to re-run the compilation passes with "genDepend". This would thus reduce overall project build times. --- compiler/main.nim | 1 + 1 file changed, 1 insertion(+) (limited to 'compiler/main.nim') diff --git a/compiler/main.nim b/compiler/main.nim index f662ded1b..76e18a80b 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -77,6 +77,7 @@ proc commandCompileToC(graph: ModuleGraph; cache: IdentCache) = let proj = changeFileExt(gProjectFull, "") extccomp.callCCompiler(proj) extccomp.writeJsonBuildInstructions(proj) + writeDepsFile(graph, toGeneratedFile(proj, "")) proc commandCompileToJS(graph: ModuleGraph; cache: IdentCache) = #incl(gGlobalOptions, optSafeCode) -- cgit 1.4.1-2-gfad0 From b06c0f97a4640c16b2205635b378a39fcef9b814 Mon Sep 17 00:00:00 2001 From: Paul Tan Date: Tue, 22 Aug 2017 23:36:03 +0800 Subject: writeDepsFile: write included files as well `writeDepsFile()` does not list files which were included with the `include` statement, e.g, with: import file1 include file2 `file1` will be written to the deps file, while `file2` would not. Fix this by modifying `writeDepsFile()` to write included files as well. Now, both `file1` and `file2` in the above example will be written to the deps file. --- compiler/main.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'compiler/main.nim') diff --git a/compiler/main.nim b/compiler/main.nim index 76e18a80b..994c28ccb 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -16,7 +16,7 @@ import cgen, jsgen, json, nversion, platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen, docgen2, service, parser, modules, ccgutils, sigmatch, ropes, - modulegraphs + modulegraphs, tables from magicsys import systemModule, resetSysTypes @@ -36,6 +36,9 @@ proc writeDepsFile(g: ModuleGraph; project: string) = for m in g.modules: if m != nil: f.writeLine(toFullPath(m.position.int32)) + for k in g.inclToMod.keys: + if g.getModule(k).isNil: # don't repeat includes which are also modules + f.writeLine(k.toFullPath) f.close() proc commandGenDepend(graph: ModuleGraph; cache: IdentCache) = -- cgit 1.4.1-2-gfad0 From da90657317e8a57bae80ebd2d637a972d3b438ab Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 21 Dec 2017 17:14:31 +0100 Subject: make the new --genDeps feature optional since it makes compilations slower --- compiler/commands.nim | 2 +- compiler/main.nim | 3 ++- doc/advopt.txt | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'compiler/main.nim') diff --git a/compiler/commands.nim b/compiler/commands.nim index de474c6e6..386d7bda8 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -611,7 +611,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; of "skipparentcfg": expectNoArg(switch, arg, pass, info) incl(gGlobalOptions, optSkipParentConfigFiles) - of "genscript": + of "genscript", "gendeps": expectNoArg(switch, arg, pass, info) incl(gGlobalOptions, optGenScript) of "colors": processOnOffSwitchG({optUseColors}, arg, pass, info) diff --git a/compiler/main.nim b/compiler/main.nim index db03f0e4d..08fc4b138 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -80,7 +80,8 @@ proc commandCompileToC(graph: ModuleGraph; cache: IdentCache) = let proj = changeFileExt(gProjectFull, "") extccomp.callCCompiler(proj) extccomp.writeJsonBuildInstructions(proj) - writeDepsFile(graph, toGeneratedFile(proj, "")) + if optGenScript in gGlobalOptions: + writeDepsFile(graph, toGeneratedFile(proj, "")) proc commandJsonScript(graph: ModuleGraph; cache: IdentCache) = let proj = changeFileExt(gProjectFull, "") diff --git a/doc/advopt.txt b/doc/advopt.txt index ab10d65ba..a1210118e 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -37,6 +37,7 @@ Advanced options: --noMain do not generate a main procedure --genScript generate a compile script (in the 'nimcache' subdirectory named 'compile_$project$scriptext') + --genDeps generate a '.deps' file containing the dependencies --os:SYMBOL set the target operating system (cross-compilation) --cpu:SYMBOL set the target processor (cross-compilation) --debuginfo enables debug information -- cgit 1.4.1-2-gfad0