treewide: rename to src/
This commit is contained in:
131
src/commands/cmake.ts
Normal file
131
src/commands/cmake.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
import { optFlag, undefList } from "./common"
|
||||
|
||||
export type CMakeDefinition = {
|
||||
name: string,
|
||||
value: string,
|
||||
type?: CMakeVariableType
|
||||
}
|
||||
|
||||
export type CMakeVariableType = "BOOL" | "FILEPATH" | "PATH" | "STRING" | "INTERNAL"
|
||||
|
||||
/**
|
||||
* General CMake variables.
|
||||
*/
|
||||
export interface GeneralVariable {
|
||||
CMAKE_BUILD_TYPE?: "Debug" | "Release" | "RelWithDebInfo" | "MinSizeRel"
|
||||
BUILD_SHARED_LIBS?: boolean,
|
||||
CMAKE_INSTALL_PREFIX?: string,
|
||||
CMAKE_SYSROOT?: string,
|
||||
CMAKE_C_COMPILER?: string,
|
||||
CMAKE_CXX_COMPILER?: string,
|
||||
CMAKE_Fortran_COMPILER?: string,
|
||||
CMAKE_Fortran_COMPILER_ID?: string,
|
||||
CMAKE_C_FLAGS?: string,
|
||||
CMAKE_CXX_FLAGS?: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* CMake variables suitable for LLVM project.
|
||||
*/
|
||||
export interface LLVMVariable {
|
||||
LLVM_TARGETS_TO_BUILD?: string[]
|
||||
LLVM_ENABLE_CLASSIC_FLANG?: boolean,
|
||||
LLVM_ENABLE_PROJECTS?: ("clang" | "openmp" | "lld" | "clang-tools-extra")[]
|
||||
LIBOMP_ARCH?: "Sw64"
|
||||
LIBOMP_USE_ITT_NOTIFY?: boolean
|
||||
LIBOMP_ENABLE_SHARED?: boolean
|
||||
OPENMP_ENABLE_LIBOMPTARGET?: boolean
|
||||
}
|
||||
|
||||
export interface CFlangCMakeVariable {
|
||||
FLANG_INCLUDE_DIRS?: boolean
|
||||
FLANG_LLVM_EXTENSIONS?: boolean
|
||||
WITH_WERROR?: boolean
|
||||
LLVM_CONFIG?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cmake definitions, take care of funny cmake string lists.
|
||||
*
|
||||
* @param object A set of cmake variables to generate
|
||||
* @returns A list of cmake definitions, could be passed to CLI
|
||||
*/
|
||||
export function variable(object: Object): CMakeDefinition[] {
|
||||
return Object.entries(object).map(([k, v]) => {
|
||||
if (typeof v === "boolean") {
|
||||
return {
|
||||
name: k,
|
||||
value: v ? "ON" : "OFF",
|
||||
type: "BOOL"
|
||||
}
|
||||
} else if (typeof v === "object" && Array.isArray(v)) {
|
||||
return {
|
||||
name: k,
|
||||
value: v.join(";"),
|
||||
type: "STRING"
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
name: k,
|
||||
value: v,
|
||||
type: "STRING"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Options for "Generate a Project Buildsystem"
|
||||
* @see https://cmake.org/cmake/help/latest/manual/cmake.1.html#generate-a-project-buildsystem
|
||||
*/
|
||||
export interface CMakeGenerateOptions {
|
||||
pathToBuild?: string
|
||||
pathToSource?: string
|
||||
|
||||
/**
|
||||
* Pre-load a script to populate the cache.
|
||||
* When CMake is first run in an empty build tree, it creates a
|
||||
* CMakeCache.txt file and populates it with customizable settings for the project.
|
||||
* This option may be used to specify a file from which to load cache entries
|
||||
* before the first pass through the project's CMake listfiles.
|
||||
* The loaded entries take priority over the project's default values.
|
||||
* The given file should be a CMake script containing set() commands that use the CACHE option,
|
||||
* not a cache-format file.
|
||||
*/
|
||||
preloadCache?: string
|
||||
|
||||
|
||||
definitions?: CMakeDefinition[]
|
||||
|
||||
/**
|
||||
* Specify a build system generator.
|
||||
*
|
||||
* CMake may support multiple native build systems on certain platforms.
|
||||
* A generator is responsible for generating a particular build system.
|
||||
* Possible generator names are specified in the [cmake-generators(7)](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#manual:cmake-generators(7)) manual.
|
||||
*/
|
||||
generator?: "Unix Makefiles" | "Ninja"
|
||||
|
||||
/**
|
||||
* Specify the cross compiling toolchain file, equivalent to setting CMAKE_TOOLCHAIN_FILE variable.
|
||||
* Relative paths are interpreted as relative to the build directory,
|
||||
* and if not found, relative to the source directory.
|
||||
*
|
||||
* New in version 3.21.
|
||||
*/
|
||||
toolchain?: string
|
||||
}
|
||||
|
||||
export function command(o: CMakeGenerateOptions): string[] {
|
||||
return [
|
||||
...optFlag("-G", o.generator),
|
||||
...undefList(o.definitions, defs => defs.flatMap(def => [
|
||||
"-D",
|
||||
`${def.name}${def.type ? `:${def.type}` : ""}=${def.value}`
|
||||
])),
|
||||
...optFlag("-B", o.pathToBuild),
|
||||
...optFlag("-S", o.pathToSource),
|
||||
]
|
||||
}
|
||||
15
src/commands/common.ts
Normal file
15
src/commands/common.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function undefList<T, U>(opt: T | undefined, fn: (opt: T) => U) {
|
||||
return opt === undefined ? [] : fn(opt)
|
||||
}
|
||||
|
||||
export const optFlag = (flag: string, opt: string | undefined) => undefList(opt, opt => [flag, opt])
|
||||
|
||||
/**
|
||||
* Generate a switch flag, like "--rebuild", "--nobuild"
|
||||
*/
|
||||
export const optSwitch = (flag: string, opt: boolean | undefined) => undefList(opt, opt => opt ? [flag] : [])
|
||||
|
||||
export const optMultiFlag = (flag: string, opt: string[] | undefined) =>
|
||||
undefList(
|
||||
opt,
|
||||
opt => opt.flatMap(name => [flag, name]))
|
||||
93
src/commands/compiler.ts
Normal file
93
src/commands/compiler.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { optFlag, optMultiFlag, optSwitch, undefList } from "./common";
|
||||
|
||||
export interface GeneralOptions {
|
||||
output?: string
|
||||
|
||||
sysroot?: string
|
||||
|
||||
outputKind?: "exe" | "object" | "assembly" | "preprocessed"
|
||||
}
|
||||
|
||||
export function generalCommand(options: GeneralOptions) {
|
||||
return [
|
||||
...optFlag("-o", options.output),
|
||||
...undefList(options.outputKind, (opt) => {
|
||||
switch (opt) {
|
||||
case "object":
|
||||
return ["-c"]
|
||||
case "exe":
|
||||
return []
|
||||
case "assembly":
|
||||
return ["-S"]
|
||||
case "preprocessed":
|
||||
return ["-E"]
|
||||
}
|
||||
}),
|
||||
...optFlag("--sysroot", options.sysroot),
|
||||
]
|
||||
}
|
||||
|
||||
interface LinkerOptions {
|
||||
/**
|
||||
* Directory searched for "-l"
|
||||
*/
|
||||
searchDirs?: string[];
|
||||
|
||||
/**
|
||||
* -l libraries.
|
||||
* Static library dependecies must be sorted in topologic order.
|
||||
*/
|
||||
libraries?: string[];
|
||||
}
|
||||
|
||||
export function linkerCommand(options: LinkerOptions) {
|
||||
return [
|
||||
...optMultiFlag("-L", options.searchDirs),
|
||||
...optMultiFlag("-l", options.libraries),
|
||||
]
|
||||
}
|
||||
|
||||
export interface PreprocessorOptions {
|
||||
includeDirs?: string[];
|
||||
}
|
||||
|
||||
export function preprocessorCommand(options: PreprocessorOptions) {
|
||||
return [
|
||||
...optMultiFlag("-I", options.includeDirs),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CLI options used for llvm-extract executable.
|
||||
*/
|
||||
export interface ExtractOptions {
|
||||
/**
|
||||
* Functions to extract.
|
||||
*/
|
||||
func?: string[];
|
||||
|
||||
/**
|
||||
* Basic block specifiers.
|
||||
*/
|
||||
bb?: string[];
|
||||
|
||||
output?: string;
|
||||
|
||||
/**
|
||||
* Input file name. If unspecified, llvm-extract reads from stdin
|
||||
*/
|
||||
input?: string;
|
||||
|
||||
asm?: boolean;
|
||||
}
|
||||
|
||||
export function extractCommand(options: ExtractOptions): string[] {
|
||||
return [
|
||||
...optMultiFlag("--func", options.func),
|
||||
...optMultiFlag("--bb", options.bb),
|
||||
...optFlag("-o", options.output),
|
||||
...optSwitch("-S", options.asm),
|
||||
...undefList(options.input, input => [input])
|
||||
];
|
||||
}
|
||||
71
src/commands/spec.ts
Normal file
71
src/commands/spec.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { optFlag, undefList } from "./common"
|
||||
|
||||
export interface RunCPUOptions {
|
||||
/**
|
||||
* Config file, used for compiling flags, compiler versions, etc.
|
||||
*/
|
||||
config?: string
|
||||
|
||||
/**
|
||||
* SPEC workload scale for each benchmark
|
||||
*/
|
||||
workload?: "test" | "train" | "ref"
|
||||
|
||||
/**
|
||||
* Selected benchmarks
|
||||
*/
|
||||
benchmarks?: string[]
|
||||
|
||||
buildType?: "nobuild" | "rebuild" | "plain",
|
||||
|
||||
/**
|
||||
* Default: HTML and text
|
||||
* Meaning: Desired report format.
|
||||
* An output format may be deselected by prepending any of the names with the word "no".
|
||||
* If more than one option is used, separate them by commas or colons.
|
||||
* The values are not case-sensitive.
|
||||
*/
|
||||
outputFormat?: ("all"
|
||||
/** config file used for this run, written as a numbered file in the result directory, for example */
|
||||
| "config"
|
||||
/** Reportable syntax check */
|
||||
| "check"
|
||||
/**
|
||||
* Comma-separated variable.
|
||||
* If you populate spreadsheets from your runs,
|
||||
* you probably should not cut/paste data from text files;
|
||||
* you'll get more accurate data by using --output_format csv.
|
||||
* The csv report includes all runs, more decimal places,
|
||||
* system information, and even the compiler flags.
|
||||
*/
|
||||
| "csv"
|
||||
| "default"
|
||||
| "flags"
|
||||
| "html"
|
||||
| "mail"
|
||||
| "pdf"
|
||||
| "postscript"
|
||||
| "raw"
|
||||
| "screen"
|
||||
/** Plain ASCII text file */
|
||||
| "text")[];
|
||||
}
|
||||
|
||||
export function runcpuOptions(o: RunCPUOptions): string[] {
|
||||
return [
|
||||
...optFlag("-c", o.config),
|
||||
...optFlag("-i", o.workload),
|
||||
...undefList(o.buildType, opt => {
|
||||
switch (opt) {
|
||||
case "nobuild":
|
||||
return ["--nobuild"]
|
||||
case "rebuild":
|
||||
return ["--rebuild"]
|
||||
case "plain":
|
||||
return []
|
||||
}
|
||||
}),
|
||||
...undefList(o.benchmarks, bench => bench),
|
||||
...undefList(o.outputFormat, of => ["--output_format", of.join(",")]),
|
||||
]
|
||||
}
|
||||
31
src/commands/systemd.ts
Normal file
31
src/commands/systemd.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { optFlag, optSwitch } from "./common";
|
||||
|
||||
export interface SystemdRunOptions {
|
||||
/**
|
||||
* Create a transient .scope unit instead of the default transient .service unit (see above).
|
||||
*
|
||||
* @since 206
|
||||
*/
|
||||
scope?: boolean;
|
||||
|
||||
/**
|
||||
* Use this unit name instead of an automatically generated one.
|
||||
*
|
||||
* @since 206
|
||||
*/
|
||||
unit?: string;
|
||||
|
||||
/**
|
||||
* Talk to the service manager of the calling user, rather than the service manager of the system.
|
||||
*/
|
||||
user?: boolean;
|
||||
}
|
||||
|
||||
|
||||
export function systemdRunOptions(o: SystemdRunOptions): string[] {
|
||||
return [
|
||||
...optSwitch("--scope", o.scope),
|
||||
...optFlag("--unit", o.unit),
|
||||
...optSwitch("--user", o.user),
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user