Use relative paths in links in docs.

This change fixes links among Bazel docs to use relative paths links instead of
absolute path (either full URL or absolute from site root). This way, versioned
documentation will link to other pages within the same versioned directory
rather than to the site root, which will point to the latest version of the
page from HEAD.

Future improvements may include adding a lint tool to check links in
documentation to ensure that the correct convention is followed such that all
links to pages within a version of the docs will point to pages within the same
version.

RELNOTES: None
PiperOrigin-RevId: 160117865
diff --git a/site/docs/bazel-user-manual.html b/site/docs/bazel-user-manual.html
index c9f6b70..5b3cbfb 100644
--- a/site/docs/bazel-user-manual.html
+++ b/site/docs/bazel-user-manual.html
@@ -9,7 +9,7 @@
 <p>
   To run Bazel, go to
 
-  your base <a href="/docs/build-ref.html#workspaces">workspace</a> directory
+  your base <a href="build-ref.html#workspaces">workspace</a> directory
   or any of its subdirectories and type <code>bazel</code>.
 </p>
 
diff --git a/site/docs/build-ref.html b/site/docs/build-ref.html
index 7b4fa8e..0b4805b 100644
--- a/site/docs/build-ref.html
+++ b/site/docs/build-ref.html
@@ -55,9 +55,9 @@
    source files for the software you want to build, as well as symbolic links
    to directories that contain the build outputs. Each workspace directory has
    a text file named <code>WORKSPACE</code> which may be empty,  or may contain
-   references to <a href="/docs/external.html">external dependencies</a>
+   references to <a href="external.html">external dependencies</a>
    required to build the outputs. See also the <a
-   href="/docs/be/workspace.html">Workspace Rules</a> section in the Build
+   href="be/workspace.html">Workspace Rules</a> section in the Build
    Encyclopedia.
 </p>
 <h3 id="packages">Packages</h3>
diff --git a/site/docs/external.md b/site/docs/external.md
index ed4b285..5211eea 100644
--- a/site/docs/external.md
+++ b/site/docs/external.md
@@ -6,10 +6,10 @@
 # Working with external dependencies
 
 External dependencies can be specified in the `WORKSPACE` file of the
-[workspace directory](/docs/build-ref.html#workspace). This `WORKSPACE` file
+[workspace directory](build-ref.html#workspace). This `WORKSPACE` file
 uses the same syntax as BUILD files, but allows a different set of
 rules. The full list of rules are in the Build Encyclopedia's
-[Workspace Rules](/docs/be/workspace.html).
+[Workspace Rules](be/workspace.html).
 
 External dependencies are all downloaded and symlinked under a directory named
 `external`. You can see this directory by running:
diff --git a/site/docs/getting-started.md b/site/docs/getting-started.md
index 1e4bc66..92d98ca 100644
--- a/site/docs/getting-started.md
+++ b/site/docs/getting-started.md
@@ -7,19 +7,19 @@
 
 ## Setup
 
-Use the [installation instructions](/docs/install.html) to install a copy of
+Use the [installation instructions](install.html) to install a copy of
 Bazel on your machine.
 
 ## Using a Workspace
 
-All Bazel builds take place in a [_workspace_](/docs/build-ref.html#workspaces),
+All Bazel builds take place in a [_workspace_](build-ref.html#workspaces),
 a directory on your filesystem that contains source code for the software you
 want to build, as well as symbolic links to directories that contain the build
 outputs (for example, `bazel-bin` and `bazel-out`). The location of the
 workspace directory is not significant, but it must contain a file called
 `WORKSPACE` in the top-level directory; an empty file is a valid workspace.
 The `WORKSPACE` file can be used to reference
-[external dependencies](/docs/external.html) required to build the outputs.
+[external dependencies](external.html) required to build the outputs.
 One workspace can be shared among multiple projects if desired.
 
 ```bash
@@ -36,7 +36,7 @@
 
 The rule probably most familiar to people who have used `Makefile`s before (as
 it is the only rule available there) is the
-[genrule](/docs/be/general.html#genrule), which specifies how the output can
+[genrule](be/general.html#genrule), which specifies how the output can
 be generated by invoking a shell command.
 
 ```
@@ -47,7 +47,7 @@
 )
 ```
 
-The shell command may contain [Make variables](/docs/be/make-variables.html).
+The shell command may contain [Make variables](be/make-variables.html).
 
 Using the above `BUILD` file, you can ask Bazel to generate the target.
 
@@ -61,8 +61,8 @@
 ```
 
 We note two things. First, targets are normally referred to by their
-[label](/docs/build-ref.html#labels), which is specified by the
-[name](/docs/be/general.html#genrule.name) attribute of the rule. (Referencing
+[label](build-ref.html#labels), which is specified by the
+[name](be/general.html#genrule.name) attribute of the rule. (Referencing
 them by the output file name is also possible, but this is not the preferred
 way.) Second, Bazel puts the generated files into a separate directory (the
 `bazel-genfiles` directory is actually a symbolic link) so as not to pollute
@@ -86,12 +86,12 @@
 )
 ```
 
-Finally, note that, while the [genrule](/docs/be/general.html#genrule) might
+Finally, note that, while the [genrule](be/general.html#genrule) might
 seem familiar, it usually is _not_ the best rule to use. It is preferrable to
-use one of the specialized [rules](/docs/be/overview.html#rules) for various
+use one of the specialized [rules](be/overview.html#rules) for various
 languages.
 
 # Next Steps
 
-Next, check out the tutorial on building [Java](/docs/tutorial/java.html)
-or [C++](/docs/tutorial/cpp.html) programs.
+Next, check out the tutorial on building [Java](tutorial/java.html)
+or [C++](tutorial/cpp.html) programs.
diff --git a/site/docs/rule-challenges.md b/site/docs/rule-challenges.md
index fece635..23737cd 100644
--- a/site/docs/rule-challenges.md
+++ b/site/docs/rule-challenges.md
@@ -119,7 +119,7 @@
 Above, we argued that in order to be correct, Bazel needs to know all the input
 files that go into a build step in order to detect whether that build step is
 still up-to-date. The same is true for package loading and rule analysis, and we
-have designed [Skyframe] (http://www.bazel.build/docs/skyframe.html) to handle this
+have designed [Skyframe] (https://bazel.build/designs/skyframe.html) to handle this
 in general. Skyframe is a graph library and evaluation framework that takes a
 goal node (such as ‘build //foo with these options’), and breaks it down into
 its constituent parts, which are then evaluated and combined to yield this
diff --git a/site/docs/skylark/language.md b/site/docs/skylark/language.md
index 583e4f7..a8492d6 100644
--- a/site/docs/skylark/language.md
+++ b/site/docs/skylark/language.md
@@ -8,7 +8,7 @@
 ## Syntax
 
 The extension language, Skylark, is a superset of the
-[Core Build Language](/docs/build-ref.html#core_build_language)
+[Core Build Language](../build-ref.html#core_build_language)
 and its syntax is a subset of Python.
 It is designed to be simple, thread-safe and integrated with the
 BUILD language. It is not a general-purpose language and most Python
diff --git a/site/docs/skylark/repository_rules.md b/site/docs/skylark/repository_rules.md
index db839d5..8f2062c 100644
--- a/site/docs/skylark/repository_rules.md
+++ b/site/docs/skylark/repository_rules.md
@@ -7,7 +7,7 @@
 **Status: Experimental**. We may make breaking changes to the API, but we will
   announce them and help you update your code.
 
-An [external repository](/docs/external.md) is a rule that can be used only
+An [external repository](../external.md) is a rule that can be used only
 in the `WORKSPACE` file and enable non-hermetic operation at the loading phase
 of Bazel. Each external repository rule creates its own workspace, with its
 own BUILD files and artifacts. They can be used to depend on third-party
diff --git a/site/docs/tutorial/android-app.md b/site/docs/tutorial/android-app.md
index cdab41e..1c6c722 100644
--- a/site/docs/tutorial/android-app.md
+++ b/site/docs/tutorial/android-app.md
@@ -115,7 +115,7 @@
 
 ## Create a BUILD file
 
-A [`BUILD` file](/docs/build-ref.html#BUILD_files) is a text file that describes
+A [`BUILD` file](../build-ref.html#BUILD_files) is a text file that describes
 the relationship between a set of build outputs -- for example, compiled
 software libraries or executables -- and their dependencies. These dependencies
 may be source files in your workspace or other build outputs. `BUILD` files are
@@ -123,7 +123,7 @@
 
 `BUILD` files are part of concept in Bazel known as the *package hierarchy*.
 The package hierarchy is a logical structure that overlays the directory
-structure in your workspace. Each [package](/docs/build-ref.html#packages) is a
+structure in your workspace. Each [package](../build-ref.html#packages) is a
 directory (and its subdirectories) that contains a related set of source files
 and a `BUILD` file. The package also includes any subdirectories, excluding
 those that contain their own `BUILD` file. The *package name* is the name of the
@@ -145,13 +145,13 @@
 ### Add an android_library rule
 
 A `BUILD` file contains several different types of instructions for Bazel. The
-most important type is the [build rule](/docs/build-ref.html#funcs), which tells
+most important type is the [build rule](../build-ref.html#funcs), which tells
 Bazel how to build an intermediate or final software output from a set of source
 files or other dependencies.
 
 Bazel provides two build rules, `android_library` and `android_binary`, that you
 can use to build an Android app. For this tutorial, you'll first use the
-[`android_library`](/docs/be/android.html#android_library) rule to tell
+[`android_library`](../be/android.html#android_library) rule to tell
 Bazel how to build an
 [Android library module](http://developer.android.com/tools/projects/index.html#LibraryProjects)
 from the app source code and resource files. Then you'll use the
@@ -176,7 +176,7 @@
 
 ### Add an android_binary rule
 
-The [`android_binary`](/docs/be/android.html#android_binary) rule builds
+The [`android_binary`](../be/android.html#android_binary) rule builds
 the Android application package (`.apk` file) for your app.
 
 Add the following to your build file:
@@ -204,10 +204,10 @@
 ## Run the build
 
 You use the
-[`bazel`](/docs/bazel-user-manual.html) command-line tool to run builds, execute
+[`bazel`](../bazel-user-manual.html) command-line tool to run builds, execute
 unit tests and perform other operations in Bazel. This tool is located in the
 `output` subdirectory of the location where you installed Bazel. During
-[installation](/docs/install.md), you probably added this location to your
+[installation](../install.md), you probably added this location to your
 path.
 
 Before you build the sample app, make sure that your current working directory
@@ -223,12 +223,12 @@
 bazel build //android:android
 ```
 
-The [`build`](/docs/bazel-user-manual.html#build) subcommand instructs Bazel to
+The [`build`](../bazel-user-manual.html#build) subcommand instructs Bazel to
 build the target that follows. The target is specified as the name of a build
 rule inside a `BUILD` file, with along with the package path relative to
 your workspace directory. Note that you can sometimes omit the package path
 or target name, depending on your current working directory at the command
-line and the name of the target. See [Labels](/docs/build-ref.html#labels) in
+line and the name of the target. See [Labels](../build-ref.html#labels) in
 *Bazel Concepts and Terminology* page for more information about target labels
 and paths.
 
@@ -271,7 +271,7 @@
 
 You can now deploy the app to a connected Android device or emulator from the
 command line using the
-[`bazel mobile-install`](http://bazel.build/docs/bazel-user-manual.html#mobile-install)
+[`bazel mobile-install`](../bazel-user-manual.html#mobile-install)
 command. This command uses the Android Debug Bridge (`adb`) to communicate with
 the device. You must set up your device to use `adb` following the instructions
 in
@@ -287,7 +287,7 @@
 ```
 
 Note that the `mobile-install` subcommand also supports the
-[`--incremental`](http://bazel.build/docs/bazel-user-manual.html#mobile-install)
+[`--incremental`](../bazel-user-manual.html#mobile-install)
 flag that can be used to deploy only those parts of the app that have changed
 since the last deployment.
 
diff --git a/site/docs/tutorial/backend-server.md b/site/docs/tutorial/backend-server.md
index 9ebbffa..cfcbc2a 100644
--- a/site/docs/tutorial/backend-server.md
+++ b/site/docs/tutorial/backend-server.md
@@ -19,7 +19,7 @@
 *   Deploy to Google App Engine
 
 Bazel provides a set of [App Engine build rules](https://github.com/bazelbuild/rules_appengine)
-written using the [Skylark](/docs/skylark/index.html) framework. You'll use
+written using the [Skylark](../skylark/index.html) framework. You'll use
 these in the steps below to build the application.
 
 ## Review the source files
@@ -50,7 +50,7 @@
 ## Update the WORKSPACE file
 
 As with the Android app, you must add references to
-[external dependencies](http://bazel.build/docs/external.html) to your `WORKSPACE`
+[external dependencies](../external.html) to your `WORKSPACE`
 file. For the backend server, these are references to the App Engine SDK,
 the Java Servlet SDK and other libraries needed to build the App Engine
 applications.
@@ -78,9 +78,9 @@
 appengine_repositories()
 ```
 
-[`http_archive`](/docs/be/workspace.html#http_archive) downloads the
+[`http_archive`](../be/workspace.html#http_archive) downloads the
 AppEngine rules from a GitHub archive. We could also have used
-[`git_repository`](/docs/be/workspace.html#git_repository) to fetch the rules
+[`git_repository`](../be/workspace.html#git_repository) to fetch the rules
 directly from the Git repository.
 
 The next two lines use the `appengine_repositories` function defined in
@@ -118,11 +118,11 @@
 )
 ```
 
-The [`java_binary`](/docs/be/java.html#java_binary) tells Bazel
+The [`java_binary`](../be/java.html#java_binary) tells Bazel
 how to build a Java `.jar` library for your application, plus a wrapper shell
 script that launches the application code from the specified main class. Here,
 we're using this rule instead of the
-[`java_library`](/docs/be/java.html#java_library) because we need
+[`java_library`](../be/java.html#java_library) because we need
 the `.jar` file to contain all the dependencies required to build the final
 App Engine `.war` file. For this reason, we specify a bogus class name
 for the `main_class` attribute.
@@ -147,7 +147,7 @@
 )
 ```
 
-The [`appengine_war`](/docs/be/appengine.html#appengine_war)
+The [`appengine_war`](../be/appengine.html#appengine_war)
 rule builds the final App Engine `war` file from the library `.jar` file and web
 application metadata files in the `webapp` directory.
 
diff --git a/site/docs/tutorial/cpp-use-cases.md b/site/docs/tutorial/cpp-use-cases.md
index 1c3af2c..b005009 100644
--- a/site/docs/tutorial/cpp-use-cases.md
+++ b/site/docs/tutorial/cpp-use-cases.md
@@ -16,7 +16,7 @@
 ## Including multiple files in a target
 
 You can include multiple files in a single target with
-[glob](https://bazel.build/versions/master/docs/be/functions.html#glob).
+[glob](../be/functions.html#glob).
 For example:
 
 ```python
diff --git a/site/docs/tutorial/cpp.md b/site/docs/tutorial/cpp.md
index e0a5e70..95898e3 100644
--- a/site/docs/tutorial/cpp.md
+++ b/site/docs/tutorial/cpp.md
@@ -27,7 +27,7 @@
 
 ## Before you begin
 
-To prepare for the tutorial, first [Install Bazel](/docs/install.md) if
+To prepare for the tutorial, first [Install Bazel](../install.md) if
 you don't have it installed already. Then, retrieve the sample project from
 Bazel's GitHub repository:
 
@@ -369,15 +369,15 @@
 Next, read up on the most common [C++ build use cases](cpp-use-cases.md). Then,
 check out the following:
 
-*  [External Dependencies](https://bazel.build/versions/master/docs/external.html)
-   to learn more about working with local and remote repositories.
+*  [External Dependencies](../external.html) to learn more about working with
+   local and remote repositories.
 
-*  The [Build Encyclopedia](/docs/be/overview.html) to learn more about Bazel.
+*  The [Build Encyclopedia](../be/overview.html) to learn more about Bazel.
 
-*  The [Java build tutorial](/docs/tutorial/java.md) to get started with
+*  The [Java build tutorial](java.md) to get started with
    building Java applications with Bazel.
 
-*  The [mobile application tutorial](/docs/tutorial/app.md) to get started with
+*  The [mobile application tutorial](app.md) to get started with
    building mobile applications for Android and iOS with Bazel.
 
 Happy building!
diff --git a/site/docs/tutorial/environment.md b/site/docs/tutorial/environment.md
index 20a4870..c9f9043 100644
--- a/site/docs/tutorial/environment.md
+++ b/site/docs/tutorial/environment.md
@@ -16,7 +16,7 @@
 
 ## Install Bazel
 
-Follow the [installation instructions](/docs/install.md) to install Bazel and
+Follow the [installation instructions](../install.md) to install Bazel and
 its dependencies.
 
 ## Install Android Studio
diff --git a/site/docs/tutorial/ios-app.md b/site/docs/tutorial/ios-app.md
index ce17c2b..ff6a5b1 100644
--- a/site/docs/tutorial/ios-app.md
+++ b/site/docs/tutorial/ios-app.md
@@ -65,7 +65,7 @@
 
 Bazel provides several build rules that you can use to build an app for the
 iOS platform. For this tutorial, you'll first use the
-[`objc_library`](/docs/be/objective-c.html#objc_library) rule to tell Bazel
+[`objc_library`](../be/objective-c.html#objc_library) rule to tell Bazel
 how to build a static library from the app source code and Xib files. Then
 you'll use the [`ios_application`](https://github.com/bazelbuild/rules_apple)
 rule to tell it how to build the application binary and the `.ipa` bundle.
@@ -93,7 +93,7 @@
 
 ## Add an ios_application rule
 
-The [`ios_application`](/docs/be/objective-c.html#ios_application) rule builds
+The [`ios_application`](../be/objective-c.html#ios_application) rule builds
 the application binary and creates the `.ipa` bundle file.
 
 Add the following to your `BUILD` file:
diff --git a/site/docs/tutorial/java.md b/site/docs/tutorial/java.md
index 34cb7b5..6059ba1 100644
--- a/site/docs/tutorial/java.md
+++ b/site/docs/tutorial/java.md
@@ -25,7 +25,7 @@
 
 ## Before you begin
 
-To prepare for the tutorial, first [Install Bazel](/docs/install.md) if
+To prepare for the tutorial, first [Install Bazel](../install.md) if
 you don't have it installed already. Then, retrieve the sample project from
 Bazel's GitHub repository:
 
@@ -94,7 +94,7 @@
 ```
 
 In our example, the `ProjectRunner` target instantiates Bazel's built-in
-[`java_binary` rule](/docs/be/java.html#java_binary). The rule tells Bazel to
+[`java_binary` rule](../be/java.html#java_binary). The rule tells Bazel to
 build a `.jar` file and a wrapper shell script (both named after the target).
 
 The attributes in the target explicitly state its dependencies and options.
@@ -102,7 +102,7 @@
 `ProjectRunner` rule target, `name` is the name of the target, `srcs` specifies
 the source files that Bazel uses to build the target, and `main_class` specifies
 the class that contains the main method. (You may have noticed that our example
-uses [glob](/docs/be/functions.html#glob) to pass a set of source files to Bazel
+uses [glob](../be/functions.html#glob) to pass a set of source files to Bazel
 instead of listing them one by one.)
 
 ### Build the project
@@ -338,7 +338,7 @@
 of its runtime dependencies. This lets you run the binary outside of your
 development environment.
 
-As you remember, the [java_binary](/docs/be/java.html#java_binary) build rule
+As you remember, the [java_binary](../be/java.html#java_binary) build rule
 produces a `.jar` and a wrapper shell script. Take a look at the contents of
 `runner.jar` using this command:
 
@@ -382,15 +382,15 @@
 
 ## Further reading
 
-*  [External Dependencies](https://bazel.build/versions/master/docs/external.html)
-   to learn more about working with local and remote repositories.
+*  [External Dependencies](../external.html) to learn more about working with
+   local and remote repositories.
 
-*  The [Build Encyclopedia](/docs/be/overview.html) to learn more about Bazel.
+*  The [Build Encyclopedia](../be/overview.html) to learn more about Bazel.
 
-*  The [C++ build tutorial](/docs/tutorial/cpp.md) to get started with building
+*  The [C++ build tutorial](../tutorial/cpp.md) to get started with building
    C++ projects with Bazel.
 
-*  The [mobile application tutorial](/docs/tutorial/app.md) to get started with
+*  The [mobile application tutorial](../tutorial/app.md) to get started with
    building mobile applications for Android and iOS with Bazel.
 
 Happy building!
diff --git a/site/docs/tutorial/workspace.md b/site/docs/tutorial/workspace.md
index eee1b1a..59115c7e 100644
--- a/site/docs/tutorial/workspace.md
+++ b/site/docs/tutorial/workspace.md
@@ -5,7 +5,7 @@
 
 # Tutorial - Set Up a Workspace
 
-A [workspace](/docs/build-ref.html#workspaces) is a directory that contains the
+A [workspace](../build-ref.html#workspaces) is a directory that contains the
 source files for one or more software projects, as well as a `WORKSPACE` file
 and `BUILD` files that contain the instructions that Bazel uses to build
 the software. The workspace may also contain symbolic links to output
@@ -32,7 +32,7 @@
 
 Every workspace must have a text file named `WORKSPACE` located in the top-level
 workspace directory. This file may be empty or it may contain references
-to [external dependencies](/docs/external.html) required to build the
+to [external dependencies](../external.html) required to build the
 software.
 
 For now, you'll create an empty `WORKSPACE` file, which simply serves to