Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 1 | import random |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 2 | |
| 3 | DEBUG_ARG='JAVA_TOOL_OPTIONS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=y"' |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 4 | FORCE_INSTALL=True |
| 5 | NONE='NONE' |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 6 | |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame^] | 7 | ONOS_GROUP_ID = 'org.onosproject' |
| 8 | ONOS_VERSION = '1.6.0-SNAPSHOT' |
| 9 | |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 10 | def osgi_jar( |
| 11 | name, |
| 12 | srcs, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame^] | 13 | group_id = ONOS_GROUP_ID, |
| 14 | version = ONOS_VERSION, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 15 | deps = [], |
| 16 | visibility = ['PUBLIC'], |
| 17 | license = 'NONE', |
| 18 | description = '', |
| 19 | debug = False, |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 20 | import_packages = '*', |
| 21 | export_packages = '*', |
| 22 | include_resources = NONE, |
| 23 | web_context = NONE, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 24 | **kwargs |
| 25 | ): |
| 26 | |
| 27 | bare_jar_name = name + '-jar' |
| 28 | osgi_jar_name = name + '-osgi' |
| 29 | mvn_coords = group_id + ':' + name + ':' + version |
| 30 | |
| 31 | java_library( |
| 32 | name = bare_jar_name, |
| 33 | srcs = srcs, |
| 34 | deps = deps, |
Ray Milkey | 7c25182 | 2016-04-06 17:38:25 -0700 | [diff] [blame] | 35 | visibility = ['PUBLIC'], |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 36 | **kwargs |
| 37 | ) |
| 38 | |
| 39 | cp = ':'.join(['$(classpath %s)' % c for c in deps]) |
| 40 | |
| 41 | args = ( '$(location :%s)' % bare_jar_name, #input jar |
| 42 | '$OUT', #output jar |
| 43 | cp, #classpath |
| 44 | name, #bundle name |
| 45 | group_id, #group id |
| 46 | version, #version |
| 47 | license, #license url |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 48 | "'%s'" % import_packages, #packages to import |
| 49 | "'%s'" % export_packages, #packages to export |
| 50 | include_resources, #custom includes to classpath |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 51 | web_context, #web context (REST API only) |
| 52 | description, #description |
| 53 | ) |
| 54 | |
| 55 | #TODO stage_jar is a horrendous hack |
| 56 | stage_jar = 'pushd $SRCDIR; mkdir bin; cd bin; jar xf $(location :%s); ls; popd; ' % bare_jar_name |
| 57 | wrap_jar = '$(exe //utils/osgiwrap:osgi-jar) ' + ' '.join(args) |
| 58 | bash = stage_jar + wrap_jar |
| 59 | if debug: |
| 60 | bash = stage_jar + DEBUG_ARG + ' ' + wrap_jar |
| 61 | print bash |
| 62 | # TODO this is a hack to add checkstyle as dependency before generating jar |
| 63 | bash = 'ls $(location :' + name + '-checkstyle) > /dev/null; ' + bash |
| 64 | |
| 65 | genrule( |
| 66 | name = osgi_jar_name, |
| 67 | bash = bash, |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame^] | 68 | out = '%s-%s.jar' % (name, version), #FIXME add version to jar file |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 69 | srcs = glob(['src/main/webapp/**']), |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 70 | visibility = [], #intentially, not visible |
| 71 | ) |
| 72 | |
| 73 | # TODO we really should shade the jar with maven flavor |
| 74 | prebuilt_jar( |
| 75 | name = name, |
| 76 | maven_coords = mvn_coords, |
| 77 | binary_jar = ':' + osgi_jar_name, |
| 78 | visibility = visibility, |
| 79 | ) |
| 80 | |
| 81 | |
| 82 | |
| 83 | ### Checkstyle |
| 84 | chk_cmd = ' '.join(( 'java -jar $(location //lib:checkstyle)', |
| 85 | '-o $OUT', |
| 86 | '-c $(location //tools/build/conf:checkstyle-xml)', |
| 87 | ' '.join(srcs) )) |
| 88 | error_cmd = '(touch $OUT; cat $OUT | grep "^\[ERROR\]"; exit 1)' |
| 89 | cmd = ' || '.join((chk_cmd, error_cmd)) |
| 90 | genrule( |
| 91 | name = name + '-checkstyle', |
| 92 | bash = cmd, |
| 93 | srcs = srcs, |
| 94 | out = 'checkstyle.log', |
| 95 | ) |
| 96 | |
| 97 | ### .m2 Install |
Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 98 | mvn_cmd = ' '.join(( 'mvn install:install-file', |
| 99 | '-Dfile=$(location :%s)' % name, |
| 100 | '-DgroupId=%s' % group_id, |
| 101 | '-DartifactId=%s' % name, |
| 102 | '-Dversion=%s' % version, |
| 103 | '-Dpackaging=jar' )) |
Brian O'Connor | e5817c9 | 2016-04-06 15:41:48 -0700 | [diff] [blame] | 104 | cmd = mvn_cmd + ' > $OUT' |
| 105 | if FORCE_INSTALL: |
| 106 | # Add a random number to the command to force this rule to run. |
| 107 | # TODO We should make this configurable from CLI, perhaps with a flag. |
| 108 | cmd = 'FOO=%s ' % random.random() + cmd |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 109 | genrule( |
| 110 | name = name + '-install', |
Brian O'Connor | b86c920 | 2016-04-05 20:15:04 -0700 | [diff] [blame] | 111 | bash = cmd, |
Brian O'Connor | 42c38cf | 2016-04-05 17:05:57 -0700 | [diff] [blame] | 112 | out = 'install.log', |
| 113 | visibility = visibility, |
| 114 | ) |
| 115 | |