scandeps

package
v0.0.0-...-fb8c843 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package scandeps provides forged C/C++ dependency scanner. Compared with Goma's input processor, it only supports simple form of C preprocessor directives and uses precomputed subtree for sysroots or complicated include dirs.

It only checks the following forms of #include

#include "foo.h"
#include <foo.h>
#include FOO_H

to support last case, it also checks the following forms of #define

#define FOO_H "foo.h"
#define FOO_H <foo.h>
#define FOO_H OTHER_FOO_H

Since it doesn't process `#if` or `#ifdef`, it expands all possible values of macros for `#include FOO_H`. Using extra inputs is not problem, but may have potential cache miss issues, since there is discrepancy between simple scandeps vs clang's *.d outputs. TODO(b/283341125): fix cache miss issue.

It doesn't allow comments nor multiline (\ at the end of line) for the directives.

Also it uses input_deps's label for sysroots etc. if include dir or sysroot dir has label with `:headers`, it adds files of the input_deps instead of scanning files in the dir. Rather using minimum sets of include dirs, it may use more files, but can use precomputed merkletree to improve performance in digest calculation for action inputs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPPScan

func CPPScan(ctx context.Context, fname string, buf []byte) ([]string, map[string][]string, error)

CPPScan scans C preprocessor directives for #include/#define in buf.

func ParseHeaderMap

func ParseHeaderMap(ctx context.Context, buf []byte) (map[string]string, error)

ParseHeaderMap parses *.hmap file.

Types

type Request

type Request struct {
	// Defines are defined macros (on command line).
	// macro value would be `"path.h"` or `<path.h>`
	Defines map[string]string

	// Sources are source files.
	Sources []string

	// Includes are additional include files (i.e. -include or /FI).
	// it would be equivalent with `#include "fname"` in source.
	Includes []string

	// Dirs are include directories (search paths) or hmap paths.
	Dirs []string

	// Frameworks are framework directories (search paths).
	Frameworks []string

	// Sysroots are sysroot directories.
	// It also includes toolchain root directory.
	Sysroots []string

	// To mitigate scanning that does not terminate.
	Timeout time.Duration
}

Request is a request to scan deps.

type ScanDeps

type ScanDeps struct {
	// contains filtered or unexported fields
}

ScanDeps is a simple C/C++ dependency scanner.

func New

func New(hashfs *hashfs.HashFS, inputDeps map[string][]string) *ScanDeps

New creates new ScanDeps.

func (*ScanDeps) Scan

func (s *ScanDeps) Scan(ctx context.Context, execRoot string, req Request) ([]string, error)

Scan scans C/C++ source/header files for req to get C/C++ dependencies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL