Merge pull request #10 from daveshah1/infrafix

Improving Project Trellis Infrastructure
diff --git a/.gitignore b/.gitignore
index c66cc06..12c37d5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
 ispTcl.tcl
 ispTcl.tcl.*
 .ispTcl.lock
+work_*/
diff --git a/README.md b/README.md
index fd6519e..3eba7a1 100644
--- a/README.md
+++ b/README.md
@@ -18,16 +18,25 @@
 
 # Quickstart Guide
 
+Currently Project Trellis is tested on Arch Linux and Ubuntu 17.10.
+
 Install the dependencies:
  - Lattice Diamond 3.10
- - Python 3.5 or later
+ - Python 3.5 or later, including development libraries (`python3-dev` on Ubuntu)
  - A modern C++14 compiler (g++ or Clang recommended)
- - Boost
+ - CMake 3.8 or later
+ - Boost including boost-python
  
 Pull submodules:
 
     git submodule update --init --recursive
 
+For a generic environment:
+
+    source environment.sh
+
+Optionally, modify `user_environment.sh` and rerun the above command if needed.
+
 Get a head start by downloading current database:
 
     # Give the argument;
@@ -36,29 +45,23 @@
     # - git if you want to use the git protocol
     ./download-latest-db.sh
 
-For a generic environment:
+Alternatively, if you want to start from scratch:
 
-    source environment.sh
-  
-TODO: device specific environments, like X-ray
+    ./create-empty-db.sh
 
-Build libtrellis:
+Build and test libtrellis:
 
     cd libtrellis
     cmake .
     make
+    cd tests/
+    ./run_all.sh
 
-Once fuzzers are written, the below will also work:
 
-(Re-)creating the database:
+(Re-)creating parts of the database, for example LUT interconnect:
 
-    cd fuzzers
-    make -j$(nproc)
-
-(Re-)creating parts of the database, for example LUT init bits:
-
-    cd fuzzers/010-lutinit
-    make -j$(nproc) run
+    cd fuzzers/001-plc2_routing
+    TRELLIS_JOBS=`nproc` python3 fuzzer.py
 
 # Process
 
@@ -133,9 +136,9 @@
 
 ## TODO List
 
- - [ ] Write fuzzing framework for configuration bit and routing fuzzing
+ - [X] Write fuzzing framework for configuration bit and routing fuzzing
  - [ ] Fuzz logic tile init and config bits
- - [ ] Fuzz logic tile routing
+ - [X] Fuzz logic tile routing
  - [ ] Fuzz other routing tiles (CIBs)
  - [ ] Fuzz IO tiles
  - [ ] Fuzz global clock tiles
diff --git a/create-empty-db.sh b/create-empty-db.sh
new file mode 100755
index 0000000..2ccfa52
--- /dev/null
+++ b/create-empty-db.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+rm -rf database
+mkdir -p database
+echo '*' > database/.gitignore
+cp devices.json database/
+python3 tools/get_tilegrid_all.py
+python3 tools/create_empty_bitdbs.py
diff --git a/download-latest-db.sh b/download-latest-db.sh
new file mode 100755
index 0000000..8612565
--- /dev/null
+++ b/download-latest-db.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+GITHUB_PROTO=${1:-https}
+GITHUB_URL=$GITHUB_PROTO://github.com/SymbiFlow/prjtrellis-db.git
+rm -rf database
+git clone $GITHUB_URL database
+echo '*' > database/.gitignore
diff --git a/libtrellis/CMakeLists.txt b/libtrellis/CMakeLists.txt
index a3f7d31..200e21a 100644
--- a/libtrellis/CMakeLists.txt
+++ b/libtrellis/CMakeLists.txt
@@ -1,12 +1,38 @@
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.8)
 project(libtrellis)
 
 set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra -Werror")
 set(CMAKE_DEFIN)
-find_package(PythonInterp)
-find_package(PythonLibs)
-find_package(Boost REQUIRED COMPONENTS python3 filesystem thread)
+set(boost_libs filesystem thread)
+find_package(PythonInterp 3.5 REQUIRED)
+find_package(PythonLibs 3.5 REQUIRED)
+
+find_package(Boost REQUIRED COMPONENTS ${boost_libs})
+
+set(version ${PYTHONLIBS_VERSION_STRING})
+
+STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
+find_package(Boost COMPONENTS "python-py${boost_py_version}" ${boost_libs})
+set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+
+while(NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND)
+    STRING( REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version} )
+
+    STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
+    find_package(Boost COMPONENTS "python-py${boost_py_version}" ${boost_libs})
+    set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+
+    STRING( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} )
+    if("${has_more_version}" STREQUAL "")
+        break()
+    endif()
+endwhile()
+
+if(NOT Boost_PYTHON_FOUND)
+    find_package(Boost COMPONENTS python3 ${boost_libs})
+endif()
+
 include_directories(include/ ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
 
 aux_source_directory(include/ INCLUDE_FILES)
diff --git a/libtrellis/tests/run_all.sh b/libtrellis/tests/run_all.sh
index ee202a2..804095b 100755
--- a/libtrellis/tests/run_all.sh
+++ b/libtrellis/tests/run_all.sh
@@ -12,7 +12,7 @@
 mkdir -p ${DIR}/work
 
 for f in ${DIR}/*.py; do
-    python $f
+    python3 $f
     RC="$?"
     let total++
     if [[ "$RC" -eq 0 ]]; then