LGTM Enterprise 1.22.1

Configuring worker hosts for code analysis

During the analysis of compiled languages, LGTM builds the code. This means that each worker host must be configured with the environment needed to build the codebases that you want to analyze on that machine. Interpreted languages often also depend on the presence of other software in the environment, and these must be made available too.

To set up the required environment for one or more projects, you can set environment variables for all of the worker daemons running on a host, or for groups of one or more workers. You do this in the cluster configuration file—see Setting environment variables for workers.

You may need to set up multiple environments, to build the code for different projects. You can then use labels to determine which workers are used to build specific projects. For more information, see Defining which workers can build and analyze a project.

In this topic

Determining what to install

In general, worker host machines should be set up in much the same way as you set up a continuous integration (CI) slave—with the software and environment required by the projects you plan to analyze on that machine.

Core requirements

The core requirements listed below are the minimum required to analyze code written in each language. Your projects may have additional requirements. Compiled languages have further requirements (detailed in the following section).

Language Essential
C/C++

Method of building the code (see next table).

C#

Method of building the code (see next table).

COBOL

No further requirements.

Go

Go toolchain (version 1.11 or later)

If dependencies are managed using dep, install version 0.5.0 or later of dep.

If dependencies are managed using Glide, install version 0.13.0 or later of Glide.

Java

Method of building the code (see next table).

JavaScript

No further requirements unless any TypeScript files are present.

If the repository also includes TypeScript files, the TypeScript requirements must be met, or TypeScript analysis disabled.

Python

Access to the pip packaging management system.

Installation of the packaging and virtualenv pip modules.

Ability to download any packages that the Python codebases you intend to analyze depend on.

TypeScript

Node.js version 6.x or later.

Auto-deduction of build commands for compiled languages

For C/C++, C#, and Java code, LGTM Enterprise uses a series of heuristics to determine a suitable set of build commands, using an appropriate build system. This is referred to as "autobuild." For each language, the autobuild process chooses between a set commonly used build systems (listed in the following table), and runs commands for that system. If your organization uses one or more of these build systems, install them on the relevant worker host machines. If some projects use other build systems, you also need to make these systems available. These projects will require a custom build configuration.

Language Automated build configuration available for
C/C++

Linux workers: Autoconf, CMake, QMake, Meson, WAF, SCons, and Linux KBuild

Windows workers: MSBuild

C#

MSBuild, .NET Core, Mono (Linux), and Visual Studio (Windows)

Java

Gradle, Maven and Ant

If you set up machines with different build environments for different types of project, set worker labels so that you can define which languages/projects are analyzed by each type of worker. For more information about setting worker labels, see Defining which workers can build and analyze a project.

Checking the basic configuration

Linux machines

You can use the lgtm-build-requirements command to check whether the basic dependencies and environment for building/analyzing projects using the default build methods supported by LGTM Enterprise are set up correctly.

On each Linux machine that runs worker daemons, run the command:

sudo lgtm-build-requirements

If you're not the root user you need to use sudo to run the lgtm-build-requirements command.

This command checks the machine for basic checkout and build requirements. Any systems that are accessible to LGTM workers are reported with a success message. For example:

[info] Python
[success] python2 found.
[success] pip for python2 found.
[success] packaging for python2 found.
[success] virtualenv for python2 found.
[error] python3 was not found. You are unlikely to be able to analyze any Python 3 projects.

In this example, the command successfully found the core dependencies for Python 2 analysis but not for Python 3 analysis.

Windows machines

For details of the system requirements of Windows machines in the work pool, see System requirements.

When you use install-machine.bat to deploy LGTM workers, the script sets the LGTM worker daemons to run under the account that you specify when you run the script. Alternatively, if you don't specify an account the LocalSystem account is used.

After installing the build tools that you need, check that they are available on the PATH for this account, and that Python 2.7 (required by the workers) is also installed and on the PATH.

Setting up a worker host for JavaScript and TypeScript analysis

Analysis of JavaScript code has no additional dependencies.

If a project includes TypeScript files (.ts and .tsx) you must install Node.js 6.x or later (we recommend the latest LTS version) on any worker host machines that will be used to analyze this code.

Linux machines

Check whether Node is available by running the lgtm-build-requirements command:

[sudo] lgtm-build-requirements

If the command returns the message [warning] node was not found, install Node.js 6.x or later (LTS version recommended).

Windows machines

Check whether Node is available by requesting the version number:

node -v

If the command returns the message 'node' is not recognized..., install Node.js 6.x or later (LTS version recommended) and add it to the PATH.

Setting up a worker host for Python analysis

Check whether Python is available by requesting the version number:

python -v

An appropriate version of Python must be available for the projects you want workers on this machine to analyze. If you want workers on a single host machine to analyze projects written in different versions of Python you can set a different PATH environment variable for specific workers (see Setting environment variables for workers) and then apply labels to workers and projects to ensure each project is processed by an appropriate worker (see Defining which workers can build and analyze a project).

Extraction of Python code relies on access to the pip packaging management system, and installation of the packaging and virtualenv pip modules.

Linux machines

To check on the availability of pip, run the following command on each worker:
python -c 'import pip'
If pip is available, the prompt returns without comment. Otherwise an error is reported.

To install pip:

  • On RedHat or CentOS run: sudo yum -y install python-pip
  • On Debian or Ubuntu run: sudo apt-get install python-pip

To install the packaging and virtualenv modules, run:

  • sudo pip install packaging virtualenv

Windows machines

LGTM requires Python 2.7 to be installed and on the PATH on all Windows worker hosts (irrespective of the language that will be analyzed). If your Python projects need to be built with another Python version you should install it in addition to 2.7. If you need to analyze Python 3 code, see Installing Python 3 below.

To check on the availability of pip, run the following command on each worker:
python -m pip --version
If pip is available, the version number is reported. Otherwise an error is reported.

To install pip:

  1. Download get-pip.py to the machine.
  2. Open a command prompt window and navigate to the directory containing get-pip.py.
  3. Run python get-pip.py. This will install pip.
  4. Check that pip is now available. If you still see an error, add pip to the PATH.

To install the packaging and virtualenv modules, run:

  • python -m pip install packaging virtualenv

Installing Python 3

Setting up a worker host for Go analysis

Install the Go toolchain on any machine that hosts worker daemons that will be used to build Go projects. If dependencies are managed using dep or Glide, install these also. See the table above for supported versions.

For projects whose dependencies are not managed using dep or Glide you only need to install the Go toolchain.

Related topicsRelated topics