Skip to content

Commit

Permalink
[cpp refactor] Finish creating separate cc_library() targets
Browse files Browse the repository at this point in the history
This is just about "what the code will look like".
  • Loading branch information
Andy C committed Nov 13, 2022
1 parent f8a9a8c commit dd80325
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 53 deletions.
5 changes: 4 additions & 1 deletion bin/NINJA_subgraph.py
Expand Up @@ -39,7 +39,10 @@ def NinjaGraph(ru):
'//cpp/core',
'//cpp/libc',
'//cpp/osh',
'//cpp/bindings',
'//cpp/pgen2',
'//cpp/pylib',
'//cpp/stdlib',

'//cpp/frontend_flag_spec',
'//cpp/frontend_match',

Expand Down
39 changes: 25 additions & 14 deletions cpp/NINJA_subgraph.py
Expand Up @@ -34,7 +34,7 @@ def NinjaGraph(ru):
'cpp/core_test.cc',
deps = [
'//cpp/core',
'//cpp/bindings', # TODO: it's only stdlib
'//cpp/stdlib',
],
matrix = ninja_lib.COMPILERS_VARIANTS)

Expand Down Expand Up @@ -97,7 +97,10 @@ def NinjaGraph(ru):

ru.cc_library(
'//cpp/osh',
srcs = ['cpp/osh.cc'],
srcs = [
'cpp/osh.cc',
'cpp/osh_tdop.cc',
],
deps = [
'//frontend/syntax.asdl',
'//cpp/core',
Expand All @@ -111,22 +114,30 @@ def NinjaGraph(ru):
matrix = ninja_lib.COMPILERS_VARIANTS)

ru.cc_library(
'//cpp/bindings',
# TODO: split these into their own libraries
srcs = [
'cpp/frontend_tdop.cc',
'cpp/pgen2.cc',
'cpp/pylib.cc',
'cpp/stdlib.cc',
],
)
'//cpp/pgen2',
srcs = ['cpp/pgen2.cc'],
deps = ['//mycpp/runtime'])

ru.cc_library(
'//cpp/pylib',
srcs = ['cpp/pylib.cc'],
deps = ['//mycpp/runtime'])

ru.cc_binary(
'cpp/pylib_test.cc',
deps = ['//cpp/pylib'],
matrix = ninja_lib.COMPILERS_VARIANTS)

ru.cc_library(
'//cpp/stdlib',
srcs = ['cpp/stdlib.cc'],
deps = ['//mycpp/runtime'])

ru.cc_binary(
'cpp/binding_test.cc',
'cpp/stdlib_test.cc',
deps = [
'//core/runtime.asdl', # sizeof_test uses this
'//cpp/bindings',
'//mycpp/runtime',
'//cpp/stdlib',
],
matrix = ninja_lib.COMPILERS_VARIANTS)

Expand Down
2 changes: 1 addition & 1 deletion cpp/README.md
Expand Up @@ -40,7 +40,7 @@ Correspond to files:
frontend_match.{cc,h}
from frontend import match

frontend_tdop.{cc,h}
osh_tdop.{cc,h}
from frontend import tdop

TODO: We want non-leaky versions of all files!
20 changes: 12 additions & 8 deletions cpp/TEST.sh
Expand Up @@ -75,16 +75,18 @@ unit() {

# Other tests
for variant in ubsan asan; do
run-one-test cpp/binding_test '' $variant
# Need -D CPP_UNIT_TEST
run-special-test cpp/frontend_flag_spec_test '' $variant

run-one-test cpp/frontend_match_test '' $variant

run-test-in-dir cpp/libc_test '' $variant # has testdata

run-one-test cpp/osh_test '' $variant

# Need -D CPP_UNIT_TEST
run-special-test cpp/frontend_flag_spec_test '' $variant
run-one-test cpp/pylib_test '' $variant

run-one-test cpp/frontend_match_test '' $variant
run-one-test cpp/stdlib_test '' $variant
done
}

Expand All @@ -106,16 +108,18 @@ coverage() {

run-one-test cpp/qsn_test $compiler $variant

run-one-test cpp/binding_test $compiler $variant
# Need -D CPP_UNIT_TEST
run-special-test cpp/frontend_flag_spec_test $compiler $variant

run-one-test cpp/frontend_match_test $compiler $variant

run-test-in-dir cpp/libc_test $compiler $variant # has testdata

run-one-test cpp/osh_test $compiler $variant

# Need -D CPP_UNIT_TEST
run-special-test cpp/frontend_flag_spec_test $compiler $variant
run-one-test cpp/pylib_test $compiler $variant

run-one-test cpp/frontend_match_test $compiler $variant
run-one-test cpp/stdlib_test $compiler $variant

local out_dir=_test/clang-coverage/cpp
test/coverage.sh html-report $out_dir cpp
Expand Down
2 changes: 1 addition & 1 deletion cpp/osh.h
Expand Up @@ -4,7 +4,7 @@
#define LEAKY_OSH_H

#include "_gen/frontend/syntax.asdl.h"
#include "cpp/frontend_tdop.h"
#include "cpp/osh_tdop.h"
#include "mycpp/runtime.h"

namespace arith_parse {
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions cpp/osh_test.cc
@@ -1,4 +1,5 @@
#include "cpp/osh.h"

#include "cpp/core_error.h"
#include "mycpp/runtime.h"
#include "vendor/greatest.h"
Expand Down
2 changes: 1 addition & 1 deletion cpp/preamble.h
Expand Up @@ -19,9 +19,9 @@
#include "cpp/core_pyerror.h"
#include "cpp/frontend_flag_spec.h"
#include "cpp/frontend_match.h"
#include "cpp/frontend_tdop.h"
#include "cpp/libc.h"
#include "cpp/osh.h"
#include "cpp/osh_tdop.h"
#include "cpp/pgen2.h"
#include "cpp/pylib.h"
#include "cpp/qsn.h"
Expand Down
42 changes: 42 additions & 0 deletions cpp/pylib_test.cc
@@ -0,0 +1,42 @@
#include "cpp/pylib.h"

#include "mycpp/runtime.h"
#include "vendor/greatest.h"

TEST os_path_test() {
// TODO: use gc_mylib here, with NewStr(), StackRoots, etc.
Str* s = nullptr;

s = os_path::rstrip_slashes(StrFromC(""));
ASSERT(str_equals(s, StrFromC("")));

s = os_path::rstrip_slashes(StrFromC("foo"));
ASSERT(str_equals(s, StrFromC("foo")));

s = os_path::rstrip_slashes(StrFromC("foo/"));
ASSERT(str_equals(s, StrFromC("foo")));

s = os_path::rstrip_slashes(StrFromC("/foo/"));
ASSERT(str_equals(s, StrFromC("/foo")));

// special case of not stripping
s = os_path::rstrip_slashes(StrFromC("///"));
ASSERT(str_equals(s, StrFromC("///")));

PASS();
}

GREATEST_MAIN_DEFS();

int main(int argc, char** argv) {
gHeap.Init();

GREATEST_MAIN_BEGIN();

RUN_TEST(os_path_test);

gHeap.CleanProcessExit();

GREATEST_MAIN_END();
return 0;
}
29 changes: 2 additions & 27 deletions cpp/binding_test.cc → cpp/stdlib_test.cc
@@ -1,12 +1,11 @@

#include "cpp/stdlib.h"

#include <errno.h>

#include "_gen/core/runtime.asdl.h" // cell, etc
#include "cpp/core_error.h" // FatalRuntime
#include "cpp/libc.h"
#include "cpp/osh.h"
#include "cpp/pylib.h"
#include "cpp/stdlib.h"
#include "mycpp/gc_builtins.h"
#include "vendor/greatest.h"

Expand Down Expand Up @@ -69,29 +68,6 @@ TEST posix_test() {
PASS();
}

TEST os_path_test() {
// TODO: use gc_mylib here, with NewStr(), StackRoots, etc.
Str* s = nullptr;

s = os_path::rstrip_slashes(StrFromC(""));
ASSERT(str_equals(s, StrFromC("")));

s = os_path::rstrip_slashes(StrFromC("foo"));
ASSERT(str_equals(s, StrFromC("foo")));

s = os_path::rstrip_slashes(StrFromC("foo/"));
ASSERT(str_equals(s, StrFromC("foo")));

s = os_path::rstrip_slashes(StrFromC("/foo/"));
ASSERT(str_equals(s, StrFromC("/foo")));

// special case of not stripping
s = os_path::rstrip_slashes(StrFromC("///"));
ASSERT(str_equals(s, StrFromC("///")));

PASS();
}

TEST putenv_test() {
Str* key = StrFromC("KEY");
Str* value = StrFromC("value");
Expand All @@ -113,7 +89,6 @@ int main(int argc, char** argv) {
RUN_TEST(show_sizeof);
RUN_TEST(time_test);
RUN_TEST(posix_test);
RUN_TEST(os_path_test);
RUN_TEST(putenv_test);

gHeap.CleanProcessExit();
Expand Down

0 comments on commit dd80325

Please sign in to comment.