From 5cd619ab0f6984400b2cfff0726415a6a8c7f201 Mon Sep 17 00:00:00 2001 From: asandrad22 Date: Wed, 4 Nov 2015 20:28:59 +0000 Subject: [PATCH 1/4] Adding vagrant files to replicate server enviornments. Adding BuilderCompilerHandler.php. This file is what handles compiling request for arduino builder. Locations are currently hardcoded. --- BuilderCompilerHandler.php | 301 ++++++++++++++++++ .../default/virtualbox/action_provision | 1 + .../default/virtualbox/action_set_name | 1 + .../machines/default/virtualbox/creator_uid | 1 + .../.vagrant/machines/default/virtualbox/id | 1 + .../machines/default/virtualbox/index_uuid | 1 + .../machines/default/virtualbox/private_key | 27 ++ .../default/virtualbox/synced_folders | 1 + vagrant/Vagrantfile | 71 +++++ 9 files changed, 405 insertions(+) create mode 100644 BuilderCompilerHandler.php create mode 100755 vagrant/.vagrant/machines/default/virtualbox/action_provision create mode 100755 vagrant/.vagrant/machines/default/virtualbox/action_set_name create mode 100755 vagrant/.vagrant/machines/default/virtualbox/creator_uid create mode 100755 vagrant/.vagrant/machines/default/virtualbox/id create mode 100755 vagrant/.vagrant/machines/default/virtualbox/index_uuid create mode 100755 vagrant/.vagrant/machines/default/virtualbox/private_key create mode 100755 vagrant/.vagrant/machines/default/virtualbox/synced_folders create mode 100755 vagrant/Vagrantfile diff --git a/BuilderCompilerHandler.php b/BuilderCompilerHandler.php new file mode 100644 index 0000000..a5a81bc --- /dev/null +++ b/BuilderCompilerHandler.php @@ -0,0 +1,301 @@ +preproc = new PreprocessingHandler(); + $this->postproc = new PostprocessingHandler(); + $this->utility = new UtilityHandler(); + } + + /** + \brief Processes a compile request. + + \param string $request The body of the POST request. + \return A message to be JSON-encoded and sent back to the requestor. + */ + function main($request, $compiler_config) + { + + error_reporting(E_ALL & ~E_STRICT); + + $this->set_values($compiler_config, + $CC, $CPP, $AS, $LD, $CLANG, $OBJCOPY, $SIZE, $CFLAGS, $CPPFLAGS, $ASFLAGS, $LDFLAGS, $LDFLAGS_TAIL, + $CLANG_FLAGS, $OBJCOPY_FLAGS, $SIZE_FLAGS, $OUTPUT, $ARDUINO_CORES_DIR, $ARDUINO_SKEL); + + $start_time = microtime(true); + + + // Step 0: Reject the request if the input data is not valid. + //TODO: Replace $tmp variable name + $tmp = $this->requestValid($request); + if($tmp["success"] == false) + return $tmp; + + $this->set_variables($request, $format, $libraries, $version, $mcu, $f_cpu, $core, $variant, $vid, $pid); + + // Step 1: Extract the files included in the request. + $tmp = $this->extractFiles($request, $dir, $files); + if ($tmp["success"] == false) + return $tmp; + + + $tmp = $this->doCompile($files, $dir, $format); + if ($tmp["success"] == false) + return $tmp; + + if ($format == "syntax") + return array( + "success" => true, + "time" => microtime(true) - $start_time); + + $build_path = '/tmp/codebender_object_files'; + $tmp = $this->convertOutput($build_path, $format, $SIZE, "Blink Example.ino", $start_time); + return $tmp; + + + } + + + private function requestValid(&$request) + { + $request = $this->preproc->validate_input($request); + if (!$request) + return array( + "success" => false, + "step" => 0, + "message" => "Invalid input."); + else return array("success" => true); + } + + protected function extractFiles($request, &$dir, &$files) + { + // Create a temporary directory to place all the files needed to process + // the compile request. This directory is created in $TMPDIR or /tmp by + // default and is automatically removed upon execution completion. + $dir = "/tmp/compiler"; + + mkdir($dir); + + if (!$dir) + return array( + "success" => false, + "step" => 1, + "message" => "Failed to create temporary directory."); + + $response = $this->utility->extract_files($dir, $request->files); + if ($response["success"] === false) + return $response; + $files = $response["files"]; + + if (!file_exists($dir."/libraries")) + mkdir($dir."/libraries/", 0777, true); + //TODO: check if it succeeded + $files["libs"] = array(); + foreach($request->libraries as $library_name => $library_files) + { + //TODO: check if it succeeded + if (!file_exists($dir."/libraries".$library_name)) + mkdir($dir."/libraries/".$library_name, 0777, true); + $tmp = $this->utility->extract_files($dir."/libraries/".$library_name, $library_files); + $files["libs"][] = $tmp["files"]; + } + + return array("success" => true); + } + + + + protected function doCompile(&$files, $dir, $format) + { + $targets = '-hardware /home/vagrant/work/src/arduino.cc/builder/hardware -hardware /home/vagrant/arduino-nightly/hardware -hardware /home/vagrant/arduino-nightly/hardware/arduino/avr -hardware /home/vagrant/arduino-nightly/hardware/tools/avr -libraries /home/vagrant/arduino-nightly/libraries -libraries /home/vagrant/arduino-nightly/hardware/arduino/avr/libraries -tools /usr/bin/ -tools /home/vagrant/arduino-nightly/hardware/tools/avr/ -tools /home/vagrant/arduino-nightly/tools-builder/'; + $builder_compiler = '/home/vagrant/work/bin/builder'; + $build_path = '/tmp/codebender_object_files'; + + $targets = escapeshellarg($targets); + $builder_compiler = escapeshellarg($builder_compiler); + $build_path = escapeshellarg($build_path); + foreach (array("c", "cpp", "S","ino") as $ext) + { + foreach ($files[$ext] as $file) + { + // From hereon, $file is shell escaped and thus should only be used in calls + // to exec(). + $file = escapeshellarg($file); + exec("/home/vagrant/work/bin/builder -fqbn arduino:avr:uno -hardware /home/vagrant/work/src/arduino.cc/builder/hardware -hardware /home/vagrant/arduino-nightly/hardware -hardware /home/vagrant/arduino-nightly/hardware/arduino/avr -hardware /home/vagrant/arduino-nightly/hardware/tools/avr -libraries /home/vagrant/arduino-nightly/libraries -libraries /home/vagrant/arduino-nightly/hardware/arduino/avr/libraries -tools /usr/bin/ -tools /home/vagrant/arduino-nightly/hardware/tools/avr/ -tools /home/vagrant/arduino-nightly/tools-builder/ -build-path $build_path $file.$ext 2>&1", $output, $ret_compile); + + + if (isset($ret_compile) && $ret_compile) + { + return array( + "success" => false, + "step" => 4, + "message" => $output, + "debug" => $avr_output); + } + unset($output); + + $files["o"][] = array_shift($files[$ext]); + + } + } + + return array("success" => true); + } + + protected function convertOutput($dir, $format, $SIZE, $OUTPUT, $start_time) + { + if ($format == "elf") + { + $ret_objcopy = false; + //exec("$SIZE $SIZE_FLAGS --target=elf32-avr $dir/$OUTPUT.elf | awk 'FNR == 2 {print $1+$2}'", $size, $ret_size); // FIXME + $content = base64_encode(file_get_contents("$dir/$OUTPUT.elf")); + } + elseif ($format == "binary") + { + //exec("$OBJCOPY $OBJCOPY_FLAGS -O binary $dir/$OUTPUT.elf $dir/$OUTPUT.bin", $dummy, $ret_objcopy); + //exec("$SIZE $SIZE_FLAGS --target=binary $dir/$OUTPUT.bin | awk 'FNR == 2 {print $1+$2}'", $size, $ret_size); // FIXME + $content = base64_encode(file_get_contents("$dir/$OUTPUT.bin")); + } + elseif ($format == "hex") + { + //exec("$OBJCOPY $OBJCOPY_FLAGS -O ihex $dir/$OUTPUT.elf $dir/$OUTPUT.hex", $dummy, $ret_objcopy); + //exec("$SIZE $SIZE_FLAGS --target=ihex $dir/$OUTPUT.hex | awk 'FNR == 2 {print $1+$2}'", $size, $ret_size); // FIXME + $content = file_get_contents("$dir/$OUTPUT.hex"); + } + + // If everything went well, return the reply to the caller. + if ($ret_objcopy || $ret_size || $content === false) + return array( + "success" => false, + "step" => 8, + "message" => "There was a problem while generating the your binary file"); + else + return array( + "success" => true, + "time" => microtime(true) - $start_time, + "size" => $size[0], + "output" => $content); + + } + + private function preprocessIno(&$files, $ARDUINO_CORES_DIR, $ARDUINO_SKEL, $version, $core) + { + foreach ($files["ino"] as $file) + { + //TODO: make it compatible with non-default hardware (variants & cores) + if (!isset($skel) && ($skel = file_get_contents("$ARDUINO_CORES_DIR/v$version/hardware/arduino/cores/$core/$ARDUINO_SKEL")) === false) + return array( + "success" => false, + "step" => 2, + "message" => "Failed to open Arduino skeleton file."); + + $code = file_get_contents("$file.ino"); + $new_code = $this->preproc->ino_to_cpp($skel, $code, "$file.ino"); + $ret = file_put_contents("$file.cpp", $new_code); + + if ($code === false || !$new_code || !$ret) + return array( + "success" => false, + "step" => 2, + "message" => "Failed to preprocess file '$file.ino'."); + + $files["cpp"][] = array_shift($files["ino"]); + } + + return array("success" => true); + } + + public function preprocessHeaders(&$files, &$libraries, &$include_directories, $dir, $ARDUINO_CORES_DIR, $version, $core, $variant) + { + try + { + // Create command-line arguments for header search paths. Note that the + // current directory is added to eliminate the difference between <> + // and "" in include preprocessor directives. + //TODO: make it compatible with non-default hardware (variants & cores) + $include_directories = "-I$dir -I$ARDUINO_CORES_DIR/v$version/hardware/arduino/cores/$core -I$ARDUINO_CORES_DIR/v$version/hardware/arduino/variants/$variant"; + + //TODO: The code that rests on the main website looks for headers in all files, not just c, cpp and h. Might raise a security issue + $files["dir"] = array(); + foreach($libraries as $library_name => $library_files) + { + $files["dir"][] = $dir."/libraries/".$library_name; + } + + // Add the libraries' paths in the include paths in the command-line arguments + if (file_exists("$dir/utility")) + $include_directories .= " -I$dir/utility"; + foreach ($files["dir"] as $directory) + $include_directories .= " -I$directory"; + } + catch(\Exception $e) + { + return array("success" => false, "step" => 3, "message" => "Unknown Error:\n".$e->getMessage()); + } + + return array("success" => true); + } + private function set_values($compiler_config, + &$CC, &$CPP, &$AS, &$LD, &$CLANG, &$OBJCOPY, &$SIZE, &$CFLAGS, &$CPPFLAGS, + &$ASFLAGS, &$LDFLAGS, &$LDFLAGS_TAIL, &$CLANG_FLAGS, &$OBJCOPY_FLAGS, &$SIZE_FLAGS, + &$OUTPUT, &$ARDUINO_CORES_DIR, &$ARDUINO_SKEL) + { + // External binaries. + $CC = $compiler_config["cc"]; + $CPP = $compiler_config["cpp"]; + $AS = $compiler_config["as"]; + $LD = $compiler_config["ld"]; + $CLANG = $compiler_config["clang"]; + $OBJCOPY = $compiler_config["objcopy"]; + $SIZE = $compiler_config["size"]; + // Standard command-line arguments used by the binaries. + $CFLAGS = $compiler_config["cflags"]; + $CPPFLAGS = $compiler_config["cppflags"]; + $ASFLAGS = $compiler_config["asflags"]; + $LDFLAGS = $compiler_config["ldflags"]; + $LDFLAGS_TAIL = $compiler_config["ldflags_tail"]; + $CLANG_FLAGS = $compiler_config["clang_flags"]; + $OBJCOPY_FLAGS = $compiler_config["objcopy_flags"]; + $SIZE_FLAGS = $compiler_config["size_flags"]; + // The default name of the output file. + $OUTPUT = $compiler_config["output"]; + // Path to arduino-core-files repository. + $ARDUINO_CORES_DIR = $compiler_config["arduino_cores_dir"]; + // The name of the Arduino skeleton file. + $ARDUINO_SKEL = $compiler_config["arduino_skel"]; + } + + private function set_variables($request, &$format, &$libraries, &$version, &$mcu, &$f_cpu, &$core, &$variant, &$vid, &$pid) + { + // Extract the request options for easier access. + $format = $request->format; + $libraries = $request->libraries; + $version = $request->version; + $mcu = $request->build->mcu; + $f_cpu = $request->build->f_cpu; + $core = $request->build->core; + $variant = $request->build->variant; + + // Set the appropriate variables for vid and pid (Leonardo). + $vid = ($variant == "leonardo") ? $request->build->vid : ""; + $pid = ($variant == "leonardo") ? $request->build->pid : ""; + } + +} diff --git a/vagrant/.vagrant/machines/default/virtualbox/action_provision b/vagrant/.vagrant/machines/default/virtualbox/action_provision new file mode 100755 index 0000000..95e57e1 --- /dev/null +++ b/vagrant/.vagrant/machines/default/virtualbox/action_provision @@ -0,0 +1 @@ +1.5:4f2169c0-47c5-4bce-9859-58fda0f7a877 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/action_set_name b/vagrant/.vagrant/machines/default/virtualbox/action_set_name new file mode 100755 index 0000000..f995fa2 --- /dev/null +++ b/vagrant/.vagrant/machines/default/virtualbox/action_set_name @@ -0,0 +1 @@ +1445846899 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/creator_uid b/vagrant/.vagrant/machines/default/virtualbox/creator_uid new file mode 100755 index 0000000..c227083 --- /dev/null +++ b/vagrant/.vagrant/machines/default/virtualbox/creator_uid @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/id b/vagrant/.vagrant/machines/default/virtualbox/id new file mode 100755 index 0000000..c5cb3ad --- /dev/null +++ b/vagrant/.vagrant/machines/default/virtualbox/id @@ -0,0 +1 @@ +4f2169c0-47c5-4bce-9859-58fda0f7a877 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/index_uuid b/vagrant/.vagrant/machines/default/virtualbox/index_uuid new file mode 100755 index 0000000..78d5735 --- /dev/null +++ b/vagrant/.vagrant/machines/default/virtualbox/index_uuid @@ -0,0 +1 @@ +b2d9f07d2f6d42afbd0db6752774cf06 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/private_key b/vagrant/.vagrant/machines/default/virtualbox/private_key new file mode 100755 index 0000000..ba45790 --- /dev/null +++ b/vagrant/.vagrant/machines/default/virtualbox/private_key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAlqo2QzmjtMBEUMgCa0URlEnf0+PFYcX8G6xRQFtixOjfGX57 +4KhXkwLbO55vnytjGUjAbME7qvcUJqQlSaCYFjEpa66c4Li9Hx8fM0AZoLyeaT1s +QH90FLvHlg61gysd5cXjmjAlgzHa/R/M++3deQlfgG8RxkkNPGv99dojlhDH2yXI +TFXxVNeY5R0ohRIWxJBMCu01kXaM8t7uUavSomLm1UeLIHCuR33Bb4PJcI3aCgGM +StySyxne+vvSAl0Y1QnyShmLrUyhE4QfyqceKwNSuP9aA7YgrqafbTq12tc6Bqf+ +RlLZjtUQVGpiMZia+joLSgVt91rxSZhHGhrE2wIDAQABAoIBAQCQfEE3bNJKp8ub +8IMpXf5CyCmnaRpD7nscCr+MyVbJ4Uz6hOrFgoshR6742LLQ4OnTOIqYgSL4jKQ9 +flLn7eOL/K9tPfHiLCfp7Y2dN46cL+Z2pFno7JFkxMPdatO1K6crUAA6QIvo6enJ +rzKEMxOeXFfCskFId4wC8smEeSKBaLObVum7EKAlYbAqyfUHhQmaRsosXMo22BiW +U7QSaNpaYg5s/wNhDY6dSz696T5CoqhWTOdJcZaKccxKN6/cGhYM3/JzyHKk/tKp +2I4zk0YLKHomd2lhcxJGBCdshxiXZUaqKh4pRQoLbLcAJ/e5JY8Vka9ud9yhXlIH +MQ4MKhDRAoGBAMbBpKrAr2RR25k5+Gw6IGWRzC6MunmBeGlPoes0UcGNeVI3y8wg +5I8z0cC7tllz0adAUhqurBQOAk4jvTpM4e9xyBiRzfIVR3nrmwrd0B1fvRKDYyJN +Sh3+q6m6LETSClx2mEG/re62asj3sG5mEwB+7zbIKdfXAjOH+ewPejYjAoGBAMIO +xOskpQjjMHCLbK+tCj/Uh5v3h0O4OqdfhfqUqnlHVnBlREAi7Yr0Gs+5kwjP6+mg +1naS8ZNYWMvEvWN+paxx4mFT6yKqSnTqamhKvA5V+pW0BG/BzxPHSBr8wG8kczaA +HqB+Ax06yhBN9wwtUtue3no6HURrhM3ZALcysPXpAoGAKnSMpwi3rlcp8EYIwZ18 +9BU7pynaXz//p4ciECrB1/VPV/ehKb5Q9CHeiSvPnLX3r6E2qIptKW+AoI5TylNH +46zLUCw88JwJA4sHOD//R3b+3SiBkX8u+M9AfeXNtPmkyvFuPoUiMx52Gu2Fm19k +abOzh2EkRv2fc8B06y63LT8CgYBgYoOOI3JRGr6Jd8aw7uqDT6VXYzds/EktrrVW +A5c0i6k0RCgFDxQbCylx+UM9gkAzly5OUKfqPlxEQWCr1VCmeR4up0bHvfsjXPci ++9Ox7yR6TKJTe9jFgxqeROGzklAjRrlvj4cucm/Ab2kARFa+PIdWAB1fSWP59glz +9JqOWQKBgQCLptHSG681HMUIOgjibaAE/W2YVYSN7ePrpy7vMWB6UuETccFm13DE +daN6+0swcW4HRPslCOKMPJ59zkPk6p+W93DRq2Stoob8IrKLbOItCoMGG89uQWEU +0QtW8ctbPO2L/Gi348eEdGpWsq49ci9qbFN02jh3LV868fTjsPpvZA== +-----END RSA PRIVATE KEY----- diff --git a/vagrant/.vagrant/machines/default/virtualbox/synced_folders b/vagrant/.vagrant/machines/default/virtualbox/synced_folders new file mode 100755 index 0000000..39695eb --- /dev/null +++ b/vagrant/.vagrant/machines/default/virtualbox/synced_folders @@ -0,0 +1 @@ +{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"C:/Users/Arturo/Documents/Computer-Engineer/vargant","disabled":false}}} \ No newline at end of file diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile new file mode 100755 index 0000000..c1653dc --- /dev/null +++ b/vagrant/Vagrantfile @@ -0,0 +1,71 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure(2) do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "ubuntu/trusty64" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = true + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + config.vm.network "forwarded_port", guest: 80, host: 80 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + #config.vm.synced_folder "./", "/home/vagrant" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + vb.gui = true + # + # # Customize the amount of memory on the VM: + vb.memory = "2048" + end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + config.vm.provision "shell", inline: <<-SHELL + sudo apt-get update + sudo apt-get install -y apache2 + SHELL +end From 46c6a61cb6945050c28b132a4d6879f5def2cb03 Mon Sep 17 00:00:00 2001 From: asandrad22 Date: Fri, 27 Nov 2015 21:35:12 +0000 Subject: [PATCH 2/4] deleted vagrant folder moved BuilderCompilerHandler.php to modified files added modified-files so Codebender/compiler can support arduino-builder added setup.sh to set up server enviornment --- .gitignore | 1 + BuilderCompilerHandler.php | 301 ------------------ vagrant/Vagrantfile => Vagrantfile | 4 +- .../Controller/DefaultController.php | 180 +++++++++++ .../Handler/BuilderCompilerHandler.php | 262 +++++++++++++++ .../Resources/config/routing.yml | 27 ++ .../Resources/config/services.yml | 36 +++ setup.sh | 16 + .../default/virtualbox/action_provision | 1 - .../default/virtualbox/action_set_name | 1 - .../machines/default/virtualbox/creator_uid | 1 - .../.vagrant/machines/default/virtualbox/id | 1 - .../machines/default/virtualbox/index_uuid | 1 - .../machines/default/virtualbox/private_key | 27 -- .../default/virtualbox/synced_folders | 1 - 15 files changed, 524 insertions(+), 336 deletions(-) create mode 100644 .gitignore delete mode 100644 BuilderCompilerHandler.php rename vagrant/Vagrantfile => Vagrantfile (95%) mode change 100755 => 100644 create mode 100644 modified-files/CompilerBundle/Controller/DefaultController.php create mode 100644 modified-files/CompilerBundle/Handler/BuilderCompilerHandler.php create mode 100644 modified-files/CompilerBundle/Resources/config/routing.yml create mode 100644 modified-files/CompilerBundle/Resources/config/services.yml create mode 100644 setup.sh delete mode 100755 vagrant/.vagrant/machines/default/virtualbox/action_provision delete mode 100755 vagrant/.vagrant/machines/default/virtualbox/action_set_name delete mode 100755 vagrant/.vagrant/machines/default/virtualbox/creator_uid delete mode 100755 vagrant/.vagrant/machines/default/virtualbox/id delete mode 100755 vagrant/.vagrant/machines/default/virtualbox/index_uuid delete mode 100755 vagrant/.vagrant/machines/default/virtualbox/private_key delete mode 100755 vagrant/.vagrant/machines/default/virtualbox/synced_folders diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..997ca2f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vagrant \ No newline at end of file diff --git a/BuilderCompilerHandler.php b/BuilderCompilerHandler.php deleted file mode 100644 index a5a81bc..0000000 --- a/BuilderCompilerHandler.php +++ /dev/null @@ -1,301 +0,0 @@ -preproc = new PreprocessingHandler(); - $this->postproc = new PostprocessingHandler(); - $this->utility = new UtilityHandler(); - } - - /** - \brief Processes a compile request. - - \param string $request The body of the POST request. - \return A message to be JSON-encoded and sent back to the requestor. - */ - function main($request, $compiler_config) - { - - error_reporting(E_ALL & ~E_STRICT); - - $this->set_values($compiler_config, - $CC, $CPP, $AS, $LD, $CLANG, $OBJCOPY, $SIZE, $CFLAGS, $CPPFLAGS, $ASFLAGS, $LDFLAGS, $LDFLAGS_TAIL, - $CLANG_FLAGS, $OBJCOPY_FLAGS, $SIZE_FLAGS, $OUTPUT, $ARDUINO_CORES_DIR, $ARDUINO_SKEL); - - $start_time = microtime(true); - - - // Step 0: Reject the request if the input data is not valid. - //TODO: Replace $tmp variable name - $tmp = $this->requestValid($request); - if($tmp["success"] == false) - return $tmp; - - $this->set_variables($request, $format, $libraries, $version, $mcu, $f_cpu, $core, $variant, $vid, $pid); - - // Step 1: Extract the files included in the request. - $tmp = $this->extractFiles($request, $dir, $files); - if ($tmp["success"] == false) - return $tmp; - - - $tmp = $this->doCompile($files, $dir, $format); - if ($tmp["success"] == false) - return $tmp; - - if ($format == "syntax") - return array( - "success" => true, - "time" => microtime(true) - $start_time); - - $build_path = '/tmp/codebender_object_files'; - $tmp = $this->convertOutput($build_path, $format, $SIZE, "Blink Example.ino", $start_time); - return $tmp; - - - } - - - private function requestValid(&$request) - { - $request = $this->preproc->validate_input($request); - if (!$request) - return array( - "success" => false, - "step" => 0, - "message" => "Invalid input."); - else return array("success" => true); - } - - protected function extractFiles($request, &$dir, &$files) - { - // Create a temporary directory to place all the files needed to process - // the compile request. This directory is created in $TMPDIR or /tmp by - // default and is automatically removed upon execution completion. - $dir = "/tmp/compiler"; - - mkdir($dir); - - if (!$dir) - return array( - "success" => false, - "step" => 1, - "message" => "Failed to create temporary directory."); - - $response = $this->utility->extract_files($dir, $request->files); - if ($response["success"] === false) - return $response; - $files = $response["files"]; - - if (!file_exists($dir."/libraries")) - mkdir($dir."/libraries/", 0777, true); - //TODO: check if it succeeded - $files["libs"] = array(); - foreach($request->libraries as $library_name => $library_files) - { - //TODO: check if it succeeded - if (!file_exists($dir."/libraries".$library_name)) - mkdir($dir."/libraries/".$library_name, 0777, true); - $tmp = $this->utility->extract_files($dir."/libraries/".$library_name, $library_files); - $files["libs"][] = $tmp["files"]; - } - - return array("success" => true); - } - - - - protected function doCompile(&$files, $dir, $format) - { - $targets = '-hardware /home/vagrant/work/src/arduino.cc/builder/hardware -hardware /home/vagrant/arduino-nightly/hardware -hardware /home/vagrant/arduino-nightly/hardware/arduino/avr -hardware /home/vagrant/arduino-nightly/hardware/tools/avr -libraries /home/vagrant/arduino-nightly/libraries -libraries /home/vagrant/arduino-nightly/hardware/arduino/avr/libraries -tools /usr/bin/ -tools /home/vagrant/arduino-nightly/hardware/tools/avr/ -tools /home/vagrant/arduino-nightly/tools-builder/'; - $builder_compiler = '/home/vagrant/work/bin/builder'; - $build_path = '/tmp/codebender_object_files'; - - $targets = escapeshellarg($targets); - $builder_compiler = escapeshellarg($builder_compiler); - $build_path = escapeshellarg($build_path); - foreach (array("c", "cpp", "S","ino") as $ext) - { - foreach ($files[$ext] as $file) - { - // From hereon, $file is shell escaped and thus should only be used in calls - // to exec(). - $file = escapeshellarg($file); - exec("/home/vagrant/work/bin/builder -fqbn arduino:avr:uno -hardware /home/vagrant/work/src/arduino.cc/builder/hardware -hardware /home/vagrant/arduino-nightly/hardware -hardware /home/vagrant/arduino-nightly/hardware/arduino/avr -hardware /home/vagrant/arduino-nightly/hardware/tools/avr -libraries /home/vagrant/arduino-nightly/libraries -libraries /home/vagrant/arduino-nightly/hardware/arduino/avr/libraries -tools /usr/bin/ -tools /home/vagrant/arduino-nightly/hardware/tools/avr/ -tools /home/vagrant/arduino-nightly/tools-builder/ -build-path $build_path $file.$ext 2>&1", $output, $ret_compile); - - - if (isset($ret_compile) && $ret_compile) - { - return array( - "success" => false, - "step" => 4, - "message" => $output, - "debug" => $avr_output); - } - unset($output); - - $files["o"][] = array_shift($files[$ext]); - - } - } - - return array("success" => true); - } - - protected function convertOutput($dir, $format, $SIZE, $OUTPUT, $start_time) - { - if ($format == "elf") - { - $ret_objcopy = false; - //exec("$SIZE $SIZE_FLAGS --target=elf32-avr $dir/$OUTPUT.elf | awk 'FNR == 2 {print $1+$2}'", $size, $ret_size); // FIXME - $content = base64_encode(file_get_contents("$dir/$OUTPUT.elf")); - } - elseif ($format == "binary") - { - //exec("$OBJCOPY $OBJCOPY_FLAGS -O binary $dir/$OUTPUT.elf $dir/$OUTPUT.bin", $dummy, $ret_objcopy); - //exec("$SIZE $SIZE_FLAGS --target=binary $dir/$OUTPUT.bin | awk 'FNR == 2 {print $1+$2}'", $size, $ret_size); // FIXME - $content = base64_encode(file_get_contents("$dir/$OUTPUT.bin")); - } - elseif ($format == "hex") - { - //exec("$OBJCOPY $OBJCOPY_FLAGS -O ihex $dir/$OUTPUT.elf $dir/$OUTPUT.hex", $dummy, $ret_objcopy); - //exec("$SIZE $SIZE_FLAGS --target=ihex $dir/$OUTPUT.hex | awk 'FNR == 2 {print $1+$2}'", $size, $ret_size); // FIXME - $content = file_get_contents("$dir/$OUTPUT.hex"); - } - - // If everything went well, return the reply to the caller. - if ($ret_objcopy || $ret_size || $content === false) - return array( - "success" => false, - "step" => 8, - "message" => "There was a problem while generating the your binary file"); - else - return array( - "success" => true, - "time" => microtime(true) - $start_time, - "size" => $size[0], - "output" => $content); - - } - - private function preprocessIno(&$files, $ARDUINO_CORES_DIR, $ARDUINO_SKEL, $version, $core) - { - foreach ($files["ino"] as $file) - { - //TODO: make it compatible with non-default hardware (variants & cores) - if (!isset($skel) && ($skel = file_get_contents("$ARDUINO_CORES_DIR/v$version/hardware/arduino/cores/$core/$ARDUINO_SKEL")) === false) - return array( - "success" => false, - "step" => 2, - "message" => "Failed to open Arduino skeleton file."); - - $code = file_get_contents("$file.ino"); - $new_code = $this->preproc->ino_to_cpp($skel, $code, "$file.ino"); - $ret = file_put_contents("$file.cpp", $new_code); - - if ($code === false || !$new_code || !$ret) - return array( - "success" => false, - "step" => 2, - "message" => "Failed to preprocess file '$file.ino'."); - - $files["cpp"][] = array_shift($files["ino"]); - } - - return array("success" => true); - } - - public function preprocessHeaders(&$files, &$libraries, &$include_directories, $dir, $ARDUINO_CORES_DIR, $version, $core, $variant) - { - try - { - // Create command-line arguments for header search paths. Note that the - // current directory is added to eliminate the difference between <> - // and "" in include preprocessor directives. - //TODO: make it compatible with non-default hardware (variants & cores) - $include_directories = "-I$dir -I$ARDUINO_CORES_DIR/v$version/hardware/arduino/cores/$core -I$ARDUINO_CORES_DIR/v$version/hardware/arduino/variants/$variant"; - - //TODO: The code that rests on the main website looks for headers in all files, not just c, cpp and h. Might raise a security issue - $files["dir"] = array(); - foreach($libraries as $library_name => $library_files) - { - $files["dir"][] = $dir."/libraries/".$library_name; - } - - // Add the libraries' paths in the include paths in the command-line arguments - if (file_exists("$dir/utility")) - $include_directories .= " -I$dir/utility"; - foreach ($files["dir"] as $directory) - $include_directories .= " -I$directory"; - } - catch(\Exception $e) - { - return array("success" => false, "step" => 3, "message" => "Unknown Error:\n".$e->getMessage()); - } - - return array("success" => true); - } - private function set_values($compiler_config, - &$CC, &$CPP, &$AS, &$LD, &$CLANG, &$OBJCOPY, &$SIZE, &$CFLAGS, &$CPPFLAGS, - &$ASFLAGS, &$LDFLAGS, &$LDFLAGS_TAIL, &$CLANG_FLAGS, &$OBJCOPY_FLAGS, &$SIZE_FLAGS, - &$OUTPUT, &$ARDUINO_CORES_DIR, &$ARDUINO_SKEL) - { - // External binaries. - $CC = $compiler_config["cc"]; - $CPP = $compiler_config["cpp"]; - $AS = $compiler_config["as"]; - $LD = $compiler_config["ld"]; - $CLANG = $compiler_config["clang"]; - $OBJCOPY = $compiler_config["objcopy"]; - $SIZE = $compiler_config["size"]; - // Standard command-line arguments used by the binaries. - $CFLAGS = $compiler_config["cflags"]; - $CPPFLAGS = $compiler_config["cppflags"]; - $ASFLAGS = $compiler_config["asflags"]; - $LDFLAGS = $compiler_config["ldflags"]; - $LDFLAGS_TAIL = $compiler_config["ldflags_tail"]; - $CLANG_FLAGS = $compiler_config["clang_flags"]; - $OBJCOPY_FLAGS = $compiler_config["objcopy_flags"]; - $SIZE_FLAGS = $compiler_config["size_flags"]; - // The default name of the output file. - $OUTPUT = $compiler_config["output"]; - // Path to arduino-core-files repository. - $ARDUINO_CORES_DIR = $compiler_config["arduino_cores_dir"]; - // The name of the Arduino skeleton file. - $ARDUINO_SKEL = $compiler_config["arduino_skel"]; - } - - private function set_variables($request, &$format, &$libraries, &$version, &$mcu, &$f_cpu, &$core, &$variant, &$vid, &$pid) - { - // Extract the request options for easier access. - $format = $request->format; - $libraries = $request->libraries; - $version = $request->version; - $mcu = $request->build->mcu; - $f_cpu = $request->build->f_cpu; - $core = $request->build->core; - $variant = $request->build->variant; - - // Set the appropriate variables for vid and pid (Leonardo). - $vid = ($variant == "leonardo") ? $request->build->vid : ""; - $pid = ($variant == "leonardo") ? $request->build->pid : ""; - } - -} diff --git a/vagrant/Vagrantfile b/Vagrantfile old mode 100755 new mode 100644 similarity index 95% rename from vagrant/Vagrantfile rename to Vagrantfile index c1653dc..93a0c4f --- a/vagrant/Vagrantfile +++ b/Vagrantfile @@ -45,7 +45,7 @@ Vagrant.configure(2) do |config| # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine - vb.gui = true + # vb.gui = true # # # Customize the amount of memory on the VM: vb.memory = "2048" @@ -66,6 +66,6 @@ Vagrant.configure(2) do |config| # documentation for more information about their specific syntax and use. config.vm.provision "shell", inline: <<-SHELL sudo apt-get update - sudo apt-get install -y apache2 + #sudo apt-get install -y apache2 SHELL end diff --git a/modified-files/CompilerBundle/Controller/DefaultController.php b/modified-files/CompilerBundle/Controller/DefaultController.php new file mode 100644 index 0000000..e30cda1 --- /dev/null +++ b/modified-files/CompilerBundle/Controller/DefaultController.php @@ -0,0 +1,180 @@ + true, "status" => "OK"))); + } + + public function testAction($authorizationKey) + { + $params = $this->generateParameters(); + + if ($authorizationKey !== $params["authorizationKey"]) + { + return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid authorization key."))); + } + + set_time_limit(0); // make the script execution time unlimited (otherwise the request may time out) + + // change the current Symfony root dir + chdir($this->get('kernel')->getRootDir()."/../"); + + //TODO: replace this with a less horrible way to handle phpunit + exec("phpunit -c app --stderr 2>&1", $output, $return_val); + + return new Response(json_encode(array("success" => (bool) !$return_val, "message" => implode("\n", $output)))); + } + + public function indexAction($authorizationKey, $version) + { + $params = $this->generateParameters(); + + if ($authorizationKey !== $params["authorizationKey"]) + { + return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid authorization key."))); + } + + if ($version == "v1") + { + $request = $this->getRequest()->getContent(); + + //Get the compiler service + /** @var CompilerHandler $compiler */ + $compiler = $this->get('builder_compiler_handler'); + + $reply = $compiler->main($request, $params); + + return new Response(json_encode($reply)); + } + else + { + return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid API version."))); + } + } + + public function deleteAllObjectsAction($authorizationKey, $version) + { + if ($this->container->getParameter('authorizationKey') != $authorizationKey) { + return new Response(json_encode( + array('success' => false, 'step' => 0, 'message' => 'Invalid authorization key.') + )); + } + + if ($version != 'v1') { + return new Response(json_encode( + array('success' => false, 'step' => 0, 'message' => 'Invalid API version.') + )); + } + + //Get the compiler service + /** @var DeletionHandler $deleter */ + $deleter = $this->get('deletion_handler'); + + $response = $deleter->deleteAllObjects(); + + if ($response['success'] !== true) { + return new Response(json_encode( + array('success' => false, 'step' => 0, 'message' => 'Failed to access object files directory.') + )); + } + + return new Response(json_encode( + array_merge( + array( + 'success' => true, + 'message' => 'Object files deletion complete. Found ' . $response['fileCount'] . ' files.' + ), + $response['deletionStats'], + array("Files not deleted" => $response['notDeletedFiles']) + ))); + } + + public function deleteSpecificObjectsAction($authorizationKey, $version, $option, $cachedObjectToDelete) + { + if ($this->container->getParameter('authorizationKey') != $authorizationKey) { + return new Response(json_encode( + array('success' => false, 'step' => 0, 'message' => 'Invalid authorization key.') + )); + } + + if ($version != 'v1') { + return new Response(json_encode( + array('success' => false, 'step' => 0, 'message' => 'Invalid API version.') + )); + } + + //Get the compiler service + /** @var DeletionHandler $deleter */ + $deleter = $this->get('deletion_handler'); + + $response = $deleter->deleteSpecificObjects($option, $cachedObjectToDelete); + + if ($response['success'] !== true) { + return new Response(json_encode( + array('success' => false, 'step' => 0, 'message' => 'Failed to access object files directory.') + )); + } + + if (!empty($response["notDeletedFiles"])) { + $message = 'Failed to delete one or more of the specified core object files.'; + if ($option == 'library') { + $message = 'Failed to delete one or more of the specified library object files.'; + } + + return new Response(json_encode( + array_merge(array('success' => false, 'step' => 0, 'message' => $message), $response) + )); + } + + $message = 'Core object files deleted successfully.'; + if ($option == 'library'){ + $message = 'Library deleted successfully.'; + } + + return new Response(json_encode(array_merge(array('success' => true, 'message' => $message), $response))); + } + + /** + * \brief Creates a list of the configuration parameters to be used in the compilation process. + * + * \return An array of the parameters. + * + * This function accesses the Symfony global configuration parameters, and creates an array that our handlers (which + * don't have access to them) can use them. + + */ + private function generateParameters() + { + $parameters = array("binutils", "python", "clang", "logdir", "temp_dir", "archive_dir", "autocompletion_dir", "autocompleter", "cflags", "cppflags", "asflags", "arflags", "ldflags", "ldflags_tail", "clang_flags", "objcopy_flags", "size_flags", "output", "arduino_cores_dir", "external_core_files", "authorizationKey"); + + $compiler_config = array(); + + foreach ($parameters as $parameter) + { + $compiler_config[$parameter] = $this->container->getParameter($parameter); + } + + return $compiler_config; + } + +} diff --git a/modified-files/CompilerBundle/Handler/BuilderCompilerHandler.php b/modified-files/CompilerBundle/Handler/BuilderCompilerHandler.php new file mode 100644 index 0000000..ea8857f --- /dev/null +++ b/modified-files/CompilerBundle/Handler/BuilderCompilerHandler.php @@ -0,0 +1,262 @@ +preproc = $preprocHandl; + $this->postproc = $postprocHandl; + $this->utility = $utilHandl; + $this->compiler_logger = $logger; + $this->object_directory = $objdir; + } + + + function main($request, $compiler_config) + { + + error_reporting(E_ALL & ~E_STRICT); + + + $start_time = microtime(true); + + // Step 0: Reject the request if the input data is not valid. + $tmp = $this->requestValid($request); + if($tmp["success"] == false) + return $tmp; + + $this->setVariables($request, $format, $libraries, $version, $mcu, $f_cpu, $core, $variant, $vid, $pid, $compiler_config); + + $TEMP_DIR = $compiler_config["temp_dir"]; + + // Step 1: Extract the files and filenames included in the request. + $filenames = array(); + + foreach ($request["files"] as $file) + array_push($filenames, $file["filename"]); + + + + $files = array(); + $tmpVar = $this->extractFiles($request["files"], $TEMP_DIR, $compiler_dir, $files["sketch_files"], "files"); + if ($tmp["success"] == false) + return $tmp; + + if (!array_key_exists("archive", $request) || ($request["archive"] !== false && $request["archive"] !== true)) + $ARCHIVE_OPTION = false; + else + $ARCHIVE_OPTION = $request["archive"]; + + if ($ARCHIVE_OPTION === true) + { + $arch_ret = $this->createArchive($compiler_dir, $TEMP_DIR, $ARCHIVE_DIR, $ARCHIVE_PATH); + if ($arch_ret["success"] === false) + return $arch_ret; + } + + + $tmp = $this->doCompile($files["sketch_files"], $compiler_dir, $format, $version, $mcu, $f_cpu, $core, $variant, $pid, $vid); + if ($tmp["success"] == false) + return $tmp; + + + + if ($format == "syntax") + return array( + "success" => true, + "time" => microtime(true) - $start_time); + + + $tmp = $this->convertOutput($compiler_dir, $format, $SIZE, $filenames , $start_time); + return $tmp; + + + } + + protected function convertOutput($dir, $format, $SIZE, $filenames, $start_time) + { + $OUTPUT = $filenames[0]; + // To Do, Handle multiple files than just one. + + if ($format == "elf") + { + $ret_objcopy = false; + $content = base64_encode(file_get_contents("$dir/$OUTPUT.elf")); + $size = filesize("$dir/$OUTPUT.elf"); + } + elseif ($format == "binary") + { + $content = base64_encode(file_get_contents("$dir/$OUTPUT.hex")); + $size = filesize("$dir/$OUTPUT.hex"); + } + elseif ($format == "hex") + { + $content = file_get_contents("$dir/$OUTPUT.hex"); + $size = filesize("$dir/$OUTPUT.hex"); + } + elseif ($format == "object") + { + + $content = base64_encode(file_get_contents("$dir/sketch/$OUTPUT.cpp.o")); + $size = filesize("$dir/sketch/$OUTPUT.cpp.o"); + } + + // If everything went well, return the reply to the caller. + if ($ret_objcopy || $content === false) + return array( + "success" => false, + "step" => 8, + "message" => "There was a problem while generating the your binary file for $dir/sketch/$OUTPUT.cpp.o"); + else + return array( + "success" => true, + "time" => microtime(true) - $start_time, + "size" => $size, + "output" => $content); + + } + private function requestValid(&$request) + { + $request = $this->preproc->validateInput($request); + if (!$request) + return array( + "success" => false, + "step" => 0, + "message" => "Invalid input."); + else return array("success" => true); + } + + private function extractFiles($request, $temp_dir, &$dir, &$files, $suffix, $lib_extraction = false) + { + // Create a temporary directory to place all the files needed to process + // the compile request. This directory is created in $TMPDIR or /tmp by + // default and is automatically removed upon execution completion. + + $cnt = 0; + + if (!$dir) + do + { + $dir = @System::mktemp(" -t $temp_dir/ -d compiler"); + $cnt++; + } while (!$dir && $cnt <= 2); + + if (!$dir) + return array( + "success" => false, + "step" => 1, + "message" => "Failed to create temporary directory."); + + $response = $this->utility->extractFiles("$dir/$suffix", $request, $lib_extraction); + + if ($response["success"] === false) + return $response; + $files = $response["files"]; + + return array("success" => true); + } + + + protected function doCompile(&$files, $dir, $format, $version, $mcu, $f_cpu, $core, $variant, $pid, $vid) + { + $hardware = "-hardware /opt/codebender/arduino-core-files/v1.6.6/hardware -hardware /opt/codebender/arduino-core-files/v1.6.6/hardware/arduino"; + $tools = "-tools /opt/arduino-builder/tools-builder -tools /opt/codebender/arduino-core-files/v1.6.6/hardware/tools/avr"; + $libraries = "-libraries /opt/codebender/arduino-core-files/v1.6.6/libraries"; + $build_path = "-build-path $dir"; + + if(!file_exists($dir)) + mkdir($dir); + + $prefs = "-prefs mcu=$mcu -prefs f_cpu=$f_cpu -prefs core=$core -prefs variant=$variant "; + + // If pid and vid build preferences were specified + if($pid != "") + $prefs = $prefs."-prefs pid=$pid "; + + if($vid != "") + $prefs = $prefs."-prefs vid=$vid "; + + $hardware = stripslashes($hardware); + $tools = stripslashes($tools); + $libraries = stripslashes($libraries); + $build_path = stripslashes($build_path); + $prefs = stripslashes($prefs); + + foreach (array("c", "cpp", "S","ino") as $ext) + { + foreach ($files[$ext] as $file) + { + // From hereon, $file is shell escaped and thus should only be used in calls + // to exec(). + $file = escapeshellarg($file); + + exec("/opt/arduino-builder/arduino-builder -fqbn arduino:avr:uno $hardware $tools $libraries $prefs $build_path $file.$ext 2>&1", $output, $ret_compile); + + + + if (isset($ret_compile) && $ret_compile) + { + return array( + "success" => false, + "step" => 4, + "message" => $output, + "debug" => $ret_compile); + } + unset($output); + + $files["o"][] = array_shift($files[$ext]); + + } + } + + return array("success" => true); + } + + + private function setVariables($request, &$format, &$libraries, &$version, &$mcu, &$f_cpu, &$core, &$variant, &$vid, &$pid, &$compiler_config) + { + // Extract the request options for easier access. + $format = $request["format"]; + $libraries = $request["libraries"]; + $version = $request["version"]; + $mcu = $request["build"]["mcu"]; + $f_cpu = $request["build"]["f_cpu"]; + $core = $request["build"]["core"]; + // Some cores do not specify any variants. In this case, set variant to be an empty string + if (!array_key_exists("variant", $request["build"])) + $variant = ""; + else + $variant = $request["build"]["variant"]; + + if ($format == "autocomplete") + { + $compiler_config["autocmpfile"] = $request["position"]["file"]; + $compiler_config["autocmprow"] = $request["position"]["row"]; + $compiler_config["autocmpcol"] = $request["position"]["column"]; + $compiler_config["autocmpmaxresults"] = 500; + $compiler_config["autocmpprefix"] = $request["prefix"]; + } + + // Set the appropriate variables for vid and pid (Leonardo). + + $vid = (isset($request["build"]["vid"])) ? $request["build"]["vid"] : "null"; + $pid = (isset($request["build"]["pid"])) ? $request["build"]["pid"] : "null"; + } +} diff --git a/modified-files/CompilerBundle/Resources/config/routing.yml b/modified-files/CompilerBundle/Resources/config/routing.yml new file mode 100644 index 0000000..bb0f875 --- /dev/null +++ b/modified-files/CompilerBundle/Resources/config/routing.yml @@ -0,0 +1,27 @@ +codebender_compiler_status_check: + pattern: /status + defaults: { _controller: CodebenderCompilerBundle:Default:status } + +codebender_compiler_test: + pattern: /{authorizationKey}/test/ + defaults: { _controller: CodebenderCompilerBundle:Default:test } + +codebender_compiler_homepage: + pattern: /{authorizationKey}/{version} + defaults: { _controller: CodebenderCompilerBundle:Default:index } + +codebender_compiler_delete_all: + pattern: /{authorizationKey}/{version}/delete/all/ + defaults: { _controller: CodebenderCompilerBundle:Default:deleteAllObjects } + +codebender_compiler_delete_specific: + pattern: /{authorizationKey}/{version}/delete/{option}/{cachedObjectToDelete} + defaults: { _controller: CodebenderCompilerBundle:Default:deleteSpecificObjects } + +# redirecting the root +root: + path: / + defaults: + _controller: FrameworkBundle:Redirect:urlRedirect + path: /status + permanent: true diff --git a/modified-files/CompilerBundle/Resources/config/services.yml b/modified-files/CompilerBundle/Resources/config/services.yml new file mode 100644 index 0000000..6a9ac30 --- /dev/null +++ b/modified-files/CompilerBundle/Resources/config/services.yml @@ -0,0 +1,36 @@ +parameters: +# codebender_compiler.example.class: Codebender\CompilerBundle\Example + buildercompiler_handler.class: Codebender\CompilerBundle\Handler\BuilderCompilerHandler + compiler_handler.class: Codebender\CompilerBundle\Handler\CompilerHandler + utility_handler.class: Codebender\CompilerBundle\Handler\UtilityHandler + preprocessing_handler.class: Codebender\CompilerBundle\Handler\PreprocessingHandler + postprocessing_handler.class: Codebender\CompilerBundle\Handler\PostprocessingHandler + deletion_handler.class: Codebender\CompilerBundle\Handler\DeletionHandler + +services: +# codebender_compiler.example:- +# class: %codebender_compiler.example.class% +# arguments: [@service_id, "plain_value", %parameter%] + buildercompiler_handler: + class: "%buildercompiler_handler.class%" + arguments: ["@preprocessing_handler", "@postprocessing_handler", "@utility_handler", "@compiler_logger", "%temp_dir%/%objdir%"] + compiler_handler: + class: "%compiler_handler.class%" + arguments: ["@preprocessing_handler", "@postprocessing_handler", "@utility_handler", "@compiler_logger", "%temp_dir%/%objdir%"] + utility_handler: + class: "%utility_handler.class%" + preprocessing_handler: + class: "%preprocessing_handler.class%" + postprocessing_handler: + class: "%postprocessing_handler.class%" + deletion_handler: + class: "%deletion_handler.class%" + arguments: ["%temp_dir%/%objdir%"] + compiler_logger: + class: Symfony\Bridge\Monolog\Logger + arguments: [cmplr_log] + calls: + - [pushHandler, [@compiler_log_handler]] + compiler_log_handler: + class: Monolog\Handler\StreamHandler + arguments: [%kernel.logs_dir%/compiler.log] diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..b8a94fa --- /dev/null +++ b/setup.sh @@ -0,0 +1,16 @@ +cd /home/vagrant +sudo apt-get install git +git clone https://github.com/codebendercc/compiler.git +cp -r /vagrant/modified-files/CompilerBundle/ compiler/Symfony/src/Codebender/ +cd /home/vagrant/compiler/ +./scripts/install.sh +cd /home/vagrant +wget http://arduino.cc/download.php?f=/arduino-1.6.6-linux64.tar.xz -O arduino-1.6.6.tar.xz +tar -xJf arduino-1.6.6.tar.xz +sudo mkdir /opt/codebender/arduino-core-files +sudo mkdir /opt/codebender/arduino-core-files/v1.6.6 +sudo cp -r arduino-1.6.6/hardware /opt/codebender/arduino-core-files/v1.6.6/ +sudo cp -r arduino-1.6.6/libraries /opt/codebender/arduino-core-files/v1.6.6/ +sudo mkdir /opt/arduino-builder +sudo cp -r arduino-1.6.6/tools-builder /opt/arduino-builder/ +sudo cp -r arduino-1.6.6/arduino-builder /opt/arduino-builder/ \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/action_provision b/vagrant/.vagrant/machines/default/virtualbox/action_provision deleted file mode 100755 index 95e57e1..0000000 --- a/vagrant/.vagrant/machines/default/virtualbox/action_provision +++ /dev/null @@ -1 +0,0 @@ -1.5:4f2169c0-47c5-4bce-9859-58fda0f7a877 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/action_set_name b/vagrant/.vagrant/machines/default/virtualbox/action_set_name deleted file mode 100755 index f995fa2..0000000 --- a/vagrant/.vagrant/machines/default/virtualbox/action_set_name +++ /dev/null @@ -1 +0,0 @@ -1445846899 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/creator_uid b/vagrant/.vagrant/machines/default/virtualbox/creator_uid deleted file mode 100755 index c227083..0000000 --- a/vagrant/.vagrant/machines/default/virtualbox/creator_uid +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/id b/vagrant/.vagrant/machines/default/virtualbox/id deleted file mode 100755 index c5cb3ad..0000000 --- a/vagrant/.vagrant/machines/default/virtualbox/id +++ /dev/null @@ -1 +0,0 @@ -4f2169c0-47c5-4bce-9859-58fda0f7a877 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/index_uuid b/vagrant/.vagrant/machines/default/virtualbox/index_uuid deleted file mode 100755 index 78d5735..0000000 --- a/vagrant/.vagrant/machines/default/virtualbox/index_uuid +++ /dev/null @@ -1 +0,0 @@ -b2d9f07d2f6d42afbd0db6752774cf06 \ No newline at end of file diff --git a/vagrant/.vagrant/machines/default/virtualbox/private_key b/vagrant/.vagrant/machines/default/virtualbox/private_key deleted file mode 100755 index ba45790..0000000 --- a/vagrant/.vagrant/machines/default/virtualbox/private_key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAlqo2QzmjtMBEUMgCa0URlEnf0+PFYcX8G6xRQFtixOjfGX57 -4KhXkwLbO55vnytjGUjAbME7qvcUJqQlSaCYFjEpa66c4Li9Hx8fM0AZoLyeaT1s -QH90FLvHlg61gysd5cXjmjAlgzHa/R/M++3deQlfgG8RxkkNPGv99dojlhDH2yXI -TFXxVNeY5R0ohRIWxJBMCu01kXaM8t7uUavSomLm1UeLIHCuR33Bb4PJcI3aCgGM -StySyxne+vvSAl0Y1QnyShmLrUyhE4QfyqceKwNSuP9aA7YgrqafbTq12tc6Bqf+ -RlLZjtUQVGpiMZia+joLSgVt91rxSZhHGhrE2wIDAQABAoIBAQCQfEE3bNJKp8ub -8IMpXf5CyCmnaRpD7nscCr+MyVbJ4Uz6hOrFgoshR6742LLQ4OnTOIqYgSL4jKQ9 -flLn7eOL/K9tPfHiLCfp7Y2dN46cL+Z2pFno7JFkxMPdatO1K6crUAA6QIvo6enJ -rzKEMxOeXFfCskFId4wC8smEeSKBaLObVum7EKAlYbAqyfUHhQmaRsosXMo22BiW -U7QSaNpaYg5s/wNhDY6dSz696T5CoqhWTOdJcZaKccxKN6/cGhYM3/JzyHKk/tKp -2I4zk0YLKHomd2lhcxJGBCdshxiXZUaqKh4pRQoLbLcAJ/e5JY8Vka9ud9yhXlIH -MQ4MKhDRAoGBAMbBpKrAr2RR25k5+Gw6IGWRzC6MunmBeGlPoes0UcGNeVI3y8wg -5I8z0cC7tllz0adAUhqurBQOAk4jvTpM4e9xyBiRzfIVR3nrmwrd0B1fvRKDYyJN -Sh3+q6m6LETSClx2mEG/re62asj3sG5mEwB+7zbIKdfXAjOH+ewPejYjAoGBAMIO -xOskpQjjMHCLbK+tCj/Uh5v3h0O4OqdfhfqUqnlHVnBlREAi7Yr0Gs+5kwjP6+mg -1naS8ZNYWMvEvWN+paxx4mFT6yKqSnTqamhKvA5V+pW0BG/BzxPHSBr8wG8kczaA -HqB+Ax06yhBN9wwtUtue3no6HURrhM3ZALcysPXpAoGAKnSMpwi3rlcp8EYIwZ18 -9BU7pynaXz//p4ciECrB1/VPV/ehKb5Q9CHeiSvPnLX3r6E2qIptKW+AoI5TylNH -46zLUCw88JwJA4sHOD//R3b+3SiBkX8u+M9AfeXNtPmkyvFuPoUiMx52Gu2Fm19k -abOzh2EkRv2fc8B06y63LT8CgYBgYoOOI3JRGr6Jd8aw7uqDT6VXYzds/EktrrVW -A5c0i6k0RCgFDxQbCylx+UM9gkAzly5OUKfqPlxEQWCr1VCmeR4up0bHvfsjXPci -+9Ox7yR6TKJTe9jFgxqeROGzklAjRrlvj4cucm/Ab2kARFa+PIdWAB1fSWP59glz -9JqOWQKBgQCLptHSG681HMUIOgjibaAE/W2YVYSN7ePrpy7vMWB6UuETccFm13DE -daN6+0swcW4HRPslCOKMPJ59zkPk6p+W93DRq2Stoob8IrKLbOItCoMGG89uQWEU -0QtW8ctbPO2L/Gi348eEdGpWsq49ci9qbFN02jh3LV868fTjsPpvZA== ------END RSA PRIVATE KEY----- diff --git a/vagrant/.vagrant/machines/default/virtualbox/synced_folders b/vagrant/.vagrant/machines/default/virtualbox/synced_folders deleted file mode 100755 index 39695eb..0000000 --- a/vagrant/.vagrant/machines/default/virtualbox/synced_folders +++ /dev/null @@ -1 +0,0 @@ -{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"C:/Users/Arturo/Documents/Computer-Engineer/vargant","disabled":false}}} \ No newline at end of file From d00c4bbd71c5b7bb0e18804fb9e621e34e84d5ec Mon Sep 17 00:00:00 2001 From: asandrad22 Date: Fri, 27 Nov 2015 21:47:36 +0000 Subject: [PATCH 3/4] Edit README.md with instructions on how to setup API. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 533e169..9f2bd77 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ # arduino-builder-service + +To setup arduino-builder-service Vagrant up the machine. Once in the machine +/vagrant/setup.sh + From c2c96a26c1f1c30268ecb4099d61c9c2de99256e Mon Sep 17 00:00:00 2001 From: asandrad22 Date: Fri, 4 Dec 2015 10:33:10 +0000 Subject: [PATCH 4/4] Modified to reflect setup for Arduino-Builder-Service --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f2bd77..427c587 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,19 @@ # arduino-builder-service -To setup arduino-builder-service Vagrant up the machine. Once in the machine -/vagrant/setup.sh +Arduino Builder Service modifies codebender/compiler to compile skits with arduino-builder. As of now Arduino Builder Service compiles for version 166 for Arduino 1.6.6. +## Setup Arduino Builder Service with Vagrant +Install [Vagrant](https://www.vagrantup.com/downloads.html) on your machine. + +Next, copy the code into any directory. `git clone https://github.com/codebendercc/arduino-builder-service.git` +Go into the directory with the code and `vagrant up` +SSH into the virtual machine using +``` +host: localhost +port: 2222 +username: vagrant +password: vagrant + +``` +Finally, set up the virtual machine by running `/vagrant/setup.sh` +To test if it work run `curl https://localhost/status` should return {"success":true,"status":"OK"}.