summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/rules.bzl
blob: 7788e5f0f5f6a6fa600f3cdca46f6e2929fd5503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library")
load("//tools/bzl:genrule2.bzl", "genrule2")
load(
    "//tools/bzl:js.bzl",
    "bundle_assets",
)

def polygerrit_bundle(name, srcs, outs, app):
    appName = app.split(".html")[0].split("/").pop()  # eg: gr-app

    closure_js_binary(
        name = name + "_closure_bin",
        # Known issue: Closure compilation not compatible with Polymer behaviors.
        # See: https://github.com/google/closure-compiler/issues/2042
        compilation_level = "WHITESPACE_ONLY",
        defs = [
            "--polymer_version=1",
            "--jscomp_off=duplicate",
            "--force_inject_library=es6_runtime",
        ],
        language = "ECMASCRIPT5",
        deps = [name + "_closure_lib"],
    )

    closure_js_library(
        name = name + "_closure_lib",
        srcs = [appName + ".js"],
        convention = "GOOGLE",
        # TODO(davido): Clean up these issues: http://paste.openstack.org/show/608548
        # and remove this supression
        suppress = [
            "JSC_JSDOC_MISSING_TYPE_WARNING",
            "JSC_UNNECESSARY_ESCAPE",
            "JSC_UNUSED_LOCAL_ASSIGNMENT",
        ],
        deps = [
            "//lib/polymer_externs:polymer_closure",
            "@io_bazel_rules_closure//closure/library",
        ],
    )

    bundle_assets(
        name = appName,
        srcs = srcs,
        app = app,
        deps = ["//polygerrit-ui:polygerrit_components.bower_components"],
    )

    native.filegroup(
        name = name + "_app_sources",
        srcs = [
            name + "_closure_bin.js",
            appName + ".html",
        ],
    )

    native.filegroup(
        name = name + "_css_sources",
        srcs = native.glob(["styles/**/*.css"]),
    )

    native.filegroup(
        name = name + "_theme_sources",
        srcs = native.glob(
            ["styles/themes/*.html"],
            # app-theme.html already included via an import in gr-app.html.
            exclude = ["styles/themes/app-theme.html"],
        ),
    )

    native.filegroup(
        name = name + "_top_sources",
        srcs = [
            "favicon.ico",
        ],
    )

    genrule2(
        name = name,
        srcs = [
            name + "_app_sources",
            name + "_css_sources",
            name + "_theme_sources",
            name + "_top_sources",
            "//lib/fonts:robotofonts",
            "//lib/js:highlightjs_files",
            # we extract from the zip, but depend on the component for license checking.
            "@webcomponentsjs//:zipfile",
            "//lib/js:webcomponentsjs",
        ],
        outs = outs,
        cmd = " && ".join([
            "mkdir -p $$TMP/polygerrit_ui/{styles/themes,fonts,bower_components/{highlightjs,webcomponentsjs},elements}",
            "for f in $(locations " + name + "_app_sources); do ext=$${f##*.}; cp -p $$f $$TMP/polygerrit_ui/elements/" + appName + ".$$ext; done",
            "cp $(locations //lib/fonts:robotofonts) $$TMP/polygerrit_ui/fonts/",
            "for f in $(locations " + name + "_top_sources); do cp $$f $$TMP/polygerrit_ui/; done",
            "for f in $(locations " + name + "_css_sources); do cp $$f $$TMP/polygerrit_ui/styles; done",
            "for f in $(locations " + name + "_theme_sources); do cp $$f $$TMP/polygerrit_ui/styles/themes; done",
            "for f in $(locations //lib/js:highlightjs_files); do cp $$f $$TMP/polygerrit_ui/bower_components/highlightjs/ ; done",
            "unzip -qd $$TMP/polygerrit_ui/bower_components $(location @webcomponentsjs//:zipfile) webcomponentsjs/webcomponents-lite.js",
            "cd $$TMP",
            "find . -exec touch -t 198001010000 '{}' ';'",
            "zip -qr $$ROOT/$@ *",
        ]),
    )