Let's say I'm writing a recipe and would like disable for debugging e.g. do_compile, how can I achieve that? The recipe in question is compiling a C library.
I tried a few things such as overwriting:
do_compile() {
pass
}
and leaving the function empty. But this did not skip the compilation.
You can always use:
do_compile[noexec] = "1"
See https://www.yoctoproject.org/docs/3.0/mega-manual/mega-manual.html#deleting-a-task
While writing this question I found the answer myself: Add a return statement:
do_compile() {
return
# following compilation will not be seen by bitbake
}
Hope this will help others.
Related
I face the following problem when using SBT. If I add this line to build.sbt:
unmanagedResourceDirectories in Compile <+= baseDirectory( _ / "src/main/scala" )
Incremental compilation breaks in a very tricky and not-nice way. A full example on how to reproduce the bug is here: https://github.com/vn971/sbt-incremental-bug
It's basically 2 files. Implicits.scala:
object MyImplicits {
implicit def stringToInt(str: String) = 1
}
And Usage.scala:
import MyImplicits._
object MyUsage {
def a: Int = ""
}
Now, in order to reproduce the incremental compilation bug, you have to do consequent changes to these files:
comment out the method in Usage.scala. Save file, re-compile.
uncomment it, save and re-compile.
comment out the method in Implicits.scala. Save file, re-compile.
Since MyImplicits.stringToInt is undoubtedly used in Usage.scala, it should not compile. But it does, with incremental compilation.
Thoughts? Questions? If you need more details than already provided, check out the minimalistic project I've linked to.
I have
val str = s"""/bin/bash -c 'some command'"""
job = Some(str.!!)
It is meant to execute the bash command I assume.
Can someone explain this syntax?
Googling for '.!!' doesn't help much neither does 'dot exclamation exclamation' so I hope someone can explain this one and/or point me to the doc.
The job doesn't run and I'm trying to debug the code, but when i put this in a
try {
command = Some(str.!!)
}
catch {
case e:Exception =>
println(e.toString)
}
e is actually not an Exception for some reason...
Trying to figure what this really does and how to find what is happening.
There is an implicit conversion from String to ProcessBuilder. When you import scala.sys.process._ then scala will automatically perform the conversion when needed, thus making the method !! available on String instances. You can find the methods of ProcessBuilder here: http://www.scala-lang.org/api/current/index.html#scala.sys.process.ProcessBuilder
The documentation for !! says that "If the exit code is non-zero, an exception is thrown." It appears that bash in this case does return 0, so the command was for some reason successful.
How do you provide help for custom commands in sbt?
I want to display said help in case the args I have set are wrong (like putting a string in a number arg)
I also want to display the help if help <myCommand> is typed.
Any clues? The documentation doesn't say anything about it:
http://www.scala-sbt.org/0.12.4/docs/Extending/Commands.html
And google doesn't help either.
Thanks.
According to the documentation, help should work on Commands. But you need to define your Command correctly using one of the methods in Command.scala, e.g.
commands += Command.command("foo", "bar", "baz")(...)
then
> foo<TAB>
bar
> help foo
baz
For the benefit of anybody wanting to do the same for Task, here's an answer...
The help input task is what you want users to type, e.g.
> help compile
Compiles sources.
and to provide the documentation string, you provide it when you define the key to your Task. e.g.
val compile = TaskKey[CompileAnalysis]("compile", "Compiles sources.", APlusTask)
Later on you assign the key to the implementation of the Task, like so
compile <<= compileTask
or using the new macro based API (which I detest)
compile := { println("hello world") ; compile.value }
Lots of examples in
https://github.com/sbt/sbt/blob/1.0.x/main/src/main/scala/sbt/Keys.scala
https://github.com/sbt/sbt/blob/1.0.x/main/src/main/scala/sbt/Defaults.scala
Why doesn't eclipse show an error when I use a variable without declaring it?
Edit:
AFAIK dynamic nature only means that type of variable is not known until run time. The variables must still be defined (explicitly or implicitly) before being used. For example - Python which is also a dynamic language reports this as an error.
Edit2:
How does groovy interpret this code so that it still isn't an error?
Because in dynamic languages like groovy, one could have implemented methodMissing() / propertyMissing(). So although such variable or method does not actually exist, it may be still not be an errors until the program is actually run. Such errors can usually only be detected at runtime and hence IDE's usually don't complain about it.
Although to hint you, eclipse is underlining such variables there which it is not able to statically reference.
EDIT :
To explain the concept by code example, just check the method test below. Now IDE can't know that something , that ... can actually be a method in this class.
This vastly helps in building DSLs in groovy.
class TestClass {
def test() {
def a = something.that.didnt.exist()
or how about some random statements that make no sense at all
a = ew Parser().doSomething() ew blah blah blah
}
def propertyMissing(String name) { println "$name"; return this }
def methodMissing(String name, args) { println "$name with $args"; return this }
}
new TestClass().test()
I think you may try to use #CompileStatic tag on method.
Then Eclipse will compile and check errors at compile time or in develop time.
I haven't Eclipse to check this now, so this is just for a proposal.
What is the difference between a scala script and scala application? Please provide an example
The book I am reading says that a script must always end in a result expression whereas the application ends in a definition. Unfortunately no clear example is shown.
Please help clarify this for me
I think that what the author means is that a regular scala file needs to define a class or an object in order to work/be useful, you can't use top-level expressions (because the entry-points to a compiled file are pre-defined). For example:
println("foo")
object Bar {
// Some code
}
The println statement is invalid in the top-level of a .scala file, because the only logical interpretation would be to run it at compile time, which doesn't really make sense.
Scala scripts in contrast can contain expressions on the top-level, because those are executed when the script is run, which makes sense again. If a Scala script file only contains definitions on the other hand, it would be useless as well, because the script wouldn't know what to do with the definitions. If you'd use the definitions in some way, however, that'd be okay again, e.g.:
object Foo {
def bar = "test"
}
println(Foo.bar)
The latter is valid as a scala script, because the last statement is an expression using the previous definition, but not a definition itself.
Comparison
Features of scripts:
Like applications, scripts get compiled before running. Actually, the compiler translates scripts to applications before compiling, as shown below.
No need to run the compiler yourself - scala does it for you when you run your script.
Feeling is very similar to script languages like bash, python, or ruby - you directly see the results of your edits, and get a very quick debug cycle.
You don't need to provide a main method, as the compiler will add one for you.
Scala scripts tend to be useful for smaller tasks that can be implemented in a single file.
Scala applications on the other hand, are much better suited when your projects start to grow more complex. They allow to split tasks into different files and namespaces, which is important for maintaining clarity.
Example
If you write the following script:
#!/usr/bin/env scala
println("foo")
Scala 2.11.1 compiler will pretend (source on github) you had written:
object Main {
def main(args: Array[String]): Unit =
new AnyRef {
println("foo")
}
}
Well, I always thought this is a Scala script:
$ cat script
#!/usr/bin/scala
!#
println("Hello, World!")
Running with simple:
$ ./script
An application on the other hand has to be compiled to .class and executed explicitly using java runtime.