Skip to content

Commit

Permalink
Merge pull request #319 from PRUNERS/issue121-bash-completion
Browse files Browse the repository at this point in the history
Issue121 bash completion
  • Loading branch information
JohnJacobsonIII authored Mar 18, 2020
2 parents e5e9175 + fde3afa commit c5553cc
Show file tree
Hide file tree
Showing 34 changed files with 1,142 additions and 298 deletions.
154 changes: 87 additions & 67 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ MKDIR ?= mkdir -m 0755 -p

SOURCE := $(wildcard src/flit/*.cpp)
HEADERS := src/flit.h
FLIT_HEADERS += $(wildcard src/flit/*.h)
FLIT_HEADERS := $(wildcard src/flit/*.h)

# Install variables

SCRIPT_DIR := scripts/flitcli
DATA_DIR := data
CONFIG_DIR := $(SCRIPT_DIR)/config
DOC_DIR := documentation
LITMUS_TESTS += $(wildcard litmus-tests/tests/*.cpp)
LITMUS_TESTS += $(wildcard litmus-tests/tests/*.h)
SCRIPT_DIR := scripts/flitcli
BASH_COMPLETE_DIR := scripts/bash-completion
DATA_DIR := data
CONFIG_DIR := $(SCRIPT_DIR)/config
DOC_DIR := documentation
LITMUS_TESTS += $(wildcard litmus-tests/tests/*.cpp)
LITMUS_TESTS += $(wildcard litmus-tests/tests/*.h)

EFFECTIVE_PREFIX := $(DESTDIR)$(PREFIX)
INST_BINDIR := $(EFFECTIVE_PREFIX)/bin
INST_LIBDIR := $(EFFECTIVE_PREFIX)/lib
INST_INCLUDEDIR := $(EFFECTIVE_PREFIX)/include/flit
INST_SHAREDIR := $(EFFECTIVE_PREFIX)/share/flit
INST_SRCDIR := $(EFFECTIVE_PREFIX)/share/flit/src
INST_LICENSEDIR := $(EFFECTIVE_PREFIX)/share/licenses/flit
INST_FLIT_CONFIG := $(EFFECTIVE_PREFIX)/share/flit/scripts/flitconfig.py
EFFECTIVE_PREFIX := $(DESTDIR)$(PREFIX)
INST_BINDIR := $(EFFECTIVE_PREFIX)/bin
INST_LIBDIR := $(EFFECTIVE_PREFIX)/lib
INST_INCLUDEDIR := $(EFFECTIVE_PREFIX)/include/flit
INST_SHAREDIR := $(EFFECTIVE_PREFIX)/share/flit
INST_SRCDIR := $(EFFECTIVE_PREFIX)/share/flit/src
INST_LICENSEDIR := $(EFFECTIVE_PREFIX)/share/licenses/flit
INST_FLIT_CONFIG := $(EFFECTIVE_PREFIX)/share/flit/scripts/flitconfig.py
INST_BASH_COMPLETE_DIR := $(EFFECTIVE_PREFIX)/share/bash-completion/completions

-include tests/color_out.mk

Expand Down Expand Up @@ -56,17 +58,18 @@ help:

.PHONY: check
check:
$(MAKE) check --directory tests
$(MAKE) --no-print-directory check --directory tests

.PHONY: clean
clean:
$(MAKE) clean --directory tests
$(MAKE) --no-print-directory clean --directory tests

.PHONY: install
install:
@$(call color_out,BLUE,Installing: DESTDIR=$(DESTDIR) PREFIX=$(PREFIX))
$(MKDIR) $(INST_BINDIR)
$(MKDIR) $(INST_INCLUDEDIR)
$(MKDIR) $(INST_BASH_COMPLETE_DIR)
$(MKDIR) $(INST_SHAREDIR)/scripts/experimental
$(MKDIR) $(INST_SHAREDIR)/doc
$(MKDIR) $(INST_SHAREDIR)/data/tests
Expand All @@ -78,16 +81,23 @@ install:
$(MKDIR) $(INST_LICENSEDIR)
@$(call color_out,CYAN, Creating command-line symbolic link $(INST_BINDIR)/flit)
ln -sf ../share/flit/scripts/flit.py $(INST_BINDIR)/flit
@$(call color_out,BROWN, Installing includes into $(INST_INCLUDEDIR))
install -m 0644 $(HEADERS) $(EFFECTIVE_PREFIX)/include
install -m 0644 $(FLIT_HEADERS) $(INST_INCLUDEDIR)
@$(call color_out,BROWN, Installing source into $(INST_SRCDIR))
install -m 0644 $(SOURCE) $(INST_SRCDIR)
@$(call color_out,BROWN, Installing scripts into $(INST_SHAREDIR)/scripts)
install -m 0755 $(SCRIPT_DIR)/flit.py $(INST_SHAREDIR)/scripts/
install -m 0755 $(SCRIPT_DIR)/flit_*.py $(INST_SHAREDIR)/scripts/
install -m 0755 $(SCRIPT_DIR)/experimental/flit_*.py $(INST_SHAREDIR)/scripts/experimental/
install -m 0644 $(SCRIPT_DIR)/experimental/ninja_syntax.py $(INST_SHAREDIR)/scripts/experimental/
install -m 0644 $(SCRIPT_DIR)/flitutil.py $(INST_SHAREDIR)/scripts/
install -m 0644 $(SCRIPT_DIR)/flitelf.py $(INST_SHAREDIR)/scripts/
install -m 0644 $(SCRIPT_DIR)/README.md $(INST_SHAREDIR)/scripts/
@$(call color_out,BROWN, Intalling bash-completion script into $(INST_BASH_COMPLETE_DIR))
@$(call color_out,GREEN, You can source it in your ~/.bashrc or copy it to /etc/bash_completion.d/)
install -m 0644 $(BASH_COMPLETE_DIR)/* $(INST_BASH_COMPLETE_DIR)/
@$(call color_out,BROWN, Installing documentation into $(INST_SHAREDIR)/doc)
install -m 0644 $(DOC_DIR)/*.md $(INST_SHAREDIR)/doc/
install -m 0644 $(DATA_DIR)/Makefile.in $(INST_SHAREDIR)/data/
install -m 0644 $(DATA_DIR)/Makefile_bisect_binary.in $(INST_SHAREDIR)/data/
Expand All @@ -97,60 +107,67 @@ install:
install -m 0644 $(DATA_DIR)/db/tables-sqlite.sql $(INST_SHAREDIR)/data/db/
install -m 0644 $(CONFIG_DIR)/version.txt $(INST_SHAREDIR)/config/
install -m 0644 $(CONFIG_DIR)/flit-default.toml.in $(INST_SHAREDIR)/config/
@$(call color_out,BROWN, Installing litmus tests into $(INST_SHAREDIR)/litmus-tests)
install -m 0644 $(LITMUS_TESTS) $(INST_SHAREDIR)/litmus-tests/
install -m 0644 LICENSE $(INST_LICENSEDIR)
@$(call color_out,BROWN, Intsalling benchmarks into $(INST_SHAREDIR)/benchmarks)
cp -r benchmarks/* $(INST_SHAREDIR)/benchmarks/
@$(call color_out,CYAN, Generating $(INST_FLIT_CONFIG))
@# Make the flitconfig.py script specifying this installation information
@echo "'''" > $(INST_FLIT_CONFIG)
@echo "Contains paths and other configurations for the flit installation." >> $(INST_FLIT_CONFIG)
@echo "This particular file was autogenerated at the time of installation." >> $(INST_FLIT_CONFIG)
@echo "This is the file that allows installations to work from any prefix." >> $(INST_FLIT_CONFIG)
@echo "'''" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "import os" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "all = [" >> $(INST_FLIT_CONFIG)
@echo " 'version'," >> $(INST_FLIT_CONFIG)
@echo " 'script_dir'," >> $(INST_FLIT_CONFIG)
@echo " 'doc_dir'," >> $(INST_FLIT_CONFIG)
@echo " 'src_dir'," >> $(INST_FLIT_CONFIG)
@echo " 'include_dir'," >> $(INST_FLIT_CONFIG)
@echo " 'config_dir'," >> $(INST_FLIT_CONFIG)
@echo " 'data_dir'," >> $(INST_FLIT_CONFIG)
@echo " 'litmus_test_dir'," >> $(INST_FLIT_CONFIG)
@echo " ]" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "_scriptpath = os.path.dirname(os.path.abspath(__file__))" >> $(INST_FLIT_CONFIG)
@echo "_prefix = os.path.realpath(" >> $(INST_FLIT_CONFIG)
@echo " os.path.join(_scriptpath, '..', '..', '..'))" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# flit scripts" >> $(INST_FLIT_CONFIG)
@echo "script_dir = os.path.join(_prefix, 'share', 'flit', 'scripts')" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# flit documentation" >> $(INST_FLIT_CONFIG)
@echo "doc_dir = os.path.join(_prefix, 'share', 'flit', 'doc')" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# flit C++ include files, primarily flit/flit.h" >> $(INST_FLIT_CONFIG)
@echo "include_dir = os.path.join(_prefix, 'include')" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# flit C++ source files" >> $(INST_FLIT_CONFIG)
@echo "src_dir = os.path.join(_prefix, 'share', 'flit', 'src')" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# default configuration for flit init" >> $(INST_FLIT_CONFIG)
@echo "config_dir = os.path.join(_prefix, 'share', 'flit', 'config')" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# current version" >> $(INST_FLIT_CONFIG)
@echo "version_file = os.path.join(config_dir, 'version.txt')" >> $(INST_FLIT_CONFIG)
@echo "with open(version_file, 'r') as _version_file_opened:" >> $(INST_FLIT_CONFIG)
@echo " version = _version_file_opened.read().strip()" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# default data files such as Makefile.in and main.cpp" >> $(INST_FLIT_CONFIG)
@echo "data_dir = os.path.join(_prefix, 'share', 'flit', 'data')" >> $(INST_FLIT_CONFIG)
@echo >> $(INST_FLIT_CONFIG)
@echo "# directory containing litmus tests" >> $(INST_FLIT_CONFIG)
@echo "litmus_test_dir = os.path.join(" >> $(INST_FLIT_CONFIG)
@echo " _prefix, 'share', 'flit', 'litmus-tests')" >> $(INST_FLIT_CONFIG)
# Make the flitconfig.py script specifying this installation information
echo "'''" > $(INST_FLIT_CONFIG)
echo "Contains paths and other configurations for the flit installation." >> $(INST_FLIT_CONFIG)
echo "This particular file was autogenerated at the time of installation." >> $(INST_FLIT_CONFIG)
echo "This is the file that allows installations to work from any prefix." >> $(INST_FLIT_CONFIG)
echo "'''" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "import os" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "all = [" >> $(INST_FLIT_CONFIG)
echo " 'version'," >> $(INST_FLIT_CONFIG)
echo " 'script_dir'," >> $(INST_FLIT_CONFIG)
echo " 'doc_dir'," >> $(INST_FLIT_CONFIG)
echo " 'src_dir'," >> $(INST_FLIT_CONFIG)
echo " 'include_dir'," >> $(INST_FLIT_CONFIG)
echo " 'config_dir'," >> $(INST_FLIT_CONFIG)
echo " 'bash_completion_dir'," >> $(INST_FLIT_CONFIG)
echo " 'data_dir'," >> $(INST_FLIT_CONFIG)
echo " 'litmus_test_dir'," >> $(INST_FLIT_CONFIG)
echo " ]" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "_scriptpath = os.path.dirname(os.path.abspath(__file__))" >> $(INST_FLIT_CONFIG)
echo "_prefix = os.path.realpath(" >> $(INST_FLIT_CONFIG)
echo " os.path.join(_scriptpath, '..', '..', '..'))" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# flit scripts" >> $(INST_FLIT_CONFIG)
echo "script_dir = os.path.join(_prefix, 'share', 'flit', 'scripts')" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# flit documentation" >> $(INST_FLIT_CONFIG)
echo "doc_dir = os.path.join(_prefix, 'share', 'flit', 'doc')" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# flit C++ include files, primarily flit/flit.h" >> $(INST_FLIT_CONFIG)
echo "include_dir = os.path.join(_prefix, 'include')" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# flit C++ source files" >> $(INST_FLIT_CONFIG)
echo "src_dir = os.path.join(_prefix, 'share', 'flit', 'src')" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# default configuration for flit init" >> $(INST_FLIT_CONFIG)
echo "config_dir = os.path.join(_prefix, 'share', 'flit', 'config')" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# where bash completion scripts for flit reside" >> $(INST_FLIT_CONFIG)
echo "bash_completion_dir = os.path.join(" >> $(INST_FLIT_CONFIG)
echo " _prefix, 'share', 'bash-completion', 'completions')" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# current version" >> $(INST_FLIT_CONFIG)
echo "version_file = os.path.join(config_dir, 'version.txt')" >> $(INST_FLIT_CONFIG)
echo "with open(version_file, 'r') as _version_file_opened:" >> $(INST_FLIT_CONFIG)
echo " version = _version_file_opened.read().strip()" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# default data files such as Makefile.in and main.cpp" >> $(INST_FLIT_CONFIG)
echo "data_dir = os.path.join(_prefix, 'share', 'flit', 'data')" >> $(INST_FLIT_CONFIG)
echo >> $(INST_FLIT_CONFIG)
echo "# directory containing litmus tests" >> $(INST_FLIT_CONFIG)
echo "litmus_test_dir = os.path.join(" >> $(INST_FLIT_CONFIG)
echo " _prefix, 'share', 'flit', 'litmus-tests')" >> $(INST_FLIT_CONFIG)

.PHONY: uninstall
uninstall:
Expand All @@ -161,7 +178,10 @@ uninstall:
$(RMDIR) $(INST_LICENSEDIR)
$(RM) $(INST_BINDIR)/flit
$(RM) $(EFFECTIVE_PREFIX)/include/flit.h
$(RM) $(INST_BASH_COMPLETE_DIR)/flit
-rmdir --ignore-fail-on-non-empty $(EFFECTIVE_PREFIX)/include 2>/dev/null
-rmdir --ignore-fail-on-non-empty $(EFFECTIVE_PREFIX)/share/bash-completion/completions 2>/dev/null
-rmdir --ignore-fail-on-non-empty $(EFFECTIVE_PREFIX)/share/bash-completion 2>/dev/null
-rmdir --ignore-fail-on-non-empty $(EFFECTIVE_PREFIX)/share/licenses 2>/dev/null
-rmdir --ignore-fail-on-non-empty $(EFFECTIVE_PREFIX)/share 2>/dev/null
-rmdir --ignore-fail-on-non-empty $(EFFECTIVE_PREFIX)/bin 2>/dev/null
Expand Down
2 changes: 1 addition & 1 deletion documentation/experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ read variables if they are present. The variables read from `custom.mk` are

This `custom.mk` file is in GNU Makefile format. Any additional variables and
rules defined inside are completely ignored. Feel free to use anything from
GNU Make including `if` statements and things like `$(wildcard ../src/*.cpp)`.
GNU Make including `if` statements and things like `$(wildcard ../src/*.cpp)`.



Expand Down
15 changes: 15 additions & 0 deletions documentation/flit-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Possible subcommands:
* [flit bisect](#flit-bisect): Assign variability blame to files and functions
* [flit experimental](#flit-experimental): Access to experimental features

Possibly of interest:

* [Adding More Subcommands](#adding-more-subcommands)

## flit help

This can display the help documentation for a specific subcommand. This is
Expand Down Expand Up @@ -220,6 +224,17 @@ You may also read the documentation on
[experimental features](experimental-features.md).


## Adding More Subcommands

The FLiT command-line structure is extremely modular. If you create a file
with the correct naming scheme, put it in the correct directory, and implement
three things, it will automatically be picked up and become available as a
subcommand from the `flit` command-line tool.

See the flit command-line [README.md](../scripts/flitcli/README.md) for more
information.


[Prev](litmus-tests.md)
|
[Table of Contents](README.md)
Expand Down
43 changes: 43 additions & 0 deletions documentation/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Instruction Contents:
* [Compilers](#compilers)
* [Optional Dependencies](#optional-dependencies)
* [FLiT Setup](#flit-setup)
* [Bash Completion](#bash-completion)
* [Database Setup](#database-setup)
* [Uninstallation](#uninstallation)

Expand Down Expand Up @@ -218,6 +219,48 @@ ln -s ~/FLiT/scripts/flitcli/flit.py ~/bin/flit
See [FLiT Command-Line](flit-command-line.md) for more information on how to
use the command-line tool.

## Bash Completion

FLiT comes with a bash-completion script to be used with bash. In the
repository, the script can be found at `scripts/bash-completion/flit`. If you
install FLiT using `make install`, it gets installed to
`$PREFIX/share/bash-completion/completions/flit`. Some systems will be able to
use the flit bash completion from this location directly (if `$PREFIX="/usr"`).
Other systems store these scripts in `/etc/bash_completion.d/`.

If your system stores bash-completion scripts in `/etc/bash_completion.d/`, you
can either copy the script, or create a symbolic link (preferred).

```bash
sudo ln -s /usr/share/bash-completion/completions/flit /etc/bash_completion.d/flit
```

If you do not have sudo permissions or do not want to install bash-completion
for flit system-wide, then you can implement it locally for your user account.
Newer bash-completion installations allow users to have a script in their home
directory called `$HOME/.bash_completion`. We recommend you have a directory
for storing bash-completion scripts. You can put the following in your
`$HOME/.bash_completion` file

```bash
if [ -d ~/.local/share/bash-completion/completions ]; then
for file in ~/.local/share/bash-completion/completions/*; do
if [ -f "$file" ]; then
source "$file"
fi
done
fi
```

Then you can simply copy or symbolically link bash-completion scripts into
`~/.local/share/bash-completion/completions`. If you are using FLiT from the
repository, you can accomplish that with

```bash
mkdir -p ~/.local/share/bash-completion/completions
ln -s <git-repo-dir>/FLiT/scripts/bash-completion/flit ~/.local/share/bash-completion/completions/flit
```

## Database Setup

There should be nothing to setup since `sqlite3` should already be present.
Expand Down
Loading

0 comments on commit c5553cc

Please sign in to comment.