File tree Expand file tree Collapse file tree 7 files changed +77
-16
lines changed Expand file tree Collapse file tree 7 files changed +77
-16
lines changed Original file line number Diff line number Diff line change 6
6
#
7
7
# ==-------------------------------------------------------------------------==#
8
8
9
- from pathlib import PurePath
9
+ from pathlib import PurePosixPath
10
10
11
11
12
12
class HeaderFile :
@@ -37,26 +37,33 @@ def add_function(self, function):
37
37
def includes (self ):
38
38
return sorted (
39
39
{
40
- PurePath ("llvm-libc-macros" ) / macro .header
40
+ PurePosixPath ("llvm-libc-macros" ) / macro .header
41
41
for macro in self .macros
42
42
if macro .header is not None
43
43
}
44
+ | {
45
+ PurePosixPath ("llvm-libc-types" ) / f"{ typ .type_name } .h"
46
+ for typ in self .types
47
+ }
44
48
)
45
49
46
50
def public_api (self ):
47
- header_dir = PurePath (self .name ).parent
51
+ # Python 3.12 has .relative_to(dir, walk_up=True) for this.
52
+ path_prefix = PurePosixPath ("../" * (len (PurePosixPath (self .name ).parents ) - 1 ))
53
+
54
+ def relpath (file ):
55
+ return path_prefix / file
56
+
48
57
content = [
49
- f'#include "{ file .relative_to (header_dir )} "' for file in self .includes ()
50
- ] + ["" ]
58
+ f"#include { file } "
59
+ for file in sorted (f'"{ relpath (file )!s} "' for file in self .includes ())
60
+ ]
51
61
52
62
for macro in self .macros :
53
63
# When there is nothing to define, the Macro object converts to str
54
64
# as an empty string. Don't emit a blank line for those cases.
55
65
if str (macro ):
56
- content .append (f"{ macro } \n " )
57
-
58
- for type_ in self .types :
59
- content .append (f"{ type_ } " )
66
+ content .extend (["" , f"{ macro } " ])
60
67
61
68
if self .enumerations :
62
69
combined_enum_content = ",\n " .join (
Original file line number Diff line number Diff line change
1
+ //===-- C standard library header subdir/test.h --------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===--------------------------------------------------------------------===//
8
+
9
+ #ifndef LLVM_LIBC_SUBDIR_TEST_H
10
+ #define LLVM_LIBC_SUBDIR_TEST_H
11
+
12
+ #include "../__llvm-libc-common.h"
13
+
14
+ #include "../llvm-libc-types/type_a.h"
15
+ #include "../llvm-libc-types/type_b.h"
16
+
17
+ __BEGIN_C_DECLS
18
+
19
+ type_a func (type_b ) __NOEXCEPT ;
20
+
21
+ __END_C_DECLS
22
+
23
+ #endif // LLVM_LIBC_SUBDIR_TEST_H
Original file line number Diff line number Diff line change 15
15
16
16
#include "llvm-libc-macros/test_more-macros.h"
17
17
#include "llvm-libc-macros/test_small-macros.h"
18
+ #include "llvm-libc-types/type_a.h"
19
+ #include "llvm-libc-types/type_b.h"
18
20
19
21
#define MACRO_A 1
20
22
21
23
#define MACRO_B 2
22
24
23
25
#define MACRO_C
24
26
25
- #include <llvm-libc-types/type_a.h>
26
- #include <llvm-libc-types/type_b.h>
27
-
28
27
enum {
29
28
enum_a = value_1 ,
30
29
enum_b = value_2 ,
Original file line number Diff line number Diff line change
1
+ //===-- C standard library header subdir/test.h --------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===--------------------------------------------------------------------===//
8
+
9
+ #ifndef LLVM_LIBC_SUBDIR_TEST_H
10
+ #define LLVM_LIBC_SUBDIR_TEST_H
11
+
12
+ #include "../__llvm-libc-common.h"
13
+
14
+ %%public_api()
15
+
16
+ #endif // LLVM_LIBC_SUBDIR_TEST_H
Original file line number Diff line number Diff line change
1
+ header : subdir/test.h
2
+ header_template : test.h.def
3
+ types :
4
+ - type_name : type_a
5
+ - type_name : type_b
6
+ functions :
7
+ - name : func
8
+ return_type : type_a
9
+ arguments :
10
+ - type : type_b
11
+ standards :
12
+ - stdc
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ def setUp(self):
12
12
self .main_script = self .source_dir .parent / "main.py"
13
13
self .maxDiff = 80 * 100
14
14
15
- def run_script (self , yaml_file , output_file , entry_points ):
15
+ def run_script (self , yaml_file , output_file , entry_points = [] ):
16
16
command = [
17
17
"python3" ,
18
18
str (self .main_script ),
@@ -52,6 +52,13 @@ def test_generate_header(self):
52
52
53
53
self .compare_files (output_file , expected_output_file )
54
54
55
+ def test_generate_subdir_header (self ):
56
+ yaml_file = self .source_dir / "input" / "subdir" / "test.yaml"
57
+ expected_output_file = self .source_dir / "expected_output" / "subdir" / "test.h"
58
+ output_file = self .output_dir / "subdir" / "test.h"
59
+ self .run_script (yaml_file , output_file )
60
+ self .compare_files (output_file , expected_output_file )
61
+
55
62
56
63
def main ():
57
64
parser = argparse .ArgumentParser (description = "TestHeaderGenIntegration arguments" )
Original file line number Diff line number Diff line change 10
10
class Type :
11
11
def __init__ (self , type_name ):
12
12
self .type_name = type_name
13
-
14
- def __str__ (self ):
15
- return f"#include <llvm-libc-types/{ self .type_name } .h>"
You can’t perform that action at this time.
0 commit comments