mvn_build.py 9.15 KB
Newer Older
Florent Langlois's avatar
Florent Langlois committed
1 2 3 4 5 6 7 8
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
#
# Lima compilation script
#
# Version 1.0
#
#
9
# Author: FL / AN (Hacked from S. Poirier)
Florent Langlois's avatar
Florent Langlois committed
10

11
from multiprocessing import Pool
12 13
from argparse import ArgumentParser

Florent Langlois's avatar
Florent Langlois committed
14 15 16 17
import os
import sys
import shutil
import string
18 19 20 21
import time


copied_files = []
22

Florent Langlois's avatar
Florent Langlois committed
23 24 25 26 27 28 29 30 31 32 33 34
#------------------------------------------------------------------------------
# build exception
#------------------------------------------------------------------------------
class BuildError(Exception):
  pass

#------------------------------------------------------------------------------
# Project directory
#------------------------------------------------------------------------------
def set_project_dir(sub_dir):
  project_dir = os.path.join(current_dir, sub_dir)
  os.chdir(project_dir)
35

Florent Langlois's avatar
Florent Langlois committed
36 37 38
#------------------------------------------------------------------------------
# Copy library
#------------------------------------------------------------------------------
39

Florent Langlois's avatar
Florent Langlois committed
40
def copy_file_ext(from_path, to_path, file_ext):
41

Florent Langlois's avatar
Florent Langlois committed
42
  if not os.path.isdir(to_path):
43
    os.makedirs(to_path)
44

Florent Langlois's avatar
Florent Langlois committed
45 46
  files = os.listdir(from_path)
  for file in files:
47 48 49 50 51
    full_name = os.path.join(from_path, file)
    if os.path.isfile(full_name):
      root, ext = os.path.splitext(full_name)
      if ext == file_ext:
        shutil.copy(full_name, to_path)
52 53
        file_to_copy = file + ' copied in ' + to_path
        copied_files.append(file_to_copy)
54

Florent Langlois's avatar
Florent Langlois committed
55 56 57 58
#------------------------------------------------------------------------------
# Compilation
#------------------------------------------------------------------------------
def build():
59
  rc = os.system(maven_clean_install + maven_options)
Florent Langlois's avatar
Florent Langlois committed
60
  if rc != 0:
61
    raise BuildError
62

Florent Langlois's avatar
Florent Langlois committed
63 64 65 66 67 68
#------------------------------------------------------------------------------
# Clean
#------------------------------------------------------------------------------
def clean():
  rc = os.system(maven_clean)
  if rc != 0:
69
    raise BuildError
70

Florent Langlois's avatar
Florent Langlois committed
71 72 73 74
#------------------------------------------------------------------------------
# Clean all modules
#------------------------------------------------------------------------------
def clean_all():
75 76 77 78 79 80
    print 'Cleaning all\n'
    set_project_dir('.');clean()
    set_project_dir('third-party/Processlib');clean()
    for cam in camera_list:
        set_project_dir('camera/'+ cam);clean()
    set_project_dir('applications/tango/LimaDetector');clean()
Florent Langlois's avatar
Florent Langlois committed
81 82 83 84 85 86 87

#------------------------------------------------------------------------------
# build the LimaDetector device
#------------------------------------------------------------------------------
def build_device(target_path):
  print 'Build Device LimaDetector\n'
  set_project_dir('applications/tango/LimaDetector')
88

89 90 91 92
  print "Maven command = ", maven_clean_install + maven_platform_options + maven_options
  rc = os.system(maven_clean_install + maven_platform_options + maven_options)
  if rc != 0:
    raise BuildError
93 94 95 96 97 98 99 100 101 102 103

  if "linux" in sys.platform:
    if target_path is not None:
      dest_path = os.path.join(target_path, '')
      copy_file_ext(device_src_path, dest_path, '')
  if "win32" in sys.platform:
    if target_path is not None:
      dest_path = os.path.join(target_path, '')
      copy_file_ext(device_src_path, dest_path, '.exe')
      copy_file_ext(device_src_path, dest_path, '.pdb')

Florent Langlois's avatar
Florent Langlois committed
104 105 106 107 108 109 110 111 112
  print '\n'

#------------------------------------------------------------------------------
# build the Lima Core
#------------------------------------------------------------------------------
def build_lima_core(target_path):
  print 'Build Lima\n'
  set_project_dir('.')
  build()
113 114 115 116 117 118 119 120 121 122

  if "linux" in sys.platform:
    if target_path is not None:
      dest_path = os.path.join(target_path, '')
      copy_file_ext(src_path, dest_path, '.so')
  if "win32" in sys.platform:
    if target_path is not None:
      dest_path = os.path.join(target_path, '')
      copy_file_ext(src_path, dest_path, '.dll')
      copy_file_ext(src_path, dest_path, '.pdb')
Florent Langlois's avatar
Florent Langlois committed
123 124 125 126 127
  print '\n'

#------------------------------------------------------------------------------
# build the Plugin 'plugin'
#------------------------------------------------------------------------------
128
def build_plugin(plugin,target_path):
129

Florent Langlois's avatar
Florent Langlois committed
130
  """Build the selected plugin"""
131 132

  print "Building:    " , plugin, "\n"
Florent Langlois's avatar
Florent Langlois committed
133 134
  set_project_dir(plugin)
  build()
135 136 137 138 139 140 141 142 143 144 145

  if "linux" in sys.platform:
    if target_path is not None:
      dest_path = os.path.join(target_path, '')
      copy_file_ext(src_path, dest_path, '.so')
  if "win32" in sys.platform:
    if target_path is not None:
      dest_path = os.path.join(target_path, '')
      copy_file_ext(src_path, dest_path, '.dll')
      copy_file_ext(src_path, dest_path, '.pdb')

Florent Langlois's avatar
Florent Langlois committed
146 147 148 149 150 151
  print '\n'


#------------------------------------------------------------------------------
# build all linux cameras
#------------------------------------------------------------------------------
152
def build_all_camera(target_path):
153
    start=time.time()
154 155 156 157 158 159
    # this take 2 min 45 sec on a quad core
    if multi_proc == False:
        for cam in camera_list:
            build_plugin('camera/' + cam, target_path)
    else:
        # this take 1 min 26 sec on a quad core
160
        pool = Pool()
161
        for cam in camera_list:
162
            print "multi proc: Building:    " , cam, "\n"
163 164 165
            pool.apply_async(build_plugin,('camera/' + cam, target_path))
        pool.close()
        pool.join()
166 167
        time.strftime("%M min %S sec", time.localtime(170))
    print "duration for compiling all cameras (MultiProc = ",multi_proc, ") = ", time.strftime("%M min %S sec", time.localtime(time.time() - start))
168

Florent Langlois's avatar
Florent Langlois committed
169 170 171 172
#------------------------------------------------------------------------------
# Main Entry point
#------------------------------------------------------------------------------
if __name__ == "__main__":
173 174

  if "linux" in sys.platform:
175
    platform = "linux"
Arafat Noureddine's avatar
Arafat Noureddine committed
176
    camera_list = ["adsc", "aviex", "basler", "eiger", "marccd","pilatus","prosilica","simulator","xpad"]
177
    maven_platform_options = " --file pom-linux.xml"
178 179
    src_path = './target/nar/lib/i386-Linux-g++/shared/'
    device_src_path = './target/nar/bin/i386-Linux-g++/'
180 181
  if "win32" in sys.platform:
    platform = "win32"
182
    camera_list = ["andor", "hamamatsu", "pco","perkinelmer","roperscientific","simulator","uview"]
183
    maven_platform_options = " --file pom-win.xml"
184 185
    src_path = './target/nar/lib/x86-Windows-msvc/shared/'
    device_src_path = './target/nar/bin/x86-Windows-msvc/'
186

187 188 189 190 191 192 193 194
  print "platform : ", platform

  # command line parsing
  parser = ArgumentParser(description="Lima compilation script")
  cams_string = ""
  for cam in camera_list:
    cams_string += cam + "|"
  help_string = "module to compile (possible values are: all|processlib|lima|cameras|"+ cams_string+ "|device||cleanall)"
195
  parser.add_argument("module", help=help_string)
196 197 198 199 200
  parser.add_argument("-o","--offline", help="mvn will be offline",action="store_true")
  parser.add_argument("-f","--pomfile", help="name of the pom file(for the Tango device only)")
  parser.add_argument("-q","--quiet", help="mvn will be quiet", action="store_true")
  parser.add_argument("-m","--multiproc", help="cameras will be compiled in multiprocessing way",action="store_true")
  parser.add_argument("-d","--directory", help="automatically install Lima binaries into the specified installation directory")
201

202
  args = parser.parse_args()
203

204 205 206 207 208 209 210
  maven_options = ""
  # manage command line option  
  if args.offline:
    maven_options += " -o"

  if args.pomfile:
    maven_platform_options = " --file " + args.pomfile
211

212 213
  if args.quiet:
    maven_options += " -q"
214

215 216 217 218
  if args.multiproc:
    multi_proc = True
  else:
    multi_proc = False
219

220 221 222 223
  if args.directory:
    target_path = args.directory
  else:
    target_path = None
224

225 226 227 228 229 230 231
  # variables
  maven_clean_install   = "mvn clean install -DenableCheckRelease=false"
  maven_clean           = "mvn clean"
  current_dir           = os.getcwd()

  try:
    # Build all
232
    if args.module == 'all':
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
        print 'BUILD ALL\n'
        build_plugin('third-party/Processlib', target_path)
        build_lima_core(target_path)
        build_all_camera(target_path)
        build_device(target_path)
    # Build processlib
    elif args.module == 'processlib':
        print 'BUILD ProcessLib\n'
        build_plugin('third-party/Processlib', target_path)
    # Build device
    elif args.module == 'device':
        print 'BUILD Device\n'
        build_device(target_path)
    # Build lima
    elif args.module == 'lima':
        print 'BUILD Lima Core\n'
        build_lima_core(target_path)
    # Build cameras
    elif args.module == 'cameras':
        print 'BUILD All ',platform,' Cameras\n'
        build_all_camera(target_path)
    # Clean all
    elif args.module =='cleanall':
        clean_all()
    # Build cam
    else:
        for cam in camera_list:
            if args.module == cam:
                build_plugin('camera/'+cam, target_path)
                break
263 264 265 266 267 268 269 270 271 272 273

    # display list of copied files, if -d option is used
    if args.directory:
        print '\n'
        print '============================================='
        print 'Modules are compiled & copied as shown below:'
        print '============================================='
        for file in copied_files:
            print '- ',file
        print '\n'

274 275
  except BuildError, e:
    sys.stderr.write("!!!   BUILD FAILED    !!!\n")
276