Skip to content

Commit

Permalink
[support, docs] A minimal implementation of the "realpath" CLI.
Browse files Browse the repository at this point in the history
This frees us from needing a system prerequisite, and enables
platforms that don't even provide such a binary.
  • Loading branch information
tkoeppe committed Oct 16, 2018
1 parent 0c9dac6 commit bed70eb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ addons:
- python-dev
- python-numpy
- python-pil
- realpath

before_install:
- curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
Expand Down
9 changes: 6 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,9 @@ genrule(
" A=$$(dirname $$s); " +
" B=$${A/assets/}; " +
" mkdir -p $(@D)/baselab$${B}; " +
" ln -s -L -t $(@D)/baselab$${B} $$(realpath $${s}); " +
" ln -s -L -t $(@D)/baselab$${B} $$($(location //deepmind/support:realpath) $${s}); " +
"done",
tools = ["//deepmind/support:realpath"],
visibility = ["//visibility:public"],
)

Expand All @@ -703,8 +704,9 @@ genrule(
cmd = "for s in $(SRCS); do " +
" A=$$(dirname $$s); " +
" mkdir -p $(@D)/baselab/$${A}; " +
" ln -s -L -t $(@D)/baselab/$${A} $$(realpath $${s}); " +
" ln -s -L -t $(@D)/baselab/$${A} $$($(location //deepmind/support:realpath) $${s}); " +
"done",
tools = ["//deepmind/support:realpath"],
visibility = ["//visibility:public"],
)

Expand All @@ -719,8 +721,9 @@ genrule(
outs = ["baselab/maps" + f[len("assets/maps/built"):] for f in BUILT_MAPS],
cmd = "for s in $(SRCS); do " +
" mkdir -p $(@D)/baselab/maps; " +
" ln -s -L -t $(@D)/baselab/maps $$(realpath $${s}); " +
" ln -s -L -t $(@D)/baselab/maps $$($(location //deepmind/support:realpath) $${s}); " +
"done",
tools = ["//deepmind/support:realpath"],
visibility = ["//visibility:public"],
)

Expand Down
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
state](https://github.com/ioquake/ioq3/tree/29db64070aa0bae49953bddbedbed5e317af48ba).
5. Lua 5.1 is now downloaded and built from source, and is thus no longer a
required local dependency.
6. A minimal version of the "realpath" utility is now bundled with the code,
and thus "realpath" is no longer a required local dependency.

### Bug Fixes:

Expand Down
10 changes: 10 additions & 0 deletions deepmind/support/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ cc_library(
hdrs = ["test_srcdir.h"],
defines = ["SUPPRESS_COMMANDLINE_FLAGS"],
)

cc_binary(
name = "realpath",
srcs = ["realpath.c"],
copts = [
"-std=c99",
"-D_BSD_SOURCE",
"-D_POSIX_C_SOURCE",
],
)
46 changes: 46 additions & 0 deletions deepmind/support/realpath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2018 Google Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
////////////////////////////////////////////////////////////////////////////////
//
// A minimal driver for Posix realpath(). Not every Posix system supplies such
// a driver, and even on those that do it might require a separate installation
// step. This implements the equivalent of "realpath -e" on Linux.

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[]) {
int num_errors = 0;
errno = 0;

for (int i = 1; i < argc; ++i) {
char* p = realpath(argv[i], NULL);
if (p == NULL) {
fprintf(stderr, "Error resolving path '%s', error was: '%s'\n",
argv[i], strerror(errno));
errno = 0;
++num_errors;
} else {
fprintf(stdout, "%s\n", p);
free(p);
}
}

return num_errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
2 changes: 1 addition & 1 deletion docs/users/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ are documented in a [separate section](#python-dependencies) below.

```shell
$ sudo apt-get install libffi-dev gettext freeglut3-dev libsdl2-dev \
libosmesa6-dev python-dev python-numpy python-pil realpath
libosmesa6-dev python-dev python-numpy python-pil
```

* On Red Hat Enterprise Linux Server:
Expand Down

0 comments on commit bed70eb

Please sign in to comment.