Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate for most types #175

Merged
merged 17 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion abaplint-downport.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"dependencies": [
{
"url": "https://github.com/open-abap/open-abap",
"url": "https://github.com/open-abap/open-abap-core",
"files": "/src/**/*.*"
}
],
Expand Down
2 changes: 1 addition & 1 deletion abaplint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": [
{
"url": "https://github.com/open-abap/open-abap",
"url": "https://github.com/open-abap/open-abap-core",
"folder": "/open-abap",
"files": "/src/**/*.*"
},
Expand Down
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
"description": "test",
"scripts": {
"lint": "abaplint",
"unit": "rm -rf output && abap_transpile test/abap_transpile.json && echo RUNNING && node output/index.mjs",
"build": "rm -rf output && abap_transpile test/abap_transpile.json",
"unit": "npm run build && echo RUNNING && node output/index.mjs",
"test": "npm run lint && npm run downport && npm run unit",
"downport": "rm -rf downport && cp -r src downport && cp deps/* downport && rm downport/*.prog.* && rm downport/zcl_aff_writer_xslt.clas.testclasses.abap && abaplint --fix abaplint-downport.jsonc",
"merge": "rm -f src/z_generate_json_schema.prog.abap && abapmerge -f src/z_generate_repo.prog.abap -c saff_generate_repo > saff_generate_repo.prog.abap",
"aff": "npm test && rm -rf abap-file-formats && git clone https://github.com/SAP/abap-file-formats && cp abap-file-formats/file-formats/*.abap downport && cp abap-file-formats/file-formats/*/type/*.abap downport && cp test/cl_run.clas.abap downport && abap_transpile test/abap_transpile.json && node test/aff.mjs",
"aff": "npm run downport && rm -rf abap-file-formats && git clone https://github.com/SAP/abap-file-formats && cp abap-file-formats/file-formats/*.abap downport && cp abap-file-formats/file-formats/*/type/*.abap downport && cp test/cl_run.clas.abap downport && abap_transpile test/abap_transpile.json && node test/aff.mjs",
"cutUnitTests": "sed -i '/CLASS\\ ltc_generator\\ I/,/ENDCLASS./d' saff_generate_repo.prog.abap && sed -i '/CLASS\\ ltc_generator\\ D/,/ENDCLASS./d' saff_generate_repo.prog.abap"
},
"license": "MIT",
"dependencies": {
"@abaplint/cli": "^2.93.33",
"@abaplint/runtime": "^2.1.88",
"@abaplint/database-sqlite": "^2.1.74",
"@abaplint/transpiler-cli": "^2.1.88",
"abapmerge": "^0.14.7"
"@abaplint/cli": "^2.93.65",
"@abaplint/runtime": "^2.3.30",
"@abaplint/database-sqlite": "^2.3.21",
"@abaplint/transpiler-cli": "^2.3.30",
"abapmerge": "^0.14.8"
}
}
2 changes: 1 addition & 1 deletion test/abap_transpile.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"output_folder": "output",
"libs": [
{
"url": "https://github.com/open-abap/open-abap"
"url": "https://github.com/open-abap/open-abap-core"
}
],
"write_unit_tests": true,
Expand Down
37 changes: 32 additions & 5 deletions test/aff.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as child_process from 'node:child_process';
import {initializeABAP} from "../output/init.mjs";
await initializeABAP();

async function run() {
const result = await abap.Classes["CL_RUN"].run();
if (fs.existsSync("generated") === false) {
fs.mkdirSync("generated");
}
for (const row of result.array()) {
fs.writeFileSync("generated" + path.sep + row.get().filename.get(), row.get().contents.get());

const types = [];
for (const f of fs.readdirSync("abap-file-formats/file-formats/")) {
if (f.length === 4) {
types.push(f.toUpperCase());
}
}

for (const type of types) {
console.log(type);
if (type === "ENHO") {
console.log("\tskip, https://github.com/SAP/abap-file-formats/issues/409");
continue;
}

const result = await abap.Classes["CL_RUN"].run({object_type: new abap.types.String().set(type)});
const filename = "generated" + path.sep + type.toLowerCase() + "-v1.json";
fs.writeFileSync(filename, result.get());

const command = `diff --strip-trailing-cr generated/${type.toLowerCase()}-v1.json abap-file-formats/file-formats/${type.toLowerCase()}/${type.toLowerCase()}-v1.json`;
console.log(command);
const output = child_process.execSync(`${command} || true`);
console.log(output.toString());
}

// only run for INTF,
/*
const result = await abap.Classes["CL_RUN"].run({object_type: new abap.types.String().set("INTF")});
fs.writeFileSync("generated" + path.sep + "intf-v1.json", result.get());
*/
}

run();
39 changes: 16 additions & 23 deletions test/cl_run.clas.abap
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
CLASS cl_run DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES: BEGIN OF ty_row,
filename TYPE string,
contents TYPE string,
END OF ty_row.
TYPES ty_tab TYPE STANDARD TABLE OF ty_row WITH DEFAULT KEY.
CLASS-METHODS run
RETURNING
VALUE(tab) TYPE ty_tab.
PRIVATE SECTION.
CLASS-METHODS run_intf
IMPORTING
object_type TYPE string
RETURNING
VALUE(result) TYPE string.
ENDCLASS.

CLASS cl_run IMPLEMENTATION.
METHOD run_intf.

METHOD run.
DATA writer TYPE REF TO zcl_aff_writer_json_schema.
DATA generator TYPE REF TO zcl_aff_generator.
DATA intf TYPE zif_aff_intf_v1=>ty_main.
DATA string_tab TYPE string_table.
DATA type_name TYPE string.
DATA schema_id TYPE string.
DATA ref TYPE REF TO data.

schema_id = |https://github.com/SAP/abap-file-formats/blob/main/file-formats/{ to_lower( object_type ) }/{ to_lower( object_type ) }-v1.json|.
type_name = to_upper( |ZIF_AFF_{ object_type }_V1=>TY_MAIN| ).

CREATE DATA ref TYPE (type_name).

CREATE OBJECT writer
EXPORTING
schema_id = 'https://github.com/SAP/abap-file-formats/blob/main/file-formats/intf/intf-v1.json'.
schema_id = schema_id.

CREATE OBJECT generator
EXPORTING
writer = writer.
string_tab = generator->generate_type( intf ).

string_tab = generator->generate_type( ref->* ).
CONCATENATE LINES OF string_tab INTO result SEPARATED BY |\n|.
ENDMETHOD.

METHOD run.
DATA str TYPE string.
DATA row LIKE LINE OF tab.

str = run_intf( ).

row-filename = 'intf.json'.
row-contents = str.
APPEND row TO tab.
ENDMETHOD.
ENDCLASS.