Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Add workaround for specifying serving_path on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion committed Dec 22, 2018
1 parent fa6b790 commit 3d38e11
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
6 changes: 6 additions & 0 deletions devserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func main() {
os.Exit(1)
}

if !strings.HasPrefix(*servingPath, "/") {
fmt.Fprintf(os.Stderr, "The specified serving_path does not start with a slash. " +
"This causes the serving path to not have any effect.\n")
os.Exit(1)
}

preScripts := make([]string, 0, 100)
postScripts := make([]string, 0, 1)

Expand Down
2 changes: 0 additions & 2 deletions examples/protocol_buffers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ ts_devserver(
entry_module = "build_bazel_rules_typescript/examples/protocol_buffers/app",
port = 8080,
deps = [":bundle"],
static_files = [":index.html"],
serving_path = "/concatjs-bundle.js",
)

# Test for production mode
Expand Down
4 changes: 3 additions & 1 deletion examples/protocol_buffers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<title>protocol_buffers example</title>
</head>
<body>
<script src="/concatjs-bundle.js"></script>
<script src="/protobuf.min.js"></script>
<script src="/long.js"></script>
<script src="/bundle.min.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion internal/devserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package(default_visibility = [

exports_files([
"ts_devserver.bzl", # Exported to be consumed for generating skydoc.
"devserver_launcher.sh",
"launcher_template.sh",
])

filegroup(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
# Copyright 2017 The Bazel Authors. All rights reserved.
#!/bin/bash

# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +48,9 @@ readonly manifest=$(rlocation "TEMPLATED_workspace/TEMPLATED_manifest")
readonly scripts_manifest=$(rlocation "TEMPLATED_workspace/TEMPLATED_scripts_manifest")
readonly entry_module=$(rlocation "TEMPLATED_entry_module")

"${main}" \
# Workaround for https://github.com/bazelbuild/bazel/issues/6764
# If this issue is incorporated into Bazel, the workaround here should be removed.
MSYS2_ARG_CONV_EXCL="*" "${main}" \
-packages=TEMPLATED_packages \
-serving_path=TEMPLATED_serving_path \
-manifest="${manifest}" \
Expand Down
18 changes: 7 additions & 11 deletions internal/devserver/ts_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ def _ts_devserver(ctx):
])

substitutions = {
"TEMPLATED_entry_module": ctx.attr.entry_module,
"TEMPLATED_main": script_path,
"TEMPLATED_workspace": workspace_name,
"TEMPLATED_packages": ",".join(packages.to_list()),
"TEMPLATED_serving_path": ctx.attr.serving_path if ctx.attr.serving_path else "",
"TEMPLATED_manifest": ctx.outputs.manifest.short_path,
"TEMPLATED_scripts_manifest": ctx.outputs.scripts_manifest.short_path,
"TEMPLATED_entry_module": ctx.attr.entry_module,
"TEMPLATED_packages": ",".join(packages.to_list()),
"TEMPLATED_port": str(ctx.attr.port),
"TEMPLATED_scripts_manifest": ctx.outputs.scripts_manifest.short_path,
"TEMPLATED_serving_path": ctx.attr.serving_path if ctx.attr.serving_path else "",
"TEMPLATED_workspace": workspace_name,
}
ctx.actions.expand_template(
template=ctx.file._launcher_template,
Expand Down Expand Up @@ -207,17 +207,13 @@ ts_devserver = rule(
executable = True,
cfg = "host",
),
"_launcher_template": attr.label(allow_single_file = True, default = Label("//internal/devserver:launcher_template.sh")),
"_requirejs_script": attr.label(allow_single_file = True, default = Label("@build_bazel_rules_typescript_devserver_deps//node_modules/requirejs:require.js")),
"_launcher_template": attr.label(
default = Label("//internal/devserver:devserver_launcher.sh"),
allow_files = True,
single_file = True
),
},
outputs = {
"manifest": "%{name}.MF",
"scripts_manifest": "scripts_%{name}.MF",
"script": "%{name}.sh",
"scripts_manifest": "scripts_%{name}.MF",
},
executable = True,
)
Expand Down

0 comments on commit 3d38e11

Please sign in to comment.