Skip to content

Commit

Permalink
Add uppercase option to VHDL format plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldolsribeiro authored Sep 30, 2024
1 parent 6f3e47e commit b26c752
Show file tree
Hide file tree
Showing 6 changed files with 466 additions and 102 deletions.
75 changes: 10 additions & 65 deletions include/VHDLFormatPluginStepParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,75 +27,20 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#include <spdlog/spdlog.h>
#ifndef VHDL_FORMAT_PLUGIN_STEP_PARSER_HPP
#define VHDL_FORMAT_PLUGIN_STEP_PARSER_HPP

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

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 );
class VHDLFormatPluginStepParser : public PluginStepParser {
public:
VHDLFormatPluginStepParser(MicroCI *microCI) : PluginStepParser(microCI) {}
virtual ~VHDLFormatPluginStepParser() {}
virtual void Parse(const YAML::Node &step) override;
};

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

#endif
15 changes: 12 additions & 3 deletions include/new/vhdl-format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,24 @@ unsigned char ___new_vhdl_format_yml[] = {
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, 0x75, 0x70, 0x70, 0x65, 0x72, 0x63, 0x61, 0x73, 0x65, 0x3a, 0x20,
0x74, 0x72, 0x75, 0x65,

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, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x73, 0x72, 0x63, 0x2f, 0x61, 0x2a,
0x2e, 0x76, 0x68, 0x64, 0x22,

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

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x73, 0x72, 0x63, 0x2f, 0x63, 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;
unsigned int ___new_vhdl_format_yml_len = 376;
5 changes: 4 additions & 1 deletion new/vhdl-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ steps:
run_as: user
plugin:
name: "vhdl-format"
uppercase: true
source:
- "src/*.vhd"
- "src/a*.vhd"
- "src/b*.vhd"
- "src/c*.vhd"
#}}}
# vim: spell spelllang=en
99 changes: 66 additions & 33 deletions src/VHDLFormatPluginStepParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,62 +40,95 @@ 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);
list<string> sourceList;

if (step["plugin"]["source"] && step["plugin"]["source"].IsSequence()) {
for (const auto &src : step["plugin"]["source"]) {
sourceList.push_back(src.as<string>());
}
}

auto upperCaseOption{false};
if (step["plugin"]["uppercase"]) {
upperCaseOption = step["plugin"]["uppercase"].as<bool>(false);
}

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"(
auto emacsConfigFilename = inja::render("{{ WORKSPACE }}/.emacs_vhdl_formatter.lisp", data);
data["EMACS_VHDL_FORMATTER_FILENAME"] = emacsConfigFilename;

ostringstream emacsConfig;
emacsConfig << inja::render(R"(;; microCI emacs configuration used for formatting VHDL code
(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)
)
)",
;; '(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-use-direct-instantiation 'always)
)",
data);
emacsConfig.close();

if (upperCaseOption) {
emacsConfig << inja::render(R"(
'(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)
)",
data);
}

emacsConfig << R"(
))";

data["EMACS_VHDL_FORMATTER_CONFIG"] = emacsConfig.str();

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

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

copySshIfAvailable(step, data);
bash -c "cd {{ WORKSPACE }}
cat <<EOF > {{ EMACS_VHDL_FORMATTER_FILENAME }}
{{ EMACS_VHDL_FORMATTER_CONFIG }}
EOF
echo "Formatting...")",
data);

for (const auto &src : sourceList) {
mMicroCI->Script() << fmt::format(R"( \
&& cat <(compgen -G '{}') \
| )",
src);
mMicroCI->Script() << inja::render(R"(xargs --no-run-if-empty -I {} emacs -batch \
-l {{ EMACS_VHDL_FORMATTER_FILENAME }} \
{} -f vhdl-beautify-buffer 2>&1 )",
data);
}
mMicroCI->Script() << inja::render(R"( \
&& emacs -batch -l {{ WORKSPACE }}/emacs_vhdl_formatter.lisp \
../hdl/**/*.vhd \
-f vhdl-beautify-buffer)", data );
&& rm -f {{ EMACS_VHDL_FORMATTER_FILENAME }})",
data);

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

1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ test:
../bin/microCI -i ../new/mkdocs_material.yml > mkdocs_material.sh
../bin/microCI -i ../new/mkdocs_material.yml -O "local-step" > mkdocs_material_only.sh
../bin/microCI -i ../new/cppcheck.yml > cppcheck.sh
../bin/microCI -i ../new/vhdl-format.yml > vhdl-format.sh
../bin/microCI -i ../new/clang-tidy.yml > clang-tidy.sh
../bin/microCI -i ../new/clang-format.yml > clang-format.sh
../bin/microCI -i ../new/plantuml.yml > plantuml.sh
Expand Down
Loading

0 comments on commit b26c752

Please sign in to comment.