Skip to content

Commit e608bdd

Browse files
committed
[support, docs] A minimal implementation of the "realpath" CLI.
This frees us from needing a system prerequisite, and enables platforms that don't even provide such a binary.
1 parent 0c9dac6 commit e608bdd

File tree

6 files changed

+61
-5
lines changed

6 files changed

+61
-5
lines changed

Diff for: .travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ addons:
1818
- python-dev
1919
- python-numpy
2020
- python-pil
21-
- realpath
2221

2322
before_install:
2423
- curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -

Diff for: BUILD

+6-3
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,9 @@ genrule(
686686
" A=$$(dirname $$s); " +
687687
" B=$${A/assets/}; " +
688688
" mkdir -p $(@D)/baselab$${B}; " +
689-
" ln -s -L -t $(@D)/baselab$${B} $$(realpath $${s}); " +
689+
" ln -s -L -t $(@D)/baselab$${B} $$($(location //deepmind/support:realpath) $${s}); " +
690690
"done",
691+
tools = ["//deepmind/support:realpath"],
691692
visibility = ["//visibility:public"],
692693
)
693694

@@ -703,8 +704,9 @@ genrule(
703704
cmd = "for s in $(SRCS); do " +
704705
" A=$$(dirname $$s); " +
705706
" mkdir -p $(@D)/baselab/$${A}; " +
706-
" ln -s -L -t $(@D)/baselab/$${A} $$(realpath $${s}); " +
707+
" ln -s -L -t $(@D)/baselab/$${A} $$($(location //deepmind/support:realpath) $${s}); " +
707708
"done",
709+
tools = ["//deepmind/support:realpath"],
708710
visibility = ["//visibility:public"],
709711
)
710712

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

Diff for: RELEASE_NOTES.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
state](https://github.com/ioquake/ioq3/tree/29db64070aa0bae49953bddbedbed5e317af48ba).
1515
5. Lua 5.1 is now downloaded and built from source, and is thus no longer a
1616
required local dependency.
17+
6. A minimal version of the "realpath" utility is now bundled with the code,
18+
and thus "realpath" is no longer a required local dependency.
1719

1820
### Bug Fixes:
1921

Diff for: deepmind/support/BUILD

+6
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ cc_library(
2323
hdrs = ["test_srcdir.h"],
2424
defines = ["SUPPRESS_COMMANDLINE_FLAGS"],
2525
)
26+
27+
cc_binary(
28+
name = "realpath",
29+
srcs = ["realpath.c"],
30+
copts = ["-std=c99"],
31+
)

Diff for: deepmind/support/realpath.c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (C) 2018 Google Inc.
2+
//
3+
// This program is free software; you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation; either version 2 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License along
14+
// with this program; if not, write to the Free Software Foundation, Inc.,
15+
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16+
//
17+
////////////////////////////////////////////////////////////////////////////////
18+
//
19+
// A minimal driver for Posix realpath(). Not every Posix system supplies such
20+
// a driver, and even on those that do it might require a separate installation
21+
// step. This implements the equivalent of "realpath -e" on Linux.
22+
23+
#include <errno.h>
24+
#include <stdio.h>
25+
#include <stdlib.h>
26+
#include <string.h>
27+
28+
int main(int argc, char* argv[]) {
29+
int num_errors = 0;
30+
errno = 0;
31+
32+
for (int i = 1; i < argc; ++i) {
33+
char* p = realpath(argv[i], NULL);
34+
if (p == NULL) {
35+
fprintf(stderr, "Error resolving path '%s', error was: '%s'\n",
36+
argv[i], strerror(errno));
37+
errno = 0;
38+
++num_errors;
39+
} else {
40+
fprintf(stdout, "%s\n", p);
41+
free(p);
42+
}
43+
}
44+
45+
return num_errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
46+
}

Diff for: docs/users/build.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ are documented in a [separate section](#python-dependencies) below.
3131

3232
```shell
3333
$ sudo apt-get install libffi-dev gettext freeglut3-dev libsdl2-dev \
34-
libosmesa6-dev python-dev python-numpy python-pil realpath
34+
libosmesa6-dev python-dev python-numpy python-pil
3535
```
3636

3737
* On Red Hat Enterprise Linux Server:

0 commit comments

Comments
 (0)