Skip to content

Commit ad56e16

Browse files
committed
Release 1.0.1
1 parent 31b7045 commit ad56e16

File tree

14 files changed

+73
-86
lines changed

14 files changed

+73
-86
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ jobs:
6161
- name: Upload to tag
6262
uses: softprops/[email protected]
6363
with:
64-
tag_name: 1.0.0
65-
body: First release, yay!
64+
tag_name: 1.0.1
65+
body: "[Change log](https://github.com/msqr1/importizer/blob/main/ChangeLog.md#101)"
6666
files: ${{ github.workspace }}/importizer*/importizer*

3rdParty/Setup.cmake

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
cmake_minimum_required(VERSION 3.25)
2+
find_package(Git)
3+
if(NOT GIT_FOUND)
4+
message(FATAL_ERROR "Git not found")
5+
endif()
26

37
function(gitClone repo hash outDir)
48
file(MAKE_DIRECTORY ${outDir})
5-
execute_process(
6-
WORKING_DIRECTORY ${outDir}
7-
COMMAND git init
8-
)
9-
execute_process(
10-
WORKING_DIRECTORY ${outDir}
11-
COMMAND git fetch --depth 1 "https://github.com/${repo}" ${hash}
12-
)
13-
execute_process(
14-
WORKING_DIRECTORY ${outDir}
15-
COMMAND git -c advice.detachedHead=false checkout ${hash}
16-
)
17-
execute_process(
18-
WORKING_DIRECTORY ${outDir}
19-
COMMAND git submodule update --init --recursive --depth 1
20-
)
9+
execute_process(WORKING_DIRECTORY ${outDir} COMMAND ${GIT_EXECUTABLE} init)
10+
execute_process(WORKING_DIRECTORY ${outDir} COMMAND ${GIT_EXECUTABLE} fetch --depth 1
11+
"https://github.com/${repo}" ${hash})
12+
execute_process(WORKING_DIRECTORY ${outDir} COMMAND ${GIT_EXECUTABLE} -c advice.detachedHead=false
13+
checkout ${hash})
14+
execute_process(WORKING_DIRECTORY ${outDir} COMMAND ${GIT_EXECUTABLE} submodule update --init
15+
--recursive --depth 1)
2116
endfunction(gitClone repo hash outDir)
2217

23-
# 11.1.2
18+
# 11.1.3
2419
if(NOT EXISTS fmt)
25-
gitClone(fmtlib/fmt 8303d140a1a11f19b982a9f664bbe59a1ccda3f4 fmt)
20+
gitClone(fmtlib/fmt 9cf9f38eded63e5e0fb95cd536ba51be601d7fa2 fmt)
2621
endif()
2722

2823
# 3.4.0
@@ -34,7 +29,6 @@ endif()
3429
if(NOT EXISTS pcre2)
3530
gitClone(PCRE2Project/pcre2 e2985c439b7fa374b4bd3052ca413e29ed1ad590 pcre2)
3631
endif()
37-
3832
if(NOT EXISTS Argparse.hpp)
39-
file(DOWNLOAD https://raw.githubusercontent.com/p-ranav/argparse/refs/tags/v3.1/include/argparse/argparse.hpp Argparse.hpp)
33+
file(DOWNLOAD https://raw.githubusercontent.com/p-ranav/argparse/refs/tags/v3.2/include/argparse/argparse.hpp Argparse.hpp)
4034
endif()

CMakeLists.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ if(CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
66
endif()
77

88
# Setup the 3rdParty folder
9-
execute_process(
10-
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/3rdParty"
11-
COMMAND ${CMAKE_COMMAND} -P Setup.cmake
12-
)
13-
9+
execute_process( WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/3rdParty" COMMAND
10+
"${CMAKE_COMMAND}" -P Setup.cmake COMMAND_ERROR_IS_FATAL ANY)
1411
set(debugCompileFlags)
1512
set(releaseCompileFlags)
1613
set(debugLinkFlags)
@@ -82,4 +79,4 @@ add_subdirectory(src)
8279
option(TESTS "Setup and run tests" OFF)
8380
if(TESTS)
8481
add_subdirectory(test)
85-
endif()
82+
endif()

ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# 1.0.1 (in progress)
1+
# 1.1.0 (in progress)
2+
3+
# 1.0.1
24
- Fix includeGuardPat not matching the entire string to qualify as a guard
35
- Fix CondMinimizer always skipping `#if` instead of only when its skippable
46
- Fix raw string handling because the first `(` is not skipped over
57
- Fix integer literals not being handled properly (I didn't think about them at all LOL)
68
- Fix CondMinimizer not handling nested `#if` (it looks for the earliest `#endif`) when skipping
9+
- Make condition hierarchy shorter by removing conditions for all imports
10+
- Bump libfmt to 11.1.3, PCRE2 to 10.45-RC1, Argparse to 3.2
711

812
# 1.0.0
913
- First release

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target_compile_features(importizer PRIVATE cxx_std_23)
55
# 3rd-party headers rarely changes
66
set(3rdPartyHeaders Argparse.hpp toml++/include/toml++/toml.hpp fmt/include/fmt/format.h
77
fmt/include/fmt/base.h fmt/include/fmt/std.h)
8-
list(TRANSFORM 3rdPartyHeaders PREPEND "../3rdParty/")
8+
list(TRANSFORM 3rdPartyHeaders PREPEND ../3rdParty/)
99

1010
# Project headers that should not be changed frequently
1111
set(stableHeaders Base.hpp Regex.hpp FileOp.hpp)
@@ -30,5 +30,5 @@ target_link_libraries(importizer pcre2-8)
3030

3131
# For actions/upload-artifact
3232
add_custom_command(POST_BUILD TARGET importizer
33-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:importizer>
34-
${CMAKE_BINARY_DIR}/$<TARGET_FILE_NAME:importizer>)
33+
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:importizer>"
34+
"${CMAKE_BINARY_DIR}/$<TARGET_FILE_NAME:importizer>")

src/Main.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <filesystem>
1010

1111
namespace fs = std::filesystem;
12+
namespace {
13+
1214
void run(int argc, const char* const* argv) {
1315
const Opts opts{getOptsOrExit(argc, argv)};
1416
if(opts.transitionalOpts) {
@@ -45,6 +47,8 @@ void run(int argc, const char* const* argv) {
4547
writeToPath(opts.outDir / file.relPath, file.content);
4648
}
4749
}
50+
51+
}
4852
int main(int argc, const char* const* argv) {
4953
try {
5054
run(argc, argv);

src/Preamble.cc

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ std::string getDefaultPreamble(const Opts& opts, std::vector<Directive>& directi
121121
const File& file, bool& manualExport) {
122122
const GetIncludeCtx ctx{opts.inDir, opts.includePaths};
123123
std::string preamble;
124+
std::string imports;
124125
IncludeHandleResult res;
125126
StdImportLvl lvl{StdImportLvl::Unused};
126127

127128
// Only convert include to import for source with a main(), paired or unpaired
128129
if(file.type == FileType::SrcWithMain) {
129-
MinimizeCondCtx mcCtx;
130+
MinimizeCondCtx NoImportCtx;
130131
for(Directive& directive : directives) switch(directive.type) {
131132
case DirectiveType::IfCond:
132133
case DirectiveType::ElCond:
133134
case DirectiveType::Else:
134135
case DirectiveType::EndIf:
135-
mcCtx.emplace_back(std::move(directive));
136+
NoImportCtx.emplace_back(std::move(directive));
136137
break;
137138
case DirectiveType::Include:
138139
res = handleInclude(std::get<IncludeInfo>(directive.extraInfo), ctx, file, opts,
@@ -141,55 +142,51 @@ std::string getDefaultPreamble(const Opts& opts, std::vector<Directive>& directi
141142
// We're in default mode, no need to handle switch case 3 or 4
142143
switch(res.index()) {
143144
case 2: // ConvertToImport
144-
mcCtx.emplace_back(std::get<ConvertToImport>(std::move(res)));
145+
imports += std::get<ConvertToImport>(res);
145146
continue;
146147
case 0: // Skip
147148
continue;
148149
case 1:; // KeepAsInclude
149150
}
150151
[[fallthrough]];
151152
default:
152-
mcCtx.emplace_back(std::move(directive.str));
153+
NoImportCtx.emplace_back(std::move(directive.str));
153154
}
154-
preamble = minimizeCondToStr(mcCtx);
155+
preamble = minimizeCondToStr(NoImportCtx);
155156
}
156157

157158
// Convert to module interface/implementation
158159
else {
159-
MinimizeCondCtx includeCtx;
160-
MinimizeCondCtx importCtx;
160+
MinimizeCondCtx GMFCtx;
161161
for(Directive& directive : directives) switch(directive.type) {
162162
case DirectiveType::IfCond:
163163
case DirectiveType::Else:
164164
case DirectiveType::ElCond:
165165
case DirectiveType::EndIf:
166-
includeCtx.emplace_back(directive);
167-
importCtx.emplace_back(std::move(directive));
166+
GMFCtx.emplace_back((std::move(directive)));
168167
break;
169168
case DirectiveType::Include:
170169
res = handleInclude(std::get<IncludeInfo>(directive.extraInfo), ctx, file, opts,
171170
lvl);
172171

173172
// We're in default mode, no need to handle switch case 3 or 4
174173
switch(res.index()) {
175-
case 0:
176-
break;
177-
case 2:
178-
importCtx.emplace_back(std::get<ConvertToImport>(std::move(res)));
174+
case 0: // Skip
179175
break;
180-
case 1:
181-
includeCtx.emplace_back(std::move(directive.str));
176+
case 2: // ConvertToImport
177+
imports += std::get<ConvertToImport>(std::move(res));
182178
break;
179+
case 1: // KeepAsInclude
180+
GMFCtx.emplace_back(std::move(directive.str));
183181
}
184182
break;
185183
default:
186-
includeCtx.emplace_back(directive.str);
187-
importCtx.emplace_back(std::move(directive.str));
184+
GMFCtx.emplace_back(directive.str);
188185
}
189186
fmt::format_to(std::back_inserter(preamble),
190187
"module;\n"
191188
"{}",
192-
minimizeCondToStr(includeCtx));
189+
minimizeCondToStr(GMFCtx));
193190

194191
// Convert header and unpaired source into module interface unit. Without
195192
// the "export " the file is a module implementation unit
@@ -198,10 +195,10 @@ std::string getDefaultPreamble(const Opts& opts, std::vector<Directive>& directi
198195
preamble += "export ";
199196
}
200197
fmt::format_to(std::back_inserter(preamble),
201-
"module {};\n"
202-
"{}",
203-
path2ModuleName(file.relPath), minimizeCondToStr(importCtx));
198+
"module {};\n",
199+
path2ModuleName(file.relPath));
204200
}
201+
preamble += imports;
205202
if(lvl == StdImportLvl::StdCompat) preamble += "import std.compat;\n";
206203
else if(lvl == StdImportLvl::Std) preamble += "import std;\n";
207204
return preamble;
@@ -214,14 +211,15 @@ std::string getTransitionalPreamble(const Opts& opts,
214211
MinimizeCondCtx includeCtx;
215212
StdImportLvl lvl{StdImportLvl::Unused};
216213
if(file.type == FileType::SrcWithMain) {
217-
MinimizeCondCtx moduleCtx;
214+
MinimizeCondCtx NoImportCtx;
215+
std::string imports;
218216
for(Directive& directive : directives) switch(directive.type) {
219217
case DirectiveType::IfCond:
220218
case DirectiveType::ElCond:
221219
case DirectiveType::Else:
222220
case DirectiveType::EndIf:
223221
includeCtx.emplace_back(directive);
224-
moduleCtx.emplace_back(std::move(directive));
222+
NoImportCtx.emplace_back(std::move(directive));
225223
break;
226224
case DirectiveType::Include:
227225
res = handleInclude(std::get<IncludeInfo>(directive.extraInfo), ctx, file, opts,
@@ -233,7 +231,7 @@ std::string getTransitionalPreamble(const Opts& opts,
233231
case 2: // ConvertToImport
234232
includeCtx.emplace_back(
235233
replaceIncludeExt(std::move(directive), opts.moduleInterfaceExt));
236-
moduleCtx.emplace_back(std::get<ConvertToImport>(std::move(res)));
234+
imports += std::get<ConvertToImport>(res);
237235
continue;
238236
case 3: // KeepForHdr
239237
includeCtx.emplace_back(std::move(directive.str));
@@ -243,18 +241,18 @@ std::string getTransitionalPreamble(const Opts& opts,
243241
[[fallthrough]];
244242
default:
245243
includeCtx.emplace_back(directive.str);
246-
moduleCtx.emplace_back(std::move(directive.str));
244+
NoImportCtx.emplace_back(std::move(directive.str));
247245
}
248246
fmt::format_to(std::back_inserter(preamble),
249247
"#ifdef {}\n"
250-
"{}",
251-
opts.transitionalOpts->mi_control, minimizeCondToStr(moduleCtx));
248+
"{}{}",
249+
opts.transitionalOpts->mi_control, minimizeCondToStr(NoImportCtx), imports);
252250
}
253251

254252
// Convert to module interface/implementation
255253
else {
256254
MinimizeCondCtx GMFCtx;
257-
MinimizeCondCtx importCtx;
255+
std::string imports;
258256
for(Directive& directive : directives) switch(directive.type) {
259257
case DirectiveType::IfCond:
260258
if(std::holds_alternative<IncludeGuard>(directive.extraInfo)) {
@@ -267,7 +265,6 @@ std::string getTransitionalPreamble(const Opts& opts,
267265
case DirectiveType::EndIf:
268266
includeCtx.emplace_back(directive);
269267
GMFCtx.emplace_back(directive);
270-
importCtx.emplace_back(std::move(directive));
271268
break;
272269
case DirectiveType::Include:
273270
res = handleInclude(std::get<IncludeInfo>(directive.extraInfo), ctx, file, opts, lvl);
@@ -283,7 +280,7 @@ std::string getTransitionalPreamble(const Opts& opts,
283280
case 2: // ConvertToImport
284281
includeCtx.emplace_back(
285282
replaceIncludeExt(std::move(directive), opts.moduleInterfaceExt));
286-
importCtx.emplace_back(std::get<ConvertToImport>(std::move(res)));
283+
imports += std::get<ConvertToImport>(res);
287284
break;
288285
case 4: // ReplaceExtForPair
289286
includeCtx.emplace_back(
@@ -301,8 +298,7 @@ std::string getTransitionalPreamble(const Opts& opts,
301298
[[fallthrough]];
302299
default:
303300
includeCtx.emplace_back(directive.str);
304-
GMFCtx.emplace_back(directive.str);
305-
importCtx.emplace_back(std::move(directive.str));
301+
GMFCtx.emplace_back(std::move(directive.str));
306302
}
307303

308304
// generic_string() to convert '\' to '/'
@@ -325,16 +321,16 @@ std::string getTransitionalPreamble(const Opts& opts,
325321
fmt::format_to(std::back_inserter(preamble),
326322
"module {};\n"
327323
"{}",
328-
path2ModuleName(file.relPath), minimizeCondToStr(importCtx));
324+
path2ModuleName(file.relPath), imports);
329325
}
330326

331327
// From here import section should be added, but not include section
332328
if(lvl == StdImportLvl::StdCompat) preamble += "import std.compat;\n";
333329
else if(lvl == StdImportLvl::Std) preamble += "import std;\n";
334330
fmt::format_to(std::back_inserter(preamble),
335331
"#else\n{}"
336-
"#endif\n"
337-
, minimizeCondToStr(includeCtx));
332+
"#endif\n",
333+
minimizeCondToStr(includeCtx));
338334
return preamble;
339335
}
340336

test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function(addTestsFromDir dir)
88
foreach(testDir ${testDirs})
99
get_filename_component(testName ${testDir} NAME)
1010
add_test(NAME "${dir}.${testName}"
11-
COMMAND ${CMAKE_COMMAND} -P Driver.cmake $<TARGET_FILE:importizer>
12-
"${testDir}/config.toml" "${testResDir}/${dir}/${testName}" $<TARGET_FILE:cmpDir>
13-
"${testDir}/CorrectOutput" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
11+
COMMAND ${CMAKE_COMMAND} -P Driver.cmake "$<TARGET_FILE:importizer>"
12+
"${testDir}/config.toml" "${testResDir}/${dir}/${testName}" "$<TARGET_FILE:cmpDir>"
13+
"${testDir}/CorrectOutput" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
1414
endforeach()
1515
endfunction(addTestsFromDir)
1616
addTestsFromDir(Other)

test/Default/Importizer/CorrectOutput/Main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import OptProcessor;
2-
import FileOp;
3-
import Preamble;
4-
import Preprocessor;
51
#include <fmt/base.h>
62
#include <fmt/format.h>
73
#include <fmt/std.h>
84
#include <exception>
95
#include <filesystem>
6+
import OptProcessor;
7+
import FileOp;
8+
import Preamble;
9+
import Preprocessor;
1010

1111

1212
namespace fs = std::filesystem;

test/Default/Importizer/CorrectOutput/Regex.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module;
88
#include "../3rdParty/pcre2/src/pcre2.h.generic"
99
module Regex;
1010
import Base;
11-
#define PCRE2_CODE_UNIT_WIDTH 8
1211

1312
#define PCRE2_CODE_UNIT_WIDTH 8
1413

test/Default/MinimizeCond/CorrectOutput/Test.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ module;
99
#define a
1010
#endif
1111
export module Test;
12-
#ifdef COND2
13-
#define a
14-
#endif
1512

1613
#ifdef COND
1714
#endif

0 commit comments

Comments
 (0)