A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
discover.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef A11_FLOW_DISCOVER_H_
18#define A11_FLOW_DISCOVER_H_
19
20#include <cstddef>
21#include <optional>
22#include <string>
23#include <string_view>
24#include <vector>
25
26#include <absl/types/span.h>
27
28#include "a11/flow/catalogue.h"
29
30namespace a11::flow {
31
71namespace discover {
72
79
81enum class Language {
82 kPython,
83 kCpp,
85};
86
89std::optional<Language> LanguageOf(std::string_view path);
90
92struct Options {
96 std::vector<std::string> skip_directories;
97
101 size_t max_file_bytes = 1u << 20;
102
104 size_t max_files = 20000;
105
107 static Options Default();
108};
109
115struct Result {
118 size_t files_read = 0;
120 std::vector<std::string> too_large;
122 bool reached_file_limit = false;
123};
124
131Result Discover(absl::Span<const std::string> roots,
132 const Options& options = Options::Default());
133
138catalogue::Catalogue DiscoverInSource(std::string_view source,
139 std::string_view path, Language language);
140
141// The `format` field of the envelope a scan answers with, which is the
142// catalogue's own: what a scan produces *is* a catalogue, and a consumer that
143// had to tell them apart would be a consumer with two code paths for one.
148inline constexpr std::string_view kScanFormat = catalogue::kCatalogueFormat;
149
150} // namespace discover
151} // namespace a11::flow
152
153#endif // A11_FLOW_DISCOVER_H_
Everything the tools know about the world, in one place.
Definition catalogue.h:119
std::string path
Definition main.cc:133
std::vector< std::string > roots
Definition main.cc:135
constexpr std::string_view kCatalogueFormat
The format field of the catalogue envelope.
Definition catalogue.h:169
Result Discover(absl::Span< const std::string > roots, const Options &options)
Every ActionSchema declared under roots, as a catalogue with origins.
Definition discover.cc:1406
constexpr std::string_view kScanFormat
The format field of the envelope a scan answers with, which is the catalogue's own: what a scan produ...
Definition discover.h:148
catalogue::Catalogue DiscoverInSource(std::string_view source, std::string_view path, Language language)
The same, for one file whose text is already in hand.
Definition discover.cc:1400
std::optional< Language > LanguageOf(std::string_view path)
The language a path's extension says it is, or nullopt for a file this does not read.
Definition discover.cc:1369
Language
A language an ActionSchema may be declared in.
Definition discover.h:81
Definition boundary.cc:32
Where an entry was declared, for an entry that was found by reading source.
Definition catalogue.h:63
What to read and what to leave alone.
Definition discover.h:92
std::vector< std::string > skip_directories
Directory names never descended into.
Definition discover.h:96
static Options Default()
Options with the defaults filled in.
Definition discover.cc:1389
size_t max_file_bytes
The largest file read.
Definition discover.h:101
size_t max_files
The most files read in one scan.
Definition discover.h:104
What a scan found, and what it did not read.
Definition discover.h:115
catalogue::Catalogue found
Definition discover.h:116
std::vector< std::string > too_large
Files skipped for being larger than max_file_bytes.
Definition discover.h:120
size_t files_read
Files opened and read to the end.
Definition discover.h:118
bool reached_file_limit
Whether max_files stopped the walk before it ran out of files.
Definition discover.h:122