[buildout]
extends =
  ../zip/buildout.cfg
  ../bazel/buildout.cfg
parts =
  slapos-cookbook-develop
  slapos-cookbook
  tensorboard-build-install-egg

[tensorboard-repository]
recipe = plone.recipe.command
stop-on-error = true
repository = https://github.com/tensorflow/tensorboard
tag = 0.4.0
git-binary = ${git:location}/bin/git
patch-binary = ${patch:location}/bin/patch
location = ${buildout:parts-directory}/${:_buildout_section_name_}
command = export HOME=${:location}; (${:git-binary} clone --quiet -b ${:tag} ${:repository} ${:location}; cd ${buildout:parts-directory} ; ${:patch-binary} -p1 -d ${:_buildout_section_name_} < ${:_profile_base_location_}/0.4.0.patch ) || (rm -fr ${:location}; exit 1)

[tensorboard-build]
recipe = slapos.recipe.build
location = ${buildout:parts-directory}/${:_buildout_section_name_}
workdir = ${tensorboard-repository:location}
gcc-bin = ${gcc:location}/bin
gcc-lib = ${gcc:location}/lib
gcc-lib64 = ${gcc:location}/lib64
numpy-python-command = ${buildout:bin-directory}/${numpy-egg:interpreter}
python27-lib = ${python2.7:location}/lib
java_home_bin = ${bazel:java_home}/bin
bazel-bin = ${bazel:location}/bin
script =
  os.makedirs(location)
  workdir = self.options['workdir']
  env = {'PATH':':'.join([self.options['gcc-bin'],
                          self.options['java_home_bin'],
                          self.options['bazel-bin'],
                          os.environ['PATH']]),
         'COMPILER_PATH':':'.join([self.options['gcc-bin'],
                                   os.environ.get('COMPILER_PATH') or '']),
         'LIBRARY_PATH':':'.join([self.options['gcc-lib'],
                                  self.options['gcc-lib64'],
                                  os.environ.get('LIBRARY_PATH') or '']),
         'PYTHON_BIN_PATH':self.options['numpy-python-command'],
         'PYTHON_LIB_PATH':self.options['python27-lib'],
         }
  import os.path
  env['LD_LIBRARY_PATH'] = env['LIBRARY_PATH']
  bazel_command = ['bazel', 'build', '--spawn_strategy=standalone', '--verbose_failures', '--sandbox_debug', '//tensorboard/pip_package:build_pip_package']
  call(bazel_command, cwd=workdir, env=env)

[tensorboard-build-install-egg]
recipe = slapos.recipe.build
unzip-binary = ${unzip:location}/bin/unzip
tensorboard-repository-path = ${tensorboard-repository:location}
location = ${buildout:parts-directory}/${:_buildout_section_name_}
need-tensorboard-build = ${tensorboard-build:location}
egg = tensorflow-tensorboard
bazel-bin = ${bazel:location}/bin
java_home_bin = ${bazel:java_home}/bin
numpy-python-command = ${buildout:bin-directory}/${numpy-egg:interpreter}
script =
  os.makedirs(location)
  workdir = self.options['tensorboard-repository-path']
  egg_name = 'tensorflow_tensorboard-0.4.0-py2.7.egg'
  dist_dir = os.path.join(workdir, 'dist')
  dest_dir = os.path.join(self.buildout['buildout']['eggs-directory'], egg_name)
  env = {'PATH':':'.join([self.options['bazel-bin'],
                          self.options['java_home_bin'],
                          os.environ['PATH']]),
         'PYTHON_BIN_PATH':self.options['numpy-python-command'],
         }
  call(['tensorboard/pip_package/build_pip_package.sh', dist_dir], cwd=workdir, env=env)
  call([self.options['unzip-binary'], '-o', os.path.join(dist_dir, egg_name), '-d', dest_dir])

[versions]
