32 Commits

Author SHA1 Message Date
David Pursehouse
4042d43567 Merge branch 'stable-2.14'
* stable-2.14:
  Bazel: Allow plugins to non-transitively depend on prolog rules

Change-Id: I6d9c7e4795249ab8c97fb064f0ebb2dd5aee8ef1
2017-05-17 19:48:49 +09:00
David Ostrovsky
b9400254a6 Bazel: Allow plugins to non-transitively depend on prolog rules
Some plugins, most notably owners-plugin, depend on prolog:common rule.
Given that this rule transitively depends on gerrit-server:server rule,
and this rule depends on virtually whole gerrit build graph, the final
plugin artifact contains effectively the whole gerrit war file content.

To fix that we expose prolog:common in plugin API. Moreover, adjust
prolog_cafe_library to not transitively depend on prolog runtime
library. We can do it, because gerrit-server already depends on it, so
that it's included in gerrit war anyway.

This change allows the owners-plugin to de-duplicate its size from 45 MB
to 1.5 MB only.

Change-Id: I8d7198a911c2da444c1822509988eda7d369af77
2017-05-17 08:51:13 +02:00
David Ostrovsky
a3844fca7f Bazel: Simplify prolog_cafe_library rule implementation
genrule2 exposes root and temp directpries, but these are not used in
this rule, so that we can just use native genrule.

Change-Id: Id1e56ba47bf04a73559ff84a7c8f69745a6b3129
2017-05-17 06:23:51 +02:00
Hector Oswaldo Caballero
db21e3add0 Replace FileInputStream and FileOutputStream with static Files methods
FileInputStream and FileOutputStream rely on finalize() method to ensure
resources are closed. This implies they are added to the finalizer queue
which causes additional work for the JVM GC process.

This is an open bug on the OpenJDK [1] and the recommended workaround is
to use the Files.newInputStream and Files.newOutputStream static methods
instead.

[1] https://bugs.openjdk.java.net/browse/JDK-8080225

Change-Id: I3cef6fcf198dde2be7cd15bded8d2fa247177654
2017-05-10 00:10:52 +00:00
Dave Borowitz
292fa154c1 Format all Java files with google-java-format
Having a standard tool for formatting saves reviewers' valuable time.
google-java-format is Google's standard formatter and is somewhat
inspired by gofmt[1]. This commit formats everything using
google-java-format version 1.2.

The downside of this one-off formatting is breaking blame. This can be
somewhat hacked around with a tool like git-hyper-blame[2], but it's
definitely not optimal until/unless this kind of feature makes its way
to git core.

Not in this change:
* Tool support, e.g. Eclipse. The command must be run manually [3].
* Documentation of best practice, e.g. new 100-column default.

[1] https://talks.golang.org/2015/gofmt-en.slide#3
[2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
[3] git ls-files | grep java$ | xargs google-java-format -i

Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3
Signed-off-by: David Pursehouse <dpursehouse@collab.net>
2017-02-07 10:04:39 +09:00
David Ostrovsky
fdbfcad77d Remove Buck based build
Bug: Issue 5302
Change-Id: I6e860446ef30ff0ad1c7c49fc0e39d39d921820b
2017-01-23 12:44:58 +00:00
David Pursehouse
2d08500516 Format .bzl files with Bazel Buildifier
Change-Id: I3ab30565e5ac110a18cbe3d34f76307801c30373
2016-12-11 19:00:21 +09:00
David Ostrovsky
fa18907d7f Bazel: Reformat build files
Reformat the Bazel build files with the buildifier tool [1].

The style is different for Bazel files. Most notably, indentation level
is 4 spaces instead of 2, and " is used instead of '.

[1] https://github.com/bazelbuild/buildifier

Change-Id: I95c0c6f11b6d76572797853b4ebb5cee5ebd3c98
2016-12-07 11:33:07 +00:00
Han-Wen Nienhuys
29cced5e29 bazel: remove 'out' attribute from genrule2, and use throughout.
This centralizes the OSX mktemp solution.

Change-Id: Iaab18450146b649245b36865bedc5d7b50d1aa07
2016-11-02 13:54:10 +01:00
Han-Wen Nienhuys
b00302e0ce bazel: pass down **kwargs for some bzl macros.
Change-Id: If136681cc5605d4c945c06c5f01f410d9a98e016
2016-10-10 11:11:45 +02:00
Han-Wen Nienhuys
7eb9ee7621 bazel: for the prolog compiler rule, don't use $TMP as temp dir.
The prolog compiler tries to be transactional by renaming a temp file to
its final destination. This only works if $TMP is on the same file
system as the final output.

Change-Id: I3b3d261d61ace2798fca96d849bce9f2bbd46bcd
2016-09-29 16:55:14 +02:00
David Pursehouse
8748462b25 Upgrade prolog-cafe to 1.4.2
This version is built with Java 8.

Change-Id: Ic1a7bcb4fadcf94b3b32d9895a1f4b387b394a85
2016-09-28 02:10:06 +00:00
Yuxuan 'fishy' Wang
75b98f77d9 bazel: add license to appropriate lib/ targets
This is to prepare for implementing genlicenses rule in bazel.

Change-Id: I60d79d5b53f9dd05c9f9ebfe6e6f658604c5a037
2016-09-26 16:42:38 +08:00
David Ostrovsky
b81b4f75ae Implement Bazel build
To run the tests:

  bazel test //...

To build the Gerrit plugin API, run:

  bazel build gerrit-plugin-api:plugin-api_deploy.jar

To build the Gerrit extension API, run:

  bazel build gerrit-extension-api:extension-api_deploy.jar

TODOs:

Licenses
Reduce visibility (all public for now)
Generate HTML Documentation
Core plugins
gerrit_plugin() rule to build plugins in tree and standalone modes
GWT UI (only gwt_module() skylark rule is provided, no gwt_binary())
PolyGerrit UI
WAR
Publish artifacts to Maven Central
Ask Bazel team to add Gerrit to their CI on ci.bazel.io

Contributed-By: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I9a86e670882a44a5c966579cdeb8ed79b1590de3
2016-06-14 21:12:02 +02:00
David Pursehouse
cf6f4a4eb0 Remove unnecessary dependencies
Since [1] dependencies to targets used in $(location //path/to:target)
macro are added implicitly.

Similar build rules simplification was applied in I6c8ddb40ef and in
Id98257e111.

[1] https://github.com/facebook/buck/issues/128

Change-Id: Ife9717f37a9cdf55358da61b7e9df26fdf23c501
2015-09-18 06:02:35 +00:00
Urs Wolfer
5e90c63dea Use try-with-resources statements
- instead of finally blocks
- in cases of missing try-finally

Change-Id: I94f481a33d8e6a3180c436245d6e95e4d525280c
2015-06-23 21:11:57 +02:00
Shawn Pearce
62826d9d2f Merge "Update to Prolog Cafe 1.4.1" 2015-03-23 23:09:05 +00:00
Shawn Pearce
2b7b9895cb Update to Prolog Cafe 1.4.1
Reduces the default Trail size from 20,000 to 100 and
changes it to grow exponentially rather than linearly.
This should reduce the amount of garbage created during
rule execution as Trail will better fit the working set.

Change-Id: Ia240ecd0db00aa8a2952f107f8259742575fd700
2015-03-21 16:18:28 -07:00
David Pursehouse
a7a2cc2842 BuckPrologCompiler: Use auto-closeable FileInputStream
Change-Id: I77bb3d6ca7de77c01fb512bc25b78b069be28199
2015-03-20 14:27:26 +00:00
David Pursehouse
1e2458a0ef BuckPrologCompiler: Fix potential NPE
File.list() can return null, so it's unsafe to use it as an iterator
in a for-loop.

Store the result of File.list() first and only iterate it when it's
not null.

Change-Id: I0ced67e5bb5bc588433cb6a03a6283f9b31cb649
2015-03-20 14:26:49 +00:00
Shawn Pearce
cc34990493 Update to Prolog Cafe 1.4
Prolog Cafe is now built with Buck and has a slightly smaller
runtime. Many features not required for Gerrit Code Review were
stripped out of the fork.

Package names were reorganized to make the runtime smaller to
read by pulling exceptions out to their own package. This is
a breaking change for any plugins that contribute a predicate.

Change-Id: Icb50d306dfda146497814c65e2c03fae416ec5e1
2015-03-18 00:25:26 -07:00
David Ostrovsky
5dacc8bcc2 Buck: Make deps to $(exe :foo) and $(location :bar) implicitly
Apply [1] on our Buck tree.

[1] https://github.com/facebook/buck/issues/128

Change-Id: Ie3a9de0b2ee3725170bcbd06df059ea5d9ae5252
2014-06-10 07:29:42 +00:00
David Ostrovsky
d8af092c0a Buck: Remove usage of genfile()
genfile() is considered to be deprecated and is going to be discontinued
in future Buck releases [1].

[1] https://groups.google.com/forum/#!topic/buck-build/Ci8Y95USD8I

Change-Id: I7a5a1ee99d1448c412bb51b793c1e874dd3c62f4
2014-06-10 07:14:18 +00:00
David Ostrovsky
3f3e9ad20c Remove unnecessary reference to $SRCDIR in Buck genrules
In new buck version `$SRCDIR` is not necessary any more.  Buck now
always runs genrule relative to the $SRCDIR link forest.

Change-Id: Iee88bb575c7baa62bc087527927be5347a7f8f95
2014-03-26 18:20:13 -07:00
Shawn Pearce
4e1a8bc63d Update Buck
Buck changed export_deps from a boolean to be exported_deps, a list of
dependencies that are to be added to deps and also exported.  This
allows libraries to have dependencies for implementation use only, but
not expose them to callers for linkage.

exported_deps aren't transparently transitive anymore.  This mostly
impacts the plugin-api:lib rule.

This is the first time Gerrit is using upstream Buck with no patches.

- Java memory settings for Buck can now be supplied in a project
  specific file using `.buckjavaargs` in the root directory.  The file
  replaces the `.buckrc` previously supported by Gerrit's fork.

- Temporary directories for java_application() invoked from genrule()
  is now supplied as part of the arguments using $TMP.  This removes
  one of the patches Gerrit had for Buck.

- Unit tests use the system temporary directory during testing.  This
  can be faster if the temporary directory is a tmpfs.  Unfortunately
  not all passing tests clean up after themselves, making it possible
  to exhaust system memory and swap with useless tmpfs contents.
  Using the system temporary directory for tests removes another patch
  Gerrit had on top of Buck.

Change-Id: I3a9fe4aab0a33a8673df727e618122027a742638
2013-11-29 10:50:59 -08:00
Shawn Pearce
39371d57b3 Simplify buck based prolog compiler
The JARs are no longer passed into the prolog to java stage.
$DEPS is not necessary on the command line and .jar handling
inside of the translater is not required.

Change-Id: I1d12ab95376bd5878609bc8635955734e599e3cf
2013-08-06 18:37:45 -07:00
Shawn Pearce
980b51f64e Fix path used in generated prolog class names
Force relative paths by passing the Prolog compiler only a relative
name from within $SRCDIR.  This avoids picking up the user's $HOME
path as part of the generated class file names, and prevents build
failures on filesystems where individual path components are limited
to 256 bytes.

Change-Id: I43f2a93daf857413401f4e1aeb24b9b2a8c741fe
2013-08-06 17:32:43 -07:00
Shawn Pearce
5047911dba Rename DEFS files to *.defs
The build system used mixed names for essentially the same things.
Rename all DEFS files to *.defs matching the handful of other files
that are already using this convention.

Change-Id: I3269bd5db5d8d83f5e192ea910f19431c2a4a1cf
2013-07-30 17:18:33 +00:00
Shawn Pearce
11d27c8ee8 Update Buck
Latest version of buck is faster than the prior version used by
Gerrit.  No-op updates when loading a debug version of the UI now take
only 1.804s on my laptop (previously 7s) and a draft UI compile is
only 24.659s (previously 39s).

The slow acceptance tests must now be excluded with `--exclude slow`.
Buck changed the meaning of the -e option to be --emulator, which is
unfortunately useful only for Android application developers.

genrule() now needs to use $(exe) to reference the binary to run,
offers $(location) to make it easier to find files in the build tree.

The empty srcs array is no longer required for genrule().  Buck has
determined it is sufficiently powerful with $(location) and deps that
requiring srcs is unnecessary.

Supporting .src.zip files in the srcs array of java_library() means
Gerrit no longer needs to run a separate genrule() to extract files
produced by ANTLR, or call javac inside of the BuckPrologCompiler
support glue.

Change-Id: Ib03042921a081b867a7aad0423bd45523e42917a
2013-07-26 18:11:51 -07:00
Shawn Pearce
daa1977489 Fix BuckPrologCompiler to create Java 6 class files
Gerrit targets Java 6, not Java 7. If Buck is run under JDK 7
the javac compiler by default will assume -source 7 -target 7
and write incompatible class files.

Ensure the compiler builds for Java 6 language features and
Java 6 class format by passing the correct flags.

Change-Id: Ib2c013a6d1955d94b75cfd5d967d2f45ef4d5486
2013-05-16 15:35:31 -07:00
Shawn Pearce
82e66ee4e5 Move Eclipse related stuff into tools/eclipse
Try to reduce the size of the top-level BUCK file by moving
anything that has to do with Eclipse project generation and
classpath management into tools/eclipse.

Change-Id: Id779eaff4fe732908b28a8e3441004e364b59e21
2013-05-10 12:42:54 -07:00
Shawn Pearce
fd6bb9f6a5 Build with Buck
Implement a new build system using Buck[1], Facebook's
open source clone of Google's internal build system.

  Pros:
  - Concise build language
  - Test and build output is concise
  - Test failures and stack traces show on terminal
  - Reliable incrementals; clean is unnecessary
  - Extensible with simple blocks of Python
  - Fast
      buck: clean: 0.452s, full 1m21.083s [*], no-op:  7.145s,
      mvn:  clean: 4.596s, full 2m53.776s,     no-op: 59.108s,

      [*] full build includes downloading all dependencies,
          time can vary due to remote server performance.

  Cons:
  - No Windows support
  - No native Maven Central support (added by macros)
  - No native GWT, Prolog, or WAR support (added by macros)
  - Bootstrap of buck requires Ant

Getting started:

  git clone https://gerrit.googlesource.com/buck
  cd buck
  ant

  Mac OS X:
    PATH="`pwd`/bin:/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands:$PATH"

  Linux:
    PATH="`pwd`/bin:$PATH"

Importing into Eclipse:

  $ time buck build :eclipse
  0m48.949s

  Import existing project from `pwd`
  Import 'gerrit' (do not import other Maven based projects)
  Expand 'gerrit'
  Right click 'buck-out' > Properties
  Under Attributes check 'Derived'

  If the code doesn't currently compile but an updated classpath
  is needed, refresh the configs and obtain missing JARs:

  $ buck build :eclipse_project :download

Running JUnit tests:

  $ time buck test --all -e slow  # skip slow tests
  0m19.320s

  $ time buck test --all          # includes acceptance tests
  5m17.517s

Building WAR:

  $ buck build :gerrit
  $ java -jar buck-out/gen/gerrit.war

Building release:

  $ buck test --all && buck build :api :release
  $ java -jar buck-out/gen/release.war
  $ ls -lh buck-out/gen/{extension,plugin}-api.jar

Downloading dependencies:

  Dependencies are normally downloaded automatically, but Buck can
  inspect its graph and download missing dependencies so future
  compiles can run without the network:

  $ buck build :download

[1] http://facebook.github.io/buck/

Change-Id: I40853b108bd8e153cefa0896a5280a9a5ff81655
2013-05-09 13:40:36 +00:00