forked from ninja-build/ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'team-4-graph' into new-graph-updated
Signed-off-by: waynewangyuxuan <[email protected]>
- Loading branch information
Showing
15 changed files
with
475 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
mkdir build && cd build | ||
cmake -S .. | ||
make -j $(nproc) | ||
ls | ||
ctest | ||
sudo cp ninja /usr/local/bin/ (move nin to local/bin) | ||
ninja --version | ||
|
||
(cd ..) | ||
git clone https://github.com/llvm/llvm-project.git | ||
cd llvm-project | ||
mkdir build | ||
cd build | ||
cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Release ../llvm | ||
ninja clang-tidy | ||
export PATH=$PATH:/home/yuwei/Documents/llvm-project/build/bin | ||
clang-tidy --version | ||
|
||
|
||
cmake -S .. -B build-cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
cmake --build build-cmake --target run-clang-tidy | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ int main(int argc, char** argv) { | |
#else | ||
real_main(argc, argv); | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#include <iostream> | ||
#include <memory> | ||
|
||
#include "build.h" | ||
#include "graph.h" | ||
#include "state.h" | ||
#include "util.h" | ||
using namespace std; | ||
|
||
void CreateHelloWorldGraph(State* state) { | ||
BindingEnv env; | ||
env.AddBinding("in", "hello_world.cpp"); | ||
env.AddBinding("out", "hello_world"); | ||
env.AddBinding("DEP_FILE", "hello_world.d"); | ||
|
||
// Create rules | ||
Rule* cxx_compiler = new Rule("CXX_COMPILER__hello_world_"); | ||
|
||
// Create command | ||
EvalString command; | ||
command.AddText("g++ -std=gnu++11 "); | ||
command.AddSpecial("$in"); | ||
command.AddText(" -o "); | ||
command.AddSpecial("$out"); | ||
cxx_compiler->AddBinding("command", command); | ||
|
||
// Create description | ||
EvalString description; | ||
description.AddText("Building CXX object "); | ||
description.AddSpecial("$out"); | ||
cxx_compiler->AddBinding("description", description); | ||
|
||
// Add dependency file | ||
EvalString depfile; | ||
depfile.AddSpecial("$DEP_FILE"); | ||
cxx_compiler->AddBinding("depfile", depfile); | ||
|
||
// Add dependency format | ||
EvalString deps; | ||
deps.AddText("gcc"); | ||
cxx_compiler->AddBinding("deps", deps); | ||
|
||
// Add rule to state | ||
state->bindings_.AddRule(cxx_compiler); | ||
|
||
Rule* cxx_linker = new Rule("CXX_EXECUTABLE_LINKER__hello_world_"); | ||
EvalString link; | ||
link.AddText("g++ "); | ||
link.AddSpecial("$in"); | ||
link.AddText(" -o "); | ||
link.AddSpecial("$out"); | ||
cxx_linker->AddBinding("command", link); | ||
EvalString linkDescription; | ||
description.AddText("Linking CXX object "); | ||
description.AddSpecial("$out"); | ||
cxx_linker->AddBinding("description", linkDescription); | ||
state->bindings_.AddRule(cxx_linker); | ||
|
||
// Create nodes | ||
Node* source_file = state->GetNode("hello_world.cpp", 0); | ||
Node* object_file = | ||
state->GetNode("CMakeFiles/hello_world.dir/hello_world.cpp.o", 0); | ||
Node* executable = state->GetNode("hello_world", 0); | ||
|
||
// Create edges | ||
string error_message = ""; | ||
string* err_ptr = &error_message; | ||
Edge* compile_edge = state->AddEdge(cxx_compiler); | ||
if (!state->AddOut(compile_edge, object_file->path(), 0, err_ptr)) { | ||
// Handle error | ||
*err_ptr = "Failed to add output to compile edge\n"; | ||
Error(error_message.c_str()); | ||
return; | ||
} | ||
compile_edge->inputs_.push_back(source_file); | ||
|
||
Edge* link_edge = state->AddEdge(cxx_linker); | ||
if (!state->AddOut(link_edge, executable->path(), 0, err_ptr)) { | ||
// Handle error | ||
*err_ptr = "Failed to add output to link edge\n"; | ||
Error(error_message.c_str()); | ||
return; | ||
} | ||
link_edge->inputs_.push_back(object_file); | ||
|
||
// Set up environment for compile edge | ||
if (compile_edge->env_ == nullptr) { | ||
compile_edge->env_ = new BindingEnv(&state->bindings_); | ||
} | ||
compile_edge->env_->AddBinding( | ||
"DEP_FILE", "CMakeFiles/hello_world.dir/hello_world.cpp.o.d"); | ||
|
||
// Add default target | ||
if (!state->AddDefault(executable->path(), err_ptr)) { | ||
// Handle error | ||
*err_ptr = "Failed to add default target: \n"; | ||
Error(error_message.c_str()); | ||
return; | ||
} | ||
} | ||
|
||
void Error(const string& message) { | ||
cerr << "Error: " << message << endl; | ||
} | ||
|
||
int main() { | ||
State state; | ||
// Create Graph | ||
CreateHelloWorldGraph(&state); | ||
// Create the Builder object | ||
Builder builder(&state); | ||
|
||
string err; | ||
if (!builder.AddTarget("hello_world", &err)) { | ||
Error("Failed to add build target: " + err); | ||
return 1; | ||
} | ||
|
||
if (!builder.Build(&err)) { | ||
Error("Build failed: " + err); | ||
return 1; | ||
} | ||
|
||
cout << "Build completed successfully!" << std::endl; | ||
return 0; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
# Set the project name | ||
project(HelloWorld) | ||
|
||
# Specify the C++ standard | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
# Add the executable | ||
add_executable(hello_world hello_world.cpp) | ||
|
||
# Optional: You can set the value of N here | ||
# target_compile_definitions(hello_world PRIVATE N="CMake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### Command for Hello World Graph | ||
cmake -G "Ninja" -S .. | ||
ninja | ||
ninja -t graph | dot -Tpng -ograph.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/home/yuwei/Documents/ShadowDash/src | ||
|
||
export LD_LIBRARY_PATH=/home/yuwei/Documents/ShadowDash/build:$LD_LIBRARY_PATH | ||
|
||
g++ -I /home/yuwei/Documents/ShadowDash/src -L /home/yuwei/Documents/ShadowDash/build -lninja_shared -o test1 test1.cc | ||
or | ||
g++ -I /home/yuwei/Documents/ShadowDash/src -L /home/yuwei/Documents/ShadowDash/build -lninja_shared -Wl,-rpath,/home/yuwei/Documents/ShadowDash/build -o test1 test1.cc | ||
|
||
g++ eval_env.cc test1.cc state.cc graph.cc -o exe.out | ||
|
||
### SO | ||
g++ -fPIC -shared -I../../src ../../src/build_log.cc \ | ||
../../src/build.cc \ | ||
../../src/clean.cc \ | ||
../../src/clparser.cc \ | ||
../../src/dyndep.cc \ | ||
../../src/dyndep_parser.cc \ | ||
../../src/debug_flags.cc \ | ||
../../src/deps_log.cc \ | ||
../../src/disk_interface.cc \ | ||
../../src/edit_distance.cc \ | ||
../../src/elide_middle.cc \ | ||
../../src/eval_env.cc \ | ||
../../src/graph.cc \ | ||
../../src/graphviz.cc \ | ||
../../src/json.cc \ | ||
../../src/line_printer.cc \ | ||
../../src/manifest_parser.cc \ | ||
../../src/metrics.cc \ | ||
../../src/missing_deps.cc \ | ||
../../src/parser.cc \ | ||
../../src/state.cc \ | ||
../../src/status_printer.cc \ | ||
../../src/string_piece_util.cc \ | ||
../../src/util.cc \ | ||
../../src/subprocess-posix.cc \ | ||
../../src/lexer.cc \ | ||
../../src/depfile_parser.cc \ | ||
../../src/version.cc -o libninja.so | ||
g++ -fPIC test1.cc -I../../src -L./ -lninja -Wl,-rpath=. -o test1 | ||
|
||
### For debug | ||
g++ -g test1.cc -I../../src -L./ -lninja -Wl,-rpath=. -o test1 | ||
gdb ./test1 | ||
sharedlibrary libninja.so | ||
run | ||
backtrace | ||
break xx |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
#ifndef N | ||
#define N "World" | ||
#endif | ||
|
||
int main() { | ||
printf("Hello %s! \n", N); | ||
return 0; | ||
} |
Binary file not shown.
Oops, something went wrong.