diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2018-04-11 21:28:54 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2018-04-11 21:28:54 +0300 |
| commit | 466d8d1d2e878330ff36c2aacd640092e7fba738 (patch) | |
| tree | 08836a6f3cb36f77aee48df0f35a6925084834e8 | |
| parent | c67a380be0dea5961d99fb8573f891980236ce2b (diff) | |
| download | nimpb-466d8d1d2e878330ff36c2aacd640092e7fba738.tar.gz nimpb-466d8d1d2e878330ff36c2aacd640092e7fba738.zip | |
Move binary part of compiler to nimpb_build
So that the binary nimble builds/installs for us is not named "compiler"... :-)
| -rw-r--r-- | nimpb.nimble | 8 | ||||
| -rw-r--r-- | nimpb/compiler/compiler.nim | 56 | ||||
| -rw-r--r-- | nimpb/compiler/nimpb_build.nim | 44 |
3 files changed, 58 insertions, 50 deletions
diff --git a/nimpb.nimble b/nimpb.nimble index 28247db..067245e 100644 --- a/nimpb.nimble +++ b/nimpb.nimble @@ -5,6 +5,12 @@ license = "MIT" skipDirs = @["examples", "tests"] -bin = @["nimpb/compiler/compiler"] +bin = @["nimpb/compiler/nimpb_build"] requires "nim >= 0.18.0" + +# Hard dependency for now. In the future we could make nimpb_protoc download +# stuff on-demand which would make the dependency a bit lighter. Especially +# if a user already has the protoc compiler somewhere, in which case +# nimpb_protoc might be unnecessary. +requires "nimpb_protoc" diff --git a/nimpb/compiler/compiler.nim b/nimpb/compiler/compiler.nim index fe0a5e4..c44ade6 100644 --- a/nimpb/compiler/compiler.nim +++ b/nimpb/compiler/compiler.nim @@ -8,11 +8,11 @@ from generator import processFileDescriptorSet, ServiceGenerator, Service, Servi export Service, ServiceMethod const - nimpbBuildInfo = gorgeEx("nimble dump nimpb_protoc") - isNimpbBuildAvailable = nimpbBuildInfo[1] == 0 + nimpbProtocInfo = gorgeEx("nimble dump nimpb_protoc") + isNimpbProtocAvailable = nimpbProtocInfo[1] == 0 -when isNimpbBuildAvailable: - import nimpb_protoc/nimpb_protoc +when isNimpbProtocAvailable: + import nimpb_protoc proc findCompiler*(): string = result = "" @@ -25,7 +25,7 @@ proc findCompiler*(): string = if result == "": result = findExe("protoc") - when isNimpbBuildAvailable: + when isNimpbProtocAvailable: if result == "": result = nimpb_protoc.getCompilerPath() @@ -48,9 +48,6 @@ Now you have three options to make this work: raise newException(Exception, msg) -proc builtinIncludeDir(compilerPath: string): string = - parentDir(compilerPath) / "include" - proc myTempDir(): string = result = getTempDir() / "nimpb_protoc_tmp" @@ -71,7 +68,8 @@ proc compileProtos*(protos: openArray[string], for incdir in includes: add(args, &"-I{incdir}") - add(args, &"-I{builtinIncludeDir(command)}") + when isNimpbProtocAvailable: + add(args, &"-I{getProtoIncludeDir()}") for proto in protos: add(args, proto) @@ -86,43 +84,3 @@ proc compileProtos*(protos: openArray[string], raise newException(Exception, outp) processFileDescriptorSet(outputFilename, outdir, protos, serviceGenerator) - - -when isMainModule: - proc usage() {.noreturn.} = - echo(&""" - {getAppFilename()} --out=OUTDIR [-IPATH [-IPATH]...] PROTOFILE... - - --out The output directory for the generated files - -I Add a path to the set of include paths - """) - quit(QuitFailure) - - var includes: seq[string] = @[] - var protos: seq[string] = @[] - var outdir: string - - if paramCount() == 0: - usage() - - for idx in 1..paramCount(): - let param = paramStr(idx) - - if param.startsWith("-I"): - add(includes, param[2..^1]) - elif param.startsWith("--out="): - outdir = param[6..^1] - elif param == "--help": - usage() - else: - add(protos, param) - - if outdir == nil: - echo("error: --out is required") - quit(QuitFailure) - - if len(protos) == 0: - echo("error: no input files") - quit(QuitFailure) - - compileProtos(protos, includes, outdir) diff --git a/nimpb/compiler/nimpb_build.nim b/nimpb/compiler/nimpb_build.nim new file mode 100644 index 0000000..1abb3f3 --- /dev/null +++ b/nimpb/compiler/nimpb_build.nim @@ -0,0 +1,44 @@ +import os +import osproc +import strformat +import strutils + +import compiler + +proc usage() {.noreturn.} = + echo(&""" +{getAppFilename()} --out=OUTDIR [-IPATH [-IPATH]...] PROTOFILE... + + --out The output directory for the generated files + -I Add a path to the set of include paths +""") + quit(QuitFailure) + +var includes: seq[string] = @[] +var protos: seq[string] = @[] +var outdir: string + +if paramCount() == 0: + usage() + +for idx in 1..paramCount(): + let param = paramStr(idx) + + if param.startsWith("-I"): + add(includes, param[2..^1]) + elif param.startsWith("--out="): + outdir = param[6..^1] + elif param == "--help": + usage() + else: + add(protos, param) + +if outdir == nil: + echo("error: --out is required") + quit(QuitFailure) + +if len(protos) == 0: + echo("error: no input files") + quit(QuitFailure) + +compileProtos(protos, includes, outdir) |
