【问题标题】:Indentation errors with scons / SConscript filesscons / SConscript 文件的缩进错误
【发布时间】:2019-05-07 00:38:56
【问题描述】:

我正在尝试编写一个 SConscript 文件,以便我可以使用 scons 来构建 Go 代码。 SConscript 文件非常简单;它只是一个入门文件:

def gc(source, target, env, for_signature):
   targets = target[0]
   sources = " ".join(str(s) for s in source)
   print(sources)
   return 'go build {}'.format(sources)


go_compiler = Builder(
   generator=gc,
   src_suffix='.go',
)

# Create environment
env = Environment(
   BUILDERS={'Go': go_compiler, }
)

# Build programs
main_package = env.Go(target='helloworld', source='helloworld.go')

但我不断收到此错误:

# scons
scons: Reading SConscript files ...
  File "/root/repo/SConstruct", line 5

    print(sources)

    ^

IndentationError: unexpected indent

我尝试在 python v2.7 和 3.7 之间切换,以各种不同的方式重写代码,但我一直遇到同样的问题。我什至尝试在 python 解释器中编写上述代码的几个片段,语法和缩进都很好。

【问题讨论】:

  • 你在哪里找到了 go builder。这不是真正的SCons'ian。并且可以大大改进..
  • @bdbaddog 我从这里的解决方案开始:stackoverflow.com/questions/1735993/…。我遇到了很多缩进错误,以及其他未定义的环境变量,我将其简化为我在这里所拥有的。对更好的资源有什么建议吗?似乎 Golang 的例子很少。
  • @bdbaddog ...此外,这实际上遵循了与 scons 用户指南第 18.5 章中描述的非常相似的模式,标题为使用生成器创建操作的构建器。也许有点简化,因为我在让它工作时遇到了很多麻烦。事实上,现在我在让 scons 识别 Go 的环境变量时遇到了问题。
  • 这里没有必要使用生成器。您的操作可能是“去构建 $SOURCES”..
  • 那张贴是古老的.. 2009.. 这是最近的努力。虽然不完整:bitbucket.org/bdbaddog/scons-gobuilder/src/default

标签: python python-3.x python-2.7 go scons


【解决方案1】:

我从网上复制/粘贴了其中的一些代码。原来有一些嵌入式选项卡,但我的编辑器使用了空格。所以几行的缩进不一致。我花了几个小时看这个,所以我想我会分享我的错误。

【讨论】:

  • 我建议删除这个问题,因为它对以后的任何人都不太可能有帮助?
猜你喜欢
  • 1970-01-01
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多