Skip to content

Commit d52d291

Browse files
committed
Flush after every std::cerr and update Dockerfile
1 parent 46dd840 commit d52d291

File tree

9 files changed

+27
-14
lines changed

9 files changed

+27
-14
lines changed

compiled_starters/cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)
22

33
project(shell-starter-cpp)
44

5-
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
5+
file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
66

77
set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
88

compiled_starters/cpp/src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#include <iostream>
22

33
int main() {
4+
// Flush after every std::cout / std:cerr
5+
std::cout << std::unitbuf;
6+
std::cerr << std::unitbuf;
7+
48
// You can use print statements as follows for debugging, they'll be visible when running tests.
59
std::cout << "Logs from your program will appear here!\n";
610

711
// Uncomment this block to pass the first stage
812
// std::cout << "$ ";
9-
// std::cout.flush();
1013
//
1114
// std::string input;
1215
// std::getline(std::cin, input);

dockerfiles/cpp-23.Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ ENV CMAKE_BIN="/cmake/bin"
1818
ENV PATH="${CMAKE_BIN}:$PATH"
1919

2020
RUN git clone https://github.com/microsoft/vcpkg.git && \
21-
./vcpkg/bootstrap-vcpkg.sh
21+
./vcpkg/bootstrap-vcpkg.sh -disableMetrics
2222

2323
ENV VCPKG_ROOT="/vcpkg"
2424
ENV PATH="${VCPKG_ROOT}:$PATH"
2525

2626
WORKDIR /app
2727

28-
COPY vcpkg.json ./
29-
COPY vcpkg-configuration.json ./
28+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
29+
COPY --exclude=.git --exclude=README.md . /app
3030

3131
RUN vcpkg install --no-print-usage
3232
RUN sed -i '1s/^/set(VCPKG_INSTALL_OPTIONS --no-print-usage)\n/' ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
@@ -36,4 +36,7 @@ RUN if [ -d "/app/build" ]; then mv /app/build /app-cached; fi
3636
RUN if [ -d "/app/vcpkg_installed" ]; then mv /app/vcpkg_installed /app-cached/build; fi
3737

3838
RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake && cmake --build ./build && sed -i '/^cmake/ s/^/# /' ./your_shell.sh" > /codecrafters-precompile.sh
39-
RUN chmod +x /codecrafters-precompile.sh
39+
RUN chmod +x /codecrafters-precompile.sh
40+
41+
# Once the heavy steps are done, we can copy all files back
42+
COPY . /app

solutions/cpp/01-oo8/code/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)
22

33
project(shell-starter-cpp)
44

5-
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
5+
file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
66

77
set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
88

solutions/cpp/01-oo8/code/src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include <iostream>
22

33
int main() {
4+
// Flush after every std::cout / std:cerr
5+
std::cout << std::unitbuf;
6+
std::cerr << std::unitbuf;
7+
48
std::cout << "$ ";
5-
std::cout.flush();
69

710
std::string input;
811
std::getline(std::cin, input);

solutions/cpp/01-oo8/diff/src/main.cpp.diff

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
@@ -1,13 +1,9 @@
1+
@@ -1,16 +1,12 @@
22
#include <iostream>
33

44
int main() {
5+
// Flush after every std::cout / std:cerr
6+
std::cout << std::unitbuf;
7+
std::cerr << std::unitbuf;
8+
59
- // You can use print statements as follows for debugging, they'll be visible when running tests.
610
- std::cout << "Logs from your program will appear here!\n";
711
+ std::cout << "$ ";
8-
+ std::cout.flush();
912

1013
- // Uncomment this block to pass the first stage
1114
- // std::cout << "$ ";
12-
- // std::cout.flush();
1315
- //
1416
- // std::string input;
1517
- // std::getline(std::cin, input);

solutions/cpp/01-oo8/explanation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Study and uncomment the relevant code:
55
```cpp
66
// Uncomment this block to pass the first stage
77
std::cout << "$ ";
8-
std::cout.flush();
98

109
std::string input;
1110
std::getline(std::cin, input);

starter_templates/cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)
22

33
project(shell-starter-cpp)
44

5-
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
5+
file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
66

77
set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
88

starter_templates/cpp/src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#include <iostream>
22

33
int main() {
4+
// Flush after every std::cout / std:cerr
5+
std::cout << std::unitbuf;
6+
std::cerr << std::unitbuf;
7+
48
// You can use print statements as follows for debugging, they'll be visible when running tests.
59
std::cout << "Logs from your program will appear here!\n";
610

711
// Uncomment this block to pass the first stage
812
// std::cout << "$ ";
9-
// std::cout.flush();
1013
//
1114
// std::string input;
1215
// std::getline(std::cin, input);

0 commit comments

Comments
 (0)