Skip to content

Commit

Permalink
VHDL format plugin base
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldolsribeiro authored Sep 27, 2024
1 parent e029263 commit 6f3e47e
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 9 deletions.
1 change: 1 addition & 0 deletions dockerfiles/ghdl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ all08.vhdl:

ams08.vhdl:
wget https://raw.githubusercontent.com/ghdl/ghdl/refs/heads/master/testsuite/sanity/004all08/ams08.vhdl

101 changes: 101 additions & 0 deletions include/VHDLFormatPluginStepParser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// MIT License
//
// Copyright (C) 2022-2024 Geraldo Luis da Silva Ribeiro
//
// ░░░░░░░░░░░░░░░░░
// ░░░░░░░█▀▀░▀█▀░░░
// ░░░█░█░█░░░░█░░░░
// ░░░█▀▀░▀▀▀░▀▀▀░░░
// ░░░▀░░░░░░░░░░░░░
// ░░░░░░░░░░░░░░░░░
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#include <spdlog/spdlog.h>

#include <VHDLFormatPluginStepParser.hpp>
#include <fstream>

namespace microci {
using namespace std;

// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
void VHDLFormatPluginStepParser::Parse(const YAML::Node &step) {
auto data = mMicroCI->DefaultDataTemplate();

auto volumes = parseVolumes(step);
auto envs = parseEnvs(step);
data = parseRunAs(step, data, "user");
data = parseNetwork(step, data, "none");
tie(data, volumes, envs) = parseSsh(step, data, volumes, envs);

data["STEP_NAME"] = stepName(step);
data["STEP_DESCRIPTION"] =
stepDescription(step, "Process source code to make readable or match to a project code style");
data["FUNCTION_NAME"] = sanitizeName(stepName(step));
data["DOCKER_IMAGE"] = stepDockerImage(step, "intmain/microci_ghdl:latest");

auto emacsConfigFilename = inja::render( "{{ WORKSPACE }}/emacs_vhdl_formatter.lisp", data);
ofstream emacsConfig(emacsConfigFilename);
emacsConfig << inja::render(R"(
(custom-set-variables
'(vhdl-align-group-separate "^\\s---*$")
'(vhdl-align-groups t)
'(vhdl-align-same-indent t)
'(vhdl-auto-align t)
'(vhdl-basic-offset 2)
'(vhdl-beautify-options '(t ;; whitespace cleanup
t ;; single statement per line
t ;; indentation
t ;; aligment
t)) ;; case fixing
;; '(vhdl-standard '(8 nil))
'(vhdl-standard '(8 (ams math))) ;; VHDL-08
'(vhdl-array-index-record-field-in-sensitivity-list t)
'(vhdl-upper-case-attributes t)
'(vhdl-upper-case-constants t)
'(vhdl-upper-case-enum-values t)
'(vhdl-upper-case-keywords t)
'(vhdl-upper-case-types t)
'(vhdl-use-direct-instantiation 'always)
)
)",
data);
emacsConfig.close();

beginFunction(data, envs);
prepareRunDocker(data, envs, volumes);

mMicroCI->Script() << inja::render(R"( \
bash -c "cd {{ WORKSPACE }})", data);

copySshIfAvailable(step, data);

mMicroCI->Script() << inja::render(R"( \
&& emacs -batch -l {{ WORKSPACE }}/emacs_vhdl_formatter.lisp \
../hdl/**/*.vhd \
-f vhdl-beautify-buffer)", data );

mMicroCI->Script() << "\"\n";
endFunction(data);
}
} // namespace microci

69 changes: 69 additions & 0 deletions include/new/vhdl-format.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// MIT License
//
// Copyright (c) 2022-2024 Geraldo Luis da Silva Ribeiro
//
// ░░░░░░░░░░░░░░░░░
// ░░░░░░░█▀▀░▀█▀░░░
// ░░░█░█░█░░░░█░░░░
// ░░░█▀▀░▀▀▀░▀▀▀░░░
// ░░░▀░░░░░░░░░░░░░
// ░░░░░░░░░░░░░░░░░
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

// DON'T EDIT THIS FILE, INSTEAD UPDATE ../new/vhdl-format.yml
unsigned char ___new_vhdl_format_yml[] = {
0x23, 0x20, 0x20, 0x20, 0x23, 0x20, 0x76, 0x68, 0x64, 0x6c, 0x2d, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20,
0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e,

0x0a, 0x23, 0x20, 0x20, 0x20,

0x0a, 0x23, 0x7b, 0x7b, 0x7b,

0x0a, 0x73, 0x74, 0x65, 0x70, 0x73, 0x3a,

0x0a, 0x20, 0x20, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x22, 0x56, 0x48, 0x44, 0x4c, 0x20, 0x73,
0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x74,
0x65, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x62, 0x65, 0x61, 0x75, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20,
0x22, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x63, 0x6f,
0x64, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x72, 0x65, 0x61, 0x64, 0x61, 0x62, 0x6c,
0x65, 0x20, 0x6f, 0x72, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x20, 0x70, 0x72,
0x6f, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x75, 0x6e, 0x5f, 0x61, 0x73, 0x3a, 0x20, 0x75, 0x73, 0x65, 0x72,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x22, 0x76, 0x68, 0x64, 0x6c,
0x2d, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x73, 0x72, 0x63, 0x2f, 0x2a, 0x2e,
0x76, 0x68, 0x64, 0x22,

0x0a, 0x23, 0x7d, 0x7d, 0x7d,

0x0a, 0x23, 0x20, 0x76, 0x69, 0x6d, 0x3a, 0x20, 0x73, 0x70, 0x65, 0x6c, 0x6c, 0x20, 0x73, 0x70, 0x65, 0x6c,
0x6c, 0x6c, 0x61, 0x6e, 0x67, 0x3d, 0x65, 0x6e,

0x0a};
unsigned int ___new_vhdl_format_yml_len = 307;
13 changes: 13 additions & 0 deletions new/vhdl-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# # vhdl-format plugin
#
#{{{
steps:
- name: "VHDL source code formatter and beautifier"
description: "Process source code to make readable or match to a project code style"
run_as: user
plugin:
name: "vhdl-format"
source:
- "src/*.vhd"
#}}}
# vim: spell spelllang=en
101 changes: 101 additions & 0 deletions src/VHDLFormatPluginStepParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// MIT License
//
// Copyright (C) 2022-2024 Geraldo Luis da Silva Ribeiro
//
// ░░░░░░░░░░░░░░░░░
// ░░░░░░░█▀▀░▀█▀░░░
// ░░░█░█░█░░░░█░░░░
// ░░░█▀▀░▀▀▀░▀▀▀░░░
// ░░░▀░░░░░░░░░░░░░
// ░░░░░░░░░░░░░░░░░
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#include <spdlog/spdlog.h>

#include <VHDLFormatPluginStepParser.hpp>
#include <fstream>

namespace microci {
using namespace std;

// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
void VHDLFormatPluginStepParser::Parse(const YAML::Node &step) {
auto data = mMicroCI->DefaultDataTemplate();

auto volumes = parseVolumes(step);
auto envs = parseEnvs(step);
data = parseRunAs(step, data, "user");
data = parseNetwork(step, data, "none");
tie(data, volumes, envs) = parseSsh(step, data, volumes, envs);

data["STEP_NAME"] = stepName(step);
data["STEP_DESCRIPTION"] =
stepDescription(step, "Process source code to make readable or match to a project code style");
data["FUNCTION_NAME"] = sanitizeName(stepName(step));
data["DOCKER_IMAGE"] = stepDockerImage(step, "intmain/microci_ghdl:latest");

auto emacsConfigFilename = inja::render( "{{ WORKSPACE }}/emacs_vhdl_formatter.lisp", data);
ofstream emacsConfig(emacsConfigFilename);
emacsConfig << inja::render(R"(
(custom-set-variables
'(vhdl-align-group-separate "^\\s---*$")
'(vhdl-align-groups t)
'(vhdl-align-same-indent t)
'(vhdl-auto-align t)
'(vhdl-basic-offset 2)
'(vhdl-beautify-options '(t ;; whitespace cleanup
t ;; single statement per line
t ;; indentation
t ;; aligment
t)) ;; case fixing
;; '(vhdl-standard '(8 nil))
'(vhdl-standard '(8 (ams math))) ;; VHDL-08
'(vhdl-array-index-record-field-in-sensitivity-list t)
'(vhdl-upper-case-attributes t)
'(vhdl-upper-case-constants t)
'(vhdl-upper-case-enum-values t)
'(vhdl-upper-case-keywords t)
'(vhdl-upper-case-types t)
'(vhdl-use-direct-instantiation 'always)
)
)",
data);
emacsConfig.close();

beginFunction(data, envs);
prepareRunDocker(data, envs, volumes);

mMicroCI->Script() << inja::render(R"( \
bash -c "cd {{ WORKSPACE }})", data);

copySshIfAvailable(step, data);

mMicroCI->Script() << inja::render(R"( \
&& emacs -batch -l {{ WORKSPACE }}/emacs_vhdl_formatter.lisp \
../hdl/**/*.vhd \
-f vhdl-beautify-buffer)", data );

mMicroCI->Script() << "\"\n";
endFunction(data);
}
} // namespace microci

23 changes: 14 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ using namespace std;
#include "PlantumlPluginStepParser.hpp"
#include "PluginStepParser.hpp"
#include "TemplatePluginStepParser.hpp"
#include "VHDLFormatPluginStepParser.hpp"

// Configuration templates
#include "new/bash.hpp"
Expand All @@ -91,6 +92,7 @@ using namespace std;
#include "new/plantuml.hpp"
#include "new/skip.hpp"
#include "new/template.hpp"
#include "new/vhdl-format.hpp"

// main class
#include "MicroCI.hpp"
Expand Down Expand Up @@ -124,6 +126,7 @@ auto help() -> string {
-n,--new plantuml Create a diagram generation step
-n,--new pikchr Create a diagram generation step
-n,--new clang-format Create a code format step
-n,--new vhdl-format Create a code format step
-n,--new beamer Create a PDF presentation step
-n,--new fetch Create a download external artfact step
-n,--new minio Create a upload/download internal artifact step
Expand Down Expand Up @@ -329,15 +332,15 @@ void loadGitlabEnvironmentVariables(MicroCI &uCI, char **envp) {
// same as the environment of the executor.
"CI_RUNNER_ID", // Job-only The unique ID of the runner being used.
"CI_RUNNER_REVISION", // Job-only The revision of the runner running the job.
"CI_RUNNER_SHORT_TOKEN", // Job-only The runner’s unique ID, used to authenticate new job requests. The token
// contains a prefix, and the first 17 characters are used.
"CI_RUNNER_TAGS", // Job-only A comma-separated list of the runner tags.
"CI_RUNNER_VERSION", // Job-only The version of the GitLab Runner running the job.
"CI_SERVER_FQDN", // Pipeline The fully qualified domain name (FQDN) of the instance. For example
// gitlab.example.com:8080. Introduced in GitLab 16.10.
"CI_SERVER_HOST", // Pipeline The host of the GitLab instance URL, without protocol or port. For example
// gitlab.example.com.
"CI_SERVER_NAME", // Pipeline The name of CI/CD server that coordinates jobs.
"CI_RUNNER_SHORT_TOKEN", // Job-only The runner’s unique ID, used to authenticate new job requests. The token
// contains a prefix, and the first 17 characters are used.
"CI_RUNNER_TAGS", // Job-only A comma-separated list of the runner tags.
"CI_RUNNER_VERSION", // Job-only The version of the GitLab Runner running the job.
"CI_SERVER_FQDN", // Pipeline The fully qualified domain name (FQDN) of the instance. For example
// gitlab.example.com:8080. Introduced in GitLab 16.10.
"CI_SERVER_HOST", // Pipeline The host of the GitLab instance URL, without protocol or port. For example
// gitlab.example.com.
"CI_SERVER_NAME", // Pipeline The name of CI/CD server that coordinates jobs.
"CI_SERVER_PORT", // Pipeline The port of the GitLab instance URL, without host or protocol. For example 8080.
"CI_SERVER_PROTOCOL", // Pipeline The protocol of the GitLab instance URL, without host or port. For example
// https.
Expand Down Expand Up @@ -444,6 +447,7 @@ auto main([[maybe_unused]] int argc, char **argv, char **envp) -> int {
uCI.RegisterPlugin("cppcheck", make_shared<CppCheckPluginStepParser>(&uCI));
uCI.RegisterPlugin("clang-tidy", make_shared<ClangTidyPluginStepParser>(&uCI));
uCI.RegisterPlugin("clang-format", make_shared<ClangFormatPluginStepParser>(&uCI));
uCI.RegisterPlugin("vhdl-format", make_shared<VHDLFormatPluginStepParser>(&uCI));
uCI.RegisterPlugin("fetch", make_shared<FetchPluginStepParser>(&uCI));
uCI.RegisterPlugin("minio", make_shared<MinioPluginStepParser>(&uCI));
uCI.RegisterPlugin("flawfinder", make_shared<FlawfinderPluginStepParser>(&uCI));
Expand Down Expand Up @@ -549,6 +553,7 @@ auto main([[maybe_unused]] int argc, char **argv, char **envp) -> int {
MICROCI_TPL(true, "npm", ".microCI.yml", yml, npm);
MICROCI_TPL(true, "plantuml", ".microCI.yml", yml, plantuml);
MICROCI_TPL(true, "pikchr", ".microCI.yml", yml, pikchr);
MICROCI_TPL(true, "vhdl-format", ".microCI.yml", yml, vhdl_format);
MICROCI_TPL(true, "clang-format", ".microCI.yml", yml, clang_format);
MICROCI_TPL(false, "clang-format", ".clang-format", yml, clang_format_config);
MICROCI_TPL(true, "beamer", ".microCI.yml", yml, beamer);
Expand Down

0 comments on commit 6f3e47e

Please sign in to comment.