Name

SPVM::Builder::CommandInfo - Command Information

Description

SPVM::Builder::CommandInfo class manages command information.

Fields

config

my $config = $command_info->config;
$command_info->config($config);

Gets and sets the config field, a SPVM::Builder::Config object.

output_file

my $output_file = $command_info->output_file;
$command_info->output_file($output_file);

Gets and sets the output_file field, an output file.

command_hash

my $command_hash = $command_info->command_hash;
$command_info->command_hash($command_hash);

Gets and sets the command_hash field, a SHA-1 hash string that uniquely identifies the compilation task.

This hash ensures the consistency of the compilation. It is generated from the following information:

  • The compilation command itself.

  • The Command version.

  • The SPVM version-specific headers.

  • The information of the dependent files.

If any of these change, the hash will change, triggering a re-compilation in the ninja build system.

start_time

my $start_time = $command_info->start_time;
$command_info->start_time($start_time);

Gets and sets the start_time field. It is a Unix timestamp in milliseconds when the command execution started.

end_time

my $end_time = $command_info->end_time;
$command_info->end_time($end_time);

Gets and sets the end_time field. It is a Unix timestamp in milliseconds when the command execution ended.

tmp_dir

my $tmp_dir = $command_info->tmp_dir;
$command_info->tmp_dir($tmp_dir);

Gets and sets the tmp_dir field. It is a directory where the stderr log file and other temporary files of the command are stored.

process_id

my $process_id = $command_info->process_id;
$command_info->process_id($process_id);

Gets and sets the process_id field. It is the process ID of the command.

Instance Methods

create_command

my $command = $command_info->create_command;
my $command_no_output = $command_info->create_command({no_output_option => 1});

Creates an array reference of the command components, and returns it.

If the no_output_option option is a true value, the output option (e.g. -o output_file) is not added to the command.

This method is meant to be implemented in child classes.

create_command_string

my $command_string = $command_info->create_command_string;
my $command_string_no_output = $command_info->create_command_string({no_output_option => 1});

Converts the array reference of the command returned by the "create_command" method into a single string that can be executed in a shell (such as sh or bash) or the Windows Command Prompt (cmd.exe).

If the no_output_option option is a true value, this option is passed to the "create_command" method, and the output option is not included in the returned string.

Each argument is automatically and appropriately quoted only when necessary (e.g., containing spaces or special characters) according to the operating system (OS) to ensure it can be safely executed as a command line.

Return Value Examples:

  • On UNIX/Linux:

    gcc -c -o foo.o -O2 '-std=c99' -Ipath/include foo.c
    
    # With no_output_option => 1
    gcc -c -O2 '-std=c99' -Ipath/include foo.c
  • On Windows:

    gcc -c -o foo.o -O2 -std=c99 -Ipath/include foo.c
    
    # With no_output_option => 1
    gcc -c -O2 -std=c99 -Ipath/include foo.c

Well Knowned Child Classes

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License