From f8db15856ca3e2c74cdda8b4e91ac41978fb9119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Majcherski?= <43614029+majcherm-da@users.noreply.github.com> Date: Tue, 16 Apr 2019 10:00:58 +0200 Subject: [PATCH] windows: navigator build (#485) --- build.ps1 | 10 +++- navigator/frontend/BUILD.bazel | 36 +++++++++------ navigator/frontend/webpack.config.js | 69 +++++++++++++++------------- 3 files changed, 68 insertions(+), 47 deletions(-) diff --git a/build.ps1 b/build.ps1 index e23068181ea..9c57d428f5c 100644 --- a/build.ps1 +++ b/build.ps1 @@ -26,13 +26,16 @@ function build-partial() { //:git-revision ` //compiler/daml-lf-ast/... ` //daml-lf/interface/... ` - //language-support/java/bindings/... + //language-support/java/bindings/... ` + //navigator/backend/... ` + //navigator/frontend/... bazel shutdown bazel test ` //daml-lf/interface/... ` - //language-support/java/bindings/... + //language-support/java/bindings/... ` + //navigator/backend/... } function build-full() { @@ -68,6 +71,8 @@ function build-full() { //ledger/ledger-api-domain/... ` //ledger/ledger-api-server-example ` //ledger-api/rs-grpc-akka/... ` + //navigator/backend/... ` + //navigator/frontend/... ` //pipeline/samples/bazel/java/... ` //pipeline/samples/bazel/haskell/... @@ -88,6 +93,7 @@ function build-full() { //ledger/ledger-api-client/... ` //ledger/ledger-api-common/... ` //ledger-api/rs-grpc-akka/... ` + //navigator/backend/... ` //pipeline/samples/bazel/java/... ` //pipeline/samples/bazel/haskell/... } diff --git a/navigator/frontend/BUILD.bazel b/navigator/frontend/BUILD.bazel index e294f9b80d9..250e40d9064 100644 --- a/navigator/frontend/BUILD.bazel +++ b/navigator/frontend/BUILD.bazel @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") +load("@os_info//:os_info.bzl", "is_windows") filegroup( name = "src", @@ -42,9 +43,9 @@ nodejs_binary( entry_point = "webpack/bin/webpack.js", node_modules = "@navigator_frontend_deps//:node_modules", # The webpack build step requires almost all of the node_modules dependencies - # data = [ - #  ... - # ], + # data = [ + # ... + # ], ) # Builds the frontend single page application and bundles all output files @@ -69,8 +70,10 @@ genrule( # Working directories export IN="$$(pwd)/$(@D)/in" export OUT="$$(pwd)/$(@D)/out" - mkdir "$$IN" - mkdir "$$OUT" + export WP_IN={WP_IN} + export WP_OUT={WP_OUT} + [ -d "$$IN" ] || mkdir "$$IN" + [ -d "$$OUT" ] || mkdir "$$OUT" # Our tools (node.js, webpack, webpack plugins, typescript) do not work nicely # with symbolic links and a node_modules directory that is not in the project root. @@ -83,31 +86,36 @@ genrule( cp -L "$$(pwd)/$(execpath tslint.json)" "$$IN/tslint.json" cp -L "$$(pwd)/$(execpath declarations.d.ts)" "$$IN/declarations.d.ts" - # Webpack needs the HOME variable to be set + # Webpack needs the HOME variable to be set export HOME="$$IN" # Run webpack. # To debug, add the following options: - # -d --progress --display-error-details --verbose + # -d --progress --display-error-details --verbose $(execpath :webpack) \ --config="$$IN/webpack.config.js" \ --env.prod \ - --env.bazel_in_dir="$$IN" \ - --env.bazel_out_dir="$$OUT/frontend" + --env.paths_case_check="{PATHS_CASE_CHECK}" \ + --env.bazel_in_dir="$$WP_IN" \ + --env.bazel_out_dir="$$WP_OUT/frontend" - # Package result (.TGZ) + # Package result (.TGZ) # To debug, change 'czf' to 'czfv'. echo "Packaging result from $$OUT to $(@D)/frontend.tgz" tar czf "$(@D)/frontend.tgz" -C $$OUT . - # Package result (.JAR) + # Package result (.JAR) echo "Packaging result from $$OUT to $(@D)/frontend.jar" - $(JAVABASE)/bin/jar c0Mf "$(@D)/frontend.jar" -C $$OUT . - """, + $(location @bazel_tools//tools/jdk:jar) c0Mf "$(@D)/frontend.jar" -C $$OUT . + """.format( + PATHS_CASE_CHECK = "false" if is_windows else "true", + WP_IN = "$$(cygpath -w $$IN)" if is_windows else "$$IN", + WP_OUT = "$$(cygpath -w $$OUT)" if is_windows else "$$OUT", + ), toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"], tools = [ ":webpack", - "@bazel_tools//tools/jdk:current_java_runtime", + "@bazel_tools//tools/jdk:jar", ], visibility = [ "//navigator:__subpackages__", diff --git a/navigator/frontend/webpack.config.js b/navigator/frontend/webpack.config.js index f016cf86ebb..49c9983f87e 100644 --- a/navigator/frontend/webpack.config.js +++ b/navigator/frontend/webpack.config.js @@ -51,11 +51,12 @@ const APP_NAME = 'Navigator'; * - paths: https://www.typescriptlang.org/docs/handbook/compiler-options.html */ module.exports = (env) => { - const in_dir = env && env.bazel_in_dir || __dirname; - const out_dir = env && env.bazel_out_dir || path.join(__dirname, 'dist'); - const build_version = env && env.bazel_version_file ? fs.readFileSync(env.bazel_version_file, 'utf8').trim() : 'HEAD'; - const build_commit = env && env.bazel_commit_file ? fs.readFileSync(env.bazel_commit_file, 'utf8').trim() : 'HEAD'; - const isProduction = env ? (!!env.prod || !!env.production) : false; + const paths_case_check = env && env.paths_case_check || 'true'; + const in_dir = env && env.bazel_in_dir || __dirname; + const out_dir = env && env.bazel_out_dir || path.join(__dirname, 'dist'); + const build_version = env && env.bazel_version_file ? fs.readFileSync(env.bazel_version_file, 'utf8').trim() : 'HEAD'; + const build_commit = env && env.bazel_commit_file ? fs.readFileSync(env.bazel_commit_file, 'utf8').trim() : 'HEAD'; + const isProduction = env ? (!!env.prod || !!env.production) : false; console.log(isProduction ? 'PRODUCTION' : 'DEVELOPMENT'); const modernizr_config = path.join(in_dir, '.modernizrrc'); @@ -67,8 +68,39 @@ module.exports = (env) => { console.log(` out_dir: ${out_dir}`); console.log(` modernizr_config: ${modernizr_config}`); console.log(` typescript_config: ${typescript_config}`); + console.log(` paths_case_check: ${paths_case_check}`); console.log(`============================== Webpack environment =============================`); + var plugins = [ + new HtmlWebpackPlugin({ + title: APP_NAME, + template: 'src/index.html' + }), + new FaviconsWebpackPlugin({ + logo: './src/images/favicon.png', + prefix: 'icons-[hash]/', + inject: true, // into HtmlWebpackPlugin + background: '#fff', + title: APP_NAME, + icons: { + android: false, + appleIcon: true, + appleStartup: true, + coast: false, + favicons: true, + firefox: true, + opengraph: false, + twitter: false, + yandex: false, + windows: false + } + }), + ] + + if (paths_case_check === 'true') { + plugins.push(new CaseSensitivePathsPlugin()) + } + return { entry: { browsercheck: './src/browsercheck.ts', @@ -153,32 +185,7 @@ module.exports = (env) => { modernizr$: modernizr_config, } }, - plugins: [ - new HtmlWebpackPlugin({ - title: APP_NAME, - template: 'src/index.html' - }), - new FaviconsWebpackPlugin({ - logo: './src/images/favicon.png', - prefix: 'icons-[hash]/', - inject: true, // into HtmlWebpackPlugin - background: '#fff', - title: APP_NAME, - icons: { - android: false, - appleIcon: true, - appleStartup: true, - coast: false, - favicons: true, - firefox: true, - opengraph: false, - twitter: false, - yandex: false, - windows: false - } - }), - new CaseSensitivePathsPlugin(), - ], + plugins: plugins, devServer: { port: 8000, // host: '0.0.0.0', // enable to allow remote computers to connect