Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect mcu script transformation #101

Closed
galpeter opened this issue May 26, 2015 · 4 comments
Closed

Incorrect mcu script transformation #101

galpeter opened this issue May 26, 2015 · 4 comments
Labels
bug Undesired behaviour infrastructure Related to GH Actions or the tested targets

Comments

@galpeter
Copy link
Contributor

By using the tools/generator.sh we transform a js file to a JERRY_MCU_SCRIPT define. However there is a problem, take the following input mcu.js file:

var a = 2 * 2;

Executing the tools/generator.sh mcu.js output command will result the following content in the output file:

#define JERRY_MCU_SCRIPT \
"var a = 2 build CMakeLists.txt jerry-core jerry-libc LICENSE main-linux.cpp main-mcu.cpp main-nuttx.cpp Makefile mcu.js out plugins README.md tests third-party tools 2;\n" \

which clearly can't be used as a start js script.

@galpeter
Copy link
Contributor Author

For this there is two solutions:

  1. enclose the variable used during the transformation:
diff --git a/tools/generator.sh b/tools/generator.sh
index e020fe0..66c0754 100755
--- a/tools/generator.sh
+++ b/tools/generator.sh
@@ -17,7 +17,7 @@
 echo "#define JERRY_MCU_SCRIPT \\" > $2
 cat $1 | while read line
 do
-  line=$(echo $line | sed 's/"/\\"/g')
+  line=$(echo "$line" | sed 's/"/\\"/g')
   echo "\"$line\n\" \\" >> $2
 done
 echo >> $2
  1. Rewrite the whole thing with sed:
diff --git a/tools/generator.sh b/tools/generator.sh
index e020fe0..ee0ff47 100755
--- a/tools/generator.sh
+++ b/tools/generator.sh
@@ -15,9 +15,5 @@
 # limitations under the License.

 echo "#define JERRY_MCU_SCRIPT \\" > $2
-cat $1 | while read line
-do
-  line=$(echo $line | sed 's/"/\\"/g')
-  echo "\"$line\n\" \\" >> $2
-done
+sed 's/"/\\"/g' $1 | sed 's/^.*$/"\0" \\/g' >> $2
 echo >> $2

There will be a bit difference in the 2nd case as it will leave any trailing/leading whitespaces intact.

Which solution would be better?

@ruben-ayrapetyan
Copy link
Contributor

@galpeter ,
it seems that leaving whitespaces exactly as they were in source script is better.

@egavrin egavrin added this to the Core ECMA features milestone May 27, 2015
@egavrin egavrin added bug Undesired behaviour infrastructure Related to GH Actions or the tested targets labels May 27, 2015
@egavrin
Copy link
Contributor

egavrin commented May 27, 2015

BTW, if someone can propose the better solution than usage of this script, I'd prefer it.

@egavrin
Copy link
Contributor

egavrin commented Jun 19, 2015

Fix is merged as #200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Undesired behaviour infrastructure Related to GH Actions or the tested targets
Projects
None yet
Development

No branches or pull requests

3 participants