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