Skip to content

Commit

Permalink
Merge with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Tingan Ho committed Aug 24, 2017
2 parents d125e36 + 76a847b commit 9c508dd
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 66 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ before_install:

# nodejs
- curl -sL https://deb.nodesource.com/setup_7.x | sudo bash
- sudo apt-get update -y
- sudo apt-get install nodejs
- sudo npm install typescript -g
- sudo npm install typescript tslint -g

# libmicrohttpd
- wget http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.52.tar.gz
- curl -O http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.52.tar.gz
- tar -xvf libmicrohttpd-0.9.52.tar.gz
- cd libmicrohttpd-0.9.52
- ./configure && make
Expand Down
11 changes: 2 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ add_subdirectory(third_party/grpc)
include_directories("C:/Program Files (x86)/libjson-rpc-cpp 0.5.0/include")
include_directories("${PROJECT_SOURCE_DIR}/src/Program")
include_directories("${PROJECT_SOURCE_DIR}/src/TestFramework")
include_directories("${PROJECT_SOURCE_DIR}/src/Vendors/Glob")
include_directories("C:/jsoncpp/dist")

ADD_LIBRARY(jsonrpccpp-common STATIC IMPORTED)
SET_TARGET_PROPERTIES(jsonrpccpp-common PROPERTIES IMPORTED_LOCATION "C:/Program Files (x86)/libjson-rpc-cpp 0.5.0/lib/libjsonrpccpp-common.a")
ADD_LIBRARY(jsonrpccpp-client STATIC IMPORTED)
SET_TARGET_PROPERTIES(jsonrpccpp-client PROPERTIES IMPORTED_LOCATION "C:/Program Files (x86)/libjson-rpc-cpp 0.5.0/lib/libjsonrpccpp-client.a")
ADD_LIBRARY(jsonrpccpp-server STATIC IMPORTED)
SET_TARGET_PROPERTIES(jsonrpccpp-server PROPERTIES IMPORTED_LOCATION "C:/Program Files (x86)/libjson-rpc-cpp 0.5.0/lib/libjsonrpccpp-server.a")

add_executable(l10ns C:/jsoncpp/dist/jsoncpp.cpp ${PROJECT_SOURCE_DIR}/src/Program/Exec.cpp)

add_executable(accept-baseline ${PROJECT_SOURCE_DIR}/tasks/AcceptBaseline.cpp)
Expand All @@ -40,7 +32,8 @@ add_executable(generate-diagnostics ${PROJECT_SOURCE_DIR}/tasks/GenerateDiagnost
add_executable(generate-json-rpc-client-stub ${PROJECT_SOURCE_DIR}/tasks/GenerateJsonRpcClientStub.cpp)
add_executable(run-tests ${PROJECT_SOURCE_DIR}/src/TestFramework/Exec.cpp)

target_link_libraries(l10ns glob jsonrpccpp-common jsonrpccpp-client jsonrpccpp-server ${Boost_LIBRARIES})
target_link_libraries(l10ns glob jsoncpp curl ${Boost_LIBRARIES})

target_link_libraries(accept-baseline glob ${Boost_LIBRARIES})
target_link_libraries(clean-project glob ${Boost_LIBRARIES})
target_link_libraries(diff glob ${Boost_LIBRARIES})
Expand Down
92 changes: 51 additions & 41 deletions src/Extensions/JavaScript/Source/Main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import net = require('net');
import fs = require('fs');
import http = require('http');
import { extractKeysFromFile, Key } from './KeyExtractor/Extractor';

interface SyncParams {
Expand All @@ -26,46 +25,57 @@ interface Files {
[name: string]: Key[];
}

function sendFinishStatus() {
fs.createWriteStream('', { fd: 4 }).write('1');
}

const server = net.createServer((client) => {
client.setEncoding('utf8');
client.on('data', (data) => {
const rpc = JSON.parse(data.toString()) as RPCRequest;
switch (rpc.method) {
case 'sync':
const files: Files = {};
const callExpressionIdentifiers = rpc.params.function_names;
for (const f of rpc.params.files) {
const keys = extractKeysFromFile(f, callExpressionIdentifiers);
files[f] = keys;
}
write(rpc.id, files);
break;
case 'compile':
break;
default:
throw new Error(`Unknown method '${rpc.method}'`);
function main() {
let firstRequest = true;
const server = http.createServer((req, res) => {
if (firstRequest) {
const body = '{}';
res.writeHead(200, { Connection: 'close', 'Content-Length': Buffer.byteLength(body) });
res.write(body);
res.end();
firstRequest = false;
return;
}
});
client.pipe(client);

function write(id: number, result: any) {
client.write(JSON.stringify({
id,
jsonrpc: '2.0',
result,
} as RPCResponse));
}
});
let data: Buffer[] = [];
req.on('data', (chunk: Buffer) => {
data.push(chunk);
})
.on('end', () => {
const body = Buffer.concat(data).toString();
const rpc = JSON.parse(body) as RPCRequest;
switch (rpc.method) {
case 'sync':
const files: Files = {};
const callExpressionIdentifiers = rpc.params.function_names;
for (const f of rpc.params.files) {
const keys = extractKeysFromFile(f, callExpressionIdentifiers);
files[f] = keys;
}
write(rpc.id, files);
break;
case 'compile':
break;
default:
throw new Error(`Unknown method '${rpc.method}'`);
}

process.on('SIGTERM', () => {
server.close();
process.exit(0);
});
function write(id: number, result: any) {
const body = JSON.stringify({
id,
jsonrpc: '2.0',
result,
} as RPCResponse);
res.writeHead(200, { Connection: 'close', 'Content-Length': Buffer.byteLength(body) });
res.write(body);
res.end();
}
});
}).listen(8888);

server.listen('/tmp/l10ns.sock', () => {
sendFinishStatus();
});
process.on('SIGTERM', () => {
server.close();
process.exit(0);
});
}
main();
7 changes: 3 additions & 4 deletions src/Program/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ class Extension {
Session* session;
JsonRpcClient* client;

int start_server(int (&fd)[2]) {
int start_server() {
pid_t cpid = fork();
if (cpid == 0) {
close(fd[0]);
execl("/bin/bash", "/bin/bash", "-c", command.c_str(), (char *) 0);
}
return cpid;
Expand All @@ -123,8 +122,8 @@ class Extension {
for (auto const& f : function_names) {
function_names_json.append(f);
}
UnixDomainSocketClient unix_domain_socket_client("/tmp/l10ns.sock");
JsonRpcClient rpc_client(unix_domain_socket_client);
HttpClient http_client("http://localhost:8888");
JsonRpcClient rpc_client(http_client);
auto file_to_keys_json = rpc_client.sync(files_json, function_names_json);
FileToKeys file_to_keys;
for (Json::ValueIterator file_to_keys_it = file_to_keys_json.begin(); file_to_keys_it != file_to_keys_json.end(); file_to_keys_it++) {
Expand Down
30 changes: 21 additions & 9 deletions src/Program/ExtensionTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Extension.cpp"
#include "Core.cpp"
#include <signal.h>
#include <curl/curl.h>

using namespace L10ns;
using namespace TestFramework;
Expand All @@ -15,8 +16,10 @@ void kill_all_processes(int signum) {
#ifdef __unix__
kill(child, SIGTERM);
unlink("/tmp/l10ns.sock");
exit(signum);
#endif
}

size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) {
return size * nmemb;
}

void run_extension_tests(Session* session) {
Expand All @@ -25,14 +28,23 @@ void run_extension_tests(Session* session) {

auto start_extension_server = [&]() -> void {
extension = Extension::create(session, extension_file);
#ifdef __unix__
int fd[2];
pipe(fd);
child = extension->start_server(fd);
child = extension->start_server();
signal(SIGINT, kill_all_processes);
char buf[1];
read(fd[0], buf, 1);
#endif

CURL *curl;
CURLcode res;
curl = curl_easy_init();
while (true) {
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8888");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
continue;
}

curl_easy_cleanup(curl);
break;
}
};

auto for_each_compilation_test_file = [&](std::function<void (const string&)> callback) -> void {
Expand Down
1 change: 0 additions & 1 deletion src/Program/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ bool copy_folder(fs::path const & source, fs::path const & destination) {
<< "' already exists." << '\n';
return false;
}

if (!fs::create_directory(destination)) {
std::cerr << "Unable to create destination directory '" << destination.string() << "'.\n";
return false;
Expand Down

0 comments on commit 9c508dd

Please sign in to comment.