0

I'm trying to write a SConscript file so that I can use scons to build Go code. The SConscript file is pretty simple; its just a starter file:

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')

But I keep getting this error:

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

    print(sources)

    ^

IndentationError: unexpected indent

I tried switching between python v2.7 and 3.7, rewriting the code in various different ways, but I kept hitting the same issue. I even tried writing several fragments of the above code inside a python interpreter and the syntax and indentation were fine.

jersey bean
  • 3,321
  • 4
  • 28
  • 43
  • Where did you find that go builder. It's not really very SCons'ian. And could be much improved.. – bdbaddog May 07 '19 at 04:26
  • @bdbaddog I started with the solution here: https://stackoverflow.com/questions/1735993/what-build-systems-work-with-go . I had run into so many indentation errors, and other env vars that weren't defined, I stripped it down to what I have here. Any suggestions for a better resource? Seems like there's very little example for Golang. – jersey bean May 07 '19 at 05:54
  • @bdbaddog ...also, this actually follows a very similar pattern as described in chapter 18.5 of the scons user guide, titled Builders That Create Actions Using Generators. Maybe a bit simplified as I was having so many troubles getting it to work. In fact, now I'm having issues getting scons to recognize Go's env vars. – jersey bean May 07 '19 at 06:00
  • There's no need to use a generator here.. your action could be "go build $SOURCES".. – bdbaddog May 07 '19 at 16:23
  • That posting is ancient.. 2009.. Here's a more recent effort. Though not complete: https://bitbucket.org/bdbaddog/scons-gobuilder/src/default/ – bdbaddog May 07 '19 at 16:30
  • If you'd like to help/help with go builder for scons.. come to the scons users mailing list.. https://scons.org/lists.html – bdbaddog May 07 '19 at 16:33

1 Answers1

0

I had copied/pasted some of this code from online. Turns out there was some embedded tabs, but my editor was using spaces. So several lines were inconsistently indented. I spend hours looking at this, so I figured I would share my mistake.

jersey bean
  • 3,321
  • 4
  • 28
  • 43