1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-03 07:24:58 +03:00
inform7/inbuild/supervisor-module/Chapter 3/Inter Skill.w

184 lines
6.5 KiB
OpenEdge ABL
Raw Normal View History

2020-02-24 01:49:56 +02:00
[InterSkill::] Inter Skill.
2021-11-23 01:40:18 +02:00
The skills of kit building and of code generation from Inter.
2020-02-24 01:49:56 +02:00
2020-03-30 14:23:06 +03:00
@h Creation.
Note that code generation can only be done internally, and only in fact within
the |inform7| compiler: this is because the Inter code which it generates from
is being held in memory by |inform7|.
=
2021-11-23 01:40:18 +02:00
build_skill *build_kit_using_inter_skill = NULL;
2020-02-24 11:48:40 +02:00
build_skill *code_generate_using_inter_skill = NULL;
2020-02-24 01:49:56 +02:00
void InterSkill::create(void) {
2021-11-23 01:40:18 +02:00
build_kit_using_inter_skill =
BuildSteps::new_skill(I"build kit using inter");
METHOD_ADD(build_kit_using_inter_skill, BUILD_SKILL_COMMAND_MTID,
InterSkill::build_kit_via_shell);
METHOD_ADD(build_kit_using_inter_skill, BUILD_SKILL_INTERNAL_MTID,
InterSkill::build_kit_internally);
2020-03-30 14:23:06 +03:00
code_generate_using_inter_skill =
BuildSteps::new_skill(I"code generate using inter");
METHOD_ADD(code_generate_using_inter_skill, BUILD_SKILL_INTERNAL_MTID,
InterSkill::code_generate_internally);
2020-02-24 01:49:56 +02:00
}
2020-03-30 14:23:06 +03:00
@h Assimilation.
=
2021-11-23 01:40:18 +02:00
int InterSkill::build_kit_via_shell(build_skill *skill, build_step *S,
text_stream *command, build_methodology *BM, linked_list *search_list) {
2020-02-24 01:49:56 +02:00
inter_architecture *A = S->for_arch;
if (A == NULL) internal_error("no architecture given");
pathname *kit_path = S->associated_copy->location_if_path;
2020-03-30 14:23:06 +03:00
Shell::quote_file(command, BM->to_inter);
2020-02-24 01:49:56 +02:00
WRITE_TO(command, "-architecture %S ", Architectures::to_codename(A));
2021-11-23 01:40:18 +02:00
WRITE_TO(command, "-build-kit ");
2020-02-24 01:49:56 +02:00
Shell::quote_path(command, kit_path);
return TRUE;
}
2020-03-30 14:23:06 +03:00
@ Something to watch out for here is that, when running internally as part of
2021-11-23 01:40:18 +02:00
|inform7|, we use the copy of the |build-kit| pipeline inside the installation
of |inform7| (it will be in the internal nest). When we build kits from the
command line using the |inter| tool, we use the |build-kit| pipeline supplied
in the |inter| installation. But those two files are in fact the same, or
should be, so the effect is the same.
2020-03-30 14:23:06 +03:00
=
2022-06-27 00:38:07 +03:00
int echo_kit_building = FALSE;
void InterSkill::echo_kit_building(void) {
echo_kit_building = TRUE;
}
2021-11-23 01:40:18 +02:00
int InterSkill::build_kit_internally(build_skill *skill, build_step *S,
build_methodology *BM, linked_list *search_list) {
#ifdef PIPELINE_MODULE
2020-02-24 01:49:56 +02:00
inter_architecture *A = S->for_arch;
if (A == NULL) internal_error("no architecture given");
pathname *kit_path = S->associated_copy->location_if_path;
2021-11-13 15:29:56 +02:00
dictionary *pipeline_vars = ParsingPipelines::basic_dictionary(NULL);
2021-11-23 01:40:18 +02:00
filename *pipeline_as_file =
InterSkill::filename_of_pipeline(I"build-kit", search_list);
2021-11-22 02:22:16 +02:00
if (pipeline_as_file == NULL) {
2021-11-23 01:40:18 +02:00
Errors::nowhere("build-kit pipeline could not be found");
2020-02-24 01:49:56 +02:00
return FALSE;
}
2021-11-22 02:22:16 +02:00
2020-02-24 01:49:56 +02:00
filename *assim = Architectures::canonical_binary(kit_path, A);
filename *assim_t = Architectures::canonical_textual(kit_path, A);
2020-06-28 01:18:54 +03:00
TEMPORARY_TEXT(fullname)
2020-02-24 01:49:56 +02:00
WRITE_TO(fullname, "%f", assim);
Str::copy(Dictionaries::create_text(pipeline_vars, I"*out"), fullname);
Str::clear(fullname);
WRITE_TO(fullname, "%f", assim_t);
Str::copy(Dictionaries::create_text(pipeline_vars, I"*outt"), fullname);
2020-06-28 01:18:54 +03:00
DISCARD_TEXT(fullname)
2020-03-30 14:23:06 +03:00
Str::copy(Dictionaries::create_text(pipeline_vars, I"*kit"),
Pathnames::directory_name(kit_path));
2020-02-24 01:49:56 +02:00
2021-11-13 15:29:56 +02:00
inter_pipeline *SS =
2021-11-22 02:22:16 +02:00
ParsingPipelines::from_file(pipeline_as_file, pipeline_vars, search_list);
2020-02-24 01:49:56 +02:00
if (SS) {
2022-04-05 14:14:27 +03:00
inter_architecture *saved_A = PipelineModule::get_architecture();
PipelineModule::set_architecture_to(A);
2022-06-27 00:38:07 +03:00
if (echo_kit_building)
WRITE_TO(STDOUT, "(Building %S for architecture %S)\n",
S->associated_copy->edition->work->title,
Architectures::to_codename(A));
2021-11-16 00:44:29 +02:00
linked_list *requirements_list = NEW_LINKED_LIST(attachment_instruction);
2021-11-29 01:34:30 +02:00
RunningPipelines::run(NULL, SS, NULL, S->associated_copy->location_if_path,
requirements_list, S->for_vm, FALSE);
2022-04-05 14:14:27 +03:00
PipelineModule::set_architecture_to(saved_A);
2020-02-24 01:49:56 +02:00
return TRUE;
} else {
2021-11-23 01:40:18 +02:00
Errors::nowhere("build-kit pipeline could not be parsed");
2020-02-24 01:49:56 +02:00
return FALSE;
}
#endif
return FALSE;
}
2020-02-24 11:48:40 +02:00
2021-11-22 02:22:16 +02:00
filename *InterSkill::filename_of_pipeline(text_stream *name, linked_list *search_list) {
inbuild_requirement *req =
Requirements::any_version_of(
Works::new(pipeline_genre, name, NULL));
inbuild_search_result *R = Nests::search_for_best(req, search_list);
if (R == NULL) return NULL;
return R->copy->location_if_file;
}
2020-03-30 14:23:06 +03:00
@h Code generation.
This can only be done internally, for reasons given above, and only when the
//pipeline// module is present in the current executable (which in practice means:
only inside //inform7//).
2020-03-30 14:23:06 +03:00
Recall that the |inter_pipeline_name| is managed in Inbuild Control, but that
it defaults to |compile|.
=
inform_project *interskill_associated_project = NULL;
int interskill_debugging_flag = FALSE;
2020-03-30 14:23:06 +03:00
int InterSkill::code_generate_internally(build_skill *skill, build_step *S,
build_methodology *BM, linked_list *search_list) {
inform_project *project = ProjectBundleManager::from_copy(S->associated_copy);
if (project == NULL) project = ProjectFileManager::from_copy(S->associated_copy);
if (project == NULL) internal_error("no project");
#ifdef PIPELINE_MODULE
clock_t back_end = clock();
interskill_associated_project = project;
2021-11-15 01:40:33 +02:00
PipelineModule::set_architecture(
Architectures::to_codename(
TargetVMs::get_architecture(S->for_vm)));
Str::copy(Dictionaries::create_text(pipeline_vars, I"*in"), I"*memory");
Str::copy(Dictionaries::create_text(pipeline_vars, I"*out"),
2020-03-30 14:23:06 +03:00
Filenames::get_leafname(S->vertex->as_file));
if (interskill_debugging_flag)
Str::copy(Dictionaries::create_text(pipeline_vars, I"*tout"), I"*log");
filename *F = inter_pipeline_file;
if (F == NULL) {
inbuild_requirement *req =
2020-03-30 14:23:06 +03:00
Requirements::any_version_of(
Works::new(pipeline_genre, inter_pipeline_name, NULL));
inbuild_search_result *R = Nests::search_for_best(req, search_list);
if (R == NULL) {
2020-03-30 14:23:06 +03:00
Errors::with_text("inter pipeline '%S' could not be found",
inter_pipeline_name);
return FALSE;
}
F = R->copy->location_if_file;
}
2021-11-22 02:22:16 +02:00
inter_pipeline *pipeline = ParsingPipelines::from_file(F, pipeline_vars, search_list);
2021-11-13 15:29:56 +02:00
if (pipeline == NULL) {
Errors::nowhere("inter pipeline file could not be parsed");
return FALSE;
}
2021-11-29 01:34:30 +02:00
RunningPipelines::run(Filenames::up(S->vertex->as_file), pipeline, Emit::tree(), NULL,
Projects::list_of_attachment_instructions(project), S->for_vm, FALSE);
2020-03-30 14:23:06 +03:00
LOG("Back end elapsed time: %dcs\n",
2022-04-30 17:46:06 +03:00
((int) (clock() - back_end)) / ((int) (CLOCKS_PER_SEC/100)));
2021-04-19 00:42:39 +03:00
#ifdef CORE_MODULE
Hierarchy::log();
return TRUE;
2020-02-24 11:48:40 +02:00
#endif
2021-04-19 00:42:39 +03:00
#endif
#ifndef CORE_MODULE
2020-02-24 11:48:40 +02:00
return FALSE;
#endif
interskill_associated_project = NULL;
}
inform_project *InterSkill::get_associated_project(void) {
return interskill_associated_project;
2020-02-24 11:48:40 +02:00
}
void InterSkill::set_debugging(void) {
interskill_debugging_flag = TRUE;
}