How to run the Polyglot Code Scanner
How to run the Polyglot Code Scanner
The code scanner is a rust command-line program - which means applications are compiled executable binary files, which you run from a terminal.
There are two ways to run the scanner - download a binary executable for your platform, or build it yourself from source.
NOTE I haven't been able to test the binary releases myself on many platforms, so if these don't work, you might have to revert to compiling yourself. (Feel free to raise an issue though, and I'll try to fix it)
Binary releases are published to https://github.com/kornysietsma/polyglot-code-scanner/releases
You should be able to download the right file for your platform here. Note I haven't tested this at all on Windows yet! And I only have a single generic build for linux x86 and OSX - I can add more if there's demand.
OSX has a system to protect you from malware, called 'gatekeeper' - by default on OSX if you try to run the binary app, you'll get an error "app is from an unknown developer". To bypass this I'd have to go through a complex extra stage of signing and bundling my tool as an application, which I'm avoiding for now.
If you are happy that the binary is safe - all the code that builds it is on github, so you should be able to inspect it yourself - you can run it by stripping the extra attributes that OSX adds when you download it, using
tar zxf polyglot-code-scanner-vwhatever-x86_64-apple-darwin.tar.gzcd polyglot-code-scanner-vwhatever-x86_64-apple-darwinxattr -d com.apple.quarantine polyglot_code_scanner
Then you can move the
polyglot_code_scanner binary to whever you want.
If you don't want to trust the binary, follow the steps below to compile it yourself.
Get rust and cargo - instructions are at https://www.rust-lang.org/tools/install
Clone or fork the project from https://github.com/kornysietsma/polyglot-code-scanner
Or you can fetch the source code for a particular release from https://github.com/kornysietsma/polyglot-code-scanner/releases
test and build with
cargothe rust packaging tool:
$ cargo test# ... maybe some warnings but hopefully no failures$ cargo build --release# ... lots of messages and noise - compiling can be slow$ ls -l target/releasetotal 14368drwxr-xr-x 125 korny staff 4000 28 Jul 15:09 builddrwxr-xr-x 891 korny staff 28512 28 Jul 15:11 depsdrwxr-xr-x 2 korny staff 64 20 Jun 15:20 examplesdrwxr-xr-x 2 korny staff 64 20 Jun 15:20 incremental-rw-r--r-- 1 korny staff 1003 29 Jun 14:45 libpolyglot_code_scanner.d-rw-r--r-- 2 korny staff 3062736 28 Jul 15:11 libpolyglot_code_scanner.rlib-rwxr-xr-x 2 korny staff 4280600 28 Jul 15:11 polyglot_code_scanner-rw-r--r-- 1 korny staff 1063 29 Jun 14:45 polyglot_code_scanner.d$ target/release/polyglot_code_scanner -Vpolyglot_code_scanner 0.1.2
All you need to care about is the binary
polyglot_code_scanner - that's what you need to run. You can run it from the target directory or copy it somewhere useful.
(You can also run the project with
cargo run but that's slower as it runs with debugging and without a lot of optimisation)
You can run
polyglot_code_scanner -h for command-line help.
Usually you will just run:
polyglot_code_scanner --coupling -o json_file_name.json <source directory>
"--years <git_years>" - scan through this much history. Git scanning can be slow, and often you only care about the last few years.
"--coupling" - enables temporal coupling. This can be very very slow to calculate - if you don't want it, don't specify this option! TODO: link to temporal coupling explanation
The scanner actually works in terms of directories and subdirectories, rather than really caring too much about git repositories. (It's even possible to work with code without git data - in theory, though this is probably broken once you try to visualise the results)
So you can store git repositories under the scanned root directory - it's quite common to check out every repository for a project as children of the root directory, and then use the
--circles layout option to show those repositories as top-level circles in the explorer.
You can even go deeper - one project I worked on had a nested tree of directories and projects 2 or 3 levels under the root; the scanner handles this just fine.
The scanner automatically ignores any files that git ignores, using the standard
.gitignore file mechanisms.
You can also add your own ignore files - at the root, or anywhere in subdirectories - the scanner will look for files called
.polyglot_code_scanner_ignore files anywhere in the codebase, the syntax is the same as .gitignore's.
So for example if you want to ignore node.js junk, XML and CSV files you could add a
.polyglot_code_scanner_ignore file at the root of your project with the content:
See Data Format for a description of the output JSON file format.
It's not pretty printed to save space - if you want it pretty, the easiest thing is to install jq and run:
jq < file.json | less