This commit removes the complex pipeline leveraging output from
/dev/urandom and simply uses $RANDOM variable. For the purpose
of generating an available container name, it will works well.
Suggested-by: Matt McCormick <matt.mccormick@kitware.com>
As explained in [1], when using dockcross from python subprocess, the
interactive mode is disabled and output of "cat /dev/urandom" is block
buffered instead of being line buffered.
Workaround to this problem is to simply read a fixed amount of characters
from urandom.
The following two snippets illustrates the problem and the
the implemented solution:
Works
```python
import subprocess as sp
sp.check_call("var=$(head -c 500 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1); echo $var", shell=True)
```
=> output random string
Fail:
```python
import subprocess as sp
sp.check_call("var=$(cat /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1); echo $var", shell=True)
```
=> Hang
[1] http://stackoverflow.com/questions/16805827/unable-to-read-stdout-from-a-running-process#16806506
where RAND is a 7 characters long randomly generated alphanumeric string.
Note that container name can NOT start with "_",
only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed
See #50
This commit fixes a regression [1] introduced in 606d0b3 (Makefile: Make sure
BIN directory exist when running any test)
Reported below the dry-run summary before and after, we can confirm the
bin directory is now created when building the `base.test` target.
Before:
$ make base.test --dry-run
docker build -t dockcross/base .
docker run --rm dockcross/base > bin/dockcross-base && chmod +x bin/dockcross-base
After:
$ make base.test --dry-run
docker build -t dockcross/base .
mkdir -p bin
docker run --rm dockcross/base > bin/dockcross-base && chmod +x bin/dockcross-base
[1] Error fixed by this commit:
Successfully built e6388fe49824
docker run --rm dockcross/base > bin/dockcross-base && chmod +x bin/dockcross-base
/bin/sh: 1: cannot create bin/dockcross-base: Directory nonexistent
make: *** [base.test] Error 2
make base.test returned exit code 2
This commit also ensures that:
* all image targets are declared as PHONY
* "test" and not "tests" is declared as PHONY
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared.
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
make browser-asmjs.test --dry-run > ../dockcross-make-browser-asmjs-test-baseline
make linux-ppc64le.test --dry-run > ../dockcross-make-linux-ppc64le-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
make browser-asmjs.test --dry-run > ../dockcross-make-browser-asmjs-test-current
make linux-ppc64le.test --dry-run > ../dockcross-make-linux-ppc64le-test-current
for target in make make-test make-browser-asmjs-test make-linux-ppc64le-test; do
diff --ignore-trailing-space ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared:
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff --ignore-trailing-space ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared.
The only difference was due to the extra space in the command line
associated with windows-x86
```
< bin/dockcross-windows-x86 python test/run.py --exe-suffix ".exe"
---
> bin/dockcross-windows-x86 python test/run.py --exe-suffix ".exe"
```
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff --ignore-trailing-space ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared:
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
Adding a new images with the usual build rule:
$(DOCKER) build -t $(ORG)/$@ $@
is now just a matter of adding an item to the "STANDARD_IMAGES" list.
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared.
Note that since this patch changes the order in which the images are
listed (manylinux is now last), the baseline and current files are
different. After inspection, we can confirm the difference is explained
by the order of the commands.
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
Since image targets are all "phony", they are always consider out-of-date
and will always be rebuilt. This means there is no need to add an explicit
dependency on non-generated files like "Dockerfile", "settings.mk" and
"test/run.py".
The only required dependencies on Dockerfile are the one for the "base"
and "manylinux" images.
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared:
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
Since image targets are all "phony", they are always consider out-of-date
and will always be rebuilt. This means there is no need to add an explicit
dependency on the "Toolchain.cmake" file.
Note also that the dependency on "Toolchain.cmake" was not consistent
for all images. For example, "linux-x64" was missing the dependency
whereas it was specified for "linux-x86".
This commit ensure all image targets are consistent removing the
dependency on "Toolchain.cmake".
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared:
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
See https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html#File-Name-Functions
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared:
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
To confirm that the Makefiles works as expected after this patch, the
list of executed commands before and after is compared:
Before:
```
make --dry-run > ../dockcross-make-baseline
make test --dry-run > ../dockcross-make-test-baseline
```
After:
```
make --dry-run > ../dockcross-make-current;
make test --dry-run > ../dockcross-make-test-current
for target in make make-test; do
diff ../dockcross-$target-current ../dockcross-$target-baseline > /dev/null 2>&1
[[ $? == 1 ]] && \
echo "" && \
echo "Error: Problem with '${target}' target: Dry-run output before and after this commit do not match."
done
```
This will allow build script like "build-wheels.sh" to run command like
the following (see [1]):
sudo yum install -y atlas-devel
It will also allow to pip install using sudo and avoid error reported in [3].
That said, instead of running pip using sudo, the recommended approach
is to specify the "--user" flag [2]
[1] 893d92517e/travis/build-wheels.sh
[2] http://stackoverflow.com/questions/7143077/how-can-i-install-packages-in-my-home-folder-with-pip#7143496
[3] Error reported when running pip without "sudo pip install <packagename" or "pip install --user <packagename>"
```
Exception:
Traceback (most recent call last):
File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/req/req_set.py", line 736, in install
requirement.uninstall(auto_confirm=True)
File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/req/req_install.py", line 742, in uninstall
paths_to_remove.remove(auto_confirm)
File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/shutil.py", line 303, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: '/opt/_internal/cpython-2.7.11-ucs2/bin/easy_install'
```
By default the toolchain file is always passed as an option to cmake/ccmake
It can be explicitly disabled setting the environment variable
DOCKCROSS_PASS_CMAKE_TOOLCHAIN_FILE to 0