Why [SUBDIRS+=] always work int equals area? - qt

I use equals a value to add different subdirs, only sub1 will build. but why all subdirs will show in left projects view
TEMPLATE = subdirs
TEST_VALUE = 1
equals(TEST_VALUE,1) {
message($$TEST_VALUE)
SUBDIRS += \
sub1
}
equals(TEST_VALUE,2) {
message($$TEST_VALUE)
SUBDIRS += \
sub2
}
equals(TEST_VALUE,3) {
message($$TEST_VALUE)
SUBDIRS += \
sub3
}
I tried looking in the build directory and only sub1 was built, which is correct. Also printing the TEST_VALUE value inside the judgment, also only 1 was printed, which is also correct. But I still can't understand why the project view on the left shows all subdirs

Related

Where is qtRunLoggedCommand defined?

I often see the calling of qtRunLoggedCommand in Qt project files but cannot find where it is defined. Can anybody provide a link to the document of this function or let me know where the function is defined in the source code? Thanks!
The function is defined in qtbase/mkspecs/features/configure_base.prf:
defineTest(qtRunLoggedCommand) {
qtLog("+ $$1")
!equals(3, false): \
1 = "( $$1 ) 2>&1"
output = $$system("$$1", lines, result)
lg =
for (l, output): \
lg += "> $$l"
qtLog($$lg)
!isEmpty(2) {
$$2 = $$output
export($$2)
}
!equals(result, 0): return(false)
return(true)
}

Google closure compiler with ADVANCED_OPTIMIZATIONS giving me empty file

Command i am using is
java -jar closure-compiler-v20181028.jar --compilation_level ADVANCED_OPTIMIZATIONS --js_output_file=out.js input.js
my input.js contains only
function base() {
var b='xyz';
if (b.tagName && 0 == b.tagName.search(this.TAGS_)) {
if (b.hasAttribute("href") && void 0 !== self.angular) {
var f = b.getAttribute("href");
if (f.indexOf("{{") >= 0 && f.indexOf("}}") > 0 && !b.hasAttribute("ng-href"))
return b.setAttribute("ng-href", f), void b.removeAttribute("href");
}
for (var a = 0; a < this.URL_ATTRIBUTES_.length; ++a)
if (b.hasAttribute(this.URL_ATTRIBUTES_[a]))
return this.updateAttributes_(b, a);
}
}
i tried with gradle script, also same result .Any help would be appreciated.
From the documentation:
"...code compiled with ADVANCED_OPTIMIZATIONS may not work with uncompiled code unless you take special steps to ensure interoperability. If you do not flag external functions and properties referenced in your code, Closure Compiler will inappropriately rename references in your code, causing mismatches between the names in your code and in the external code."
By "flag" here, they mean "export". For more information see this documentation on the different compilations levels:
https://developers.google.com/closure/compiler/docs/compilation_levels
This blog post:
http://closuretools.blogspot.com/2012/09/which-compilation-level-is-right-for-me.html
And the documentation on exports here:
https://developers.google.com/closure/compiler/docs/api-tutorial3
If you don't call base(), the code will be removed as it is unreachable.
You'll either want to call it or add an #export notation to tell Closure it's needed by other code.
Alternatively, if something is calling base() it may not be properly included in your build.

qmake math operation (qt increment build number)

I am trying to to add build increment mechanism within .pro file.
To do so I have created a file named "version" with this content "1.1.15" (MAJOR_VERSION.MINOR_VERSION.BUILD_NUMBER)
Please find here my .pro content
MY_VERSION = "$$cat(version)"
VERSIONS = $$split(MY_VERSION, ".")
VERSION_MAJ = $$member(VERSIONS, 0)
VERSION_MIN = $$member(VERSIONS, 1)
VERSION_BUILD = $$member(VERSIONS, 2)
# VERSION_BUILD++ ??? HOW TO ???
VERSIONS = $$VERSION_MAJ $$VERSION_MIN $$VERSION_BUILD
MY_VERSION = $$join(VERSIONS, ".")
write_file(version, MY_VERSION)
Could someone help me on this ?
I've found a solution (not clean for me)
win32 {
VERSION_BUILD = $$system("set /a $$VERSION_BUILD + 1")
} else:unix {
VERSION_BUILD = $$system("echo $(($$VERSION_BUILD + 1))")
}

Difference Between Two Recursive Methods

I wanted to reflect a binary tree, such that all nodes on the left ended up on the right, and vice versa.
Something like :
A
/ \
B C
/ / \
D E F
would become
A
/ \
C B
/ \ \
F E D
I noticed that, while writing my solution, this code worked:
static Tree getReflection(Tree root) {
if(root == null) {
return null;
}
Tree reflect = root;
Tree subRight = getReflection(root.right);
Tree subLeft = getReflection(root.left);
reflect.left = subRight;
reflect.right = subLeft;
return reflect;
}
And yet, this one doesn't:
static Tree getReflection(Tree root) {
if(root == null) {
return null;
}
Tree reflect = root;
reflect.left = getReflection(root.right);
reflect.right = getReflection(root.left);
return reflect;
}
Can someone explain to me why? To me, they seem like identical methods, except one uses temporary tree variables.
Look at your first statement in each: when you assign
reflect = root
, the two variables now point to the same memory location. Now, let's look at the operation of the second routine:
Tree reflect = root;
// reflect and root now refer to exactly the same tree.
reflect.left = getReflection(root.right);
// reflect the right subtree; make that the new left subtree.
reflect.right = getReflection(root.left);
// Grab that new subtree, re-reflect it, and put it back on the right.
The original left subtree is lost, replaced by a reflection of the right.
In the first routine, you saved them in local variables until you'd done both reflections.
It is because in the second function (the one that doesn't work), you are assigning the reflected result to your left node and then using that as input to the reflection that you assign to your right node.
Tree reflect = root;
reflect.left = getReflection(root.right);
reflect.right = getReflection(root.left);

Grunt task for making sure you have copyrights on each file

I need to make sure there's copyrights notice at the beginning of each file.
How can I use grunt to fail my build in case the copyrights statement is missing?
First of all, I'm assuming you are referring to *.js or *.html or other similar work files, and not to graphic or binary files.
This can be done, with a grunt.registerTask which will:
1. loop through all relevant files
2. Read and compare first line to copyright line
3. If different - re-write file but a new first line which will be the copyright info
Pretty simple. Again - this will not work on binary files. I wrote this for you but it seems very useful, I might consider adding it as a plugin. Field tested:
run it by grunt verifyCopyright and also make sure that if your files are in a different directory your change it, and also if you want to process other files add them to the list as well. good luck...
grunt.registerTask('verifyCopyright', function () {
var fileRead, firstLine, counter = 0, fileExtension, commentWrapper;
copyrightInfo = 'Copyright by Gilad Peleg #2013';
//get file extension regex
var re = /(?:\.([^.]+))?$/;
grunt.log.writeln();
// read all subdirectories from your modules folder
grunt.file.expand(
{filter: 'isFile', cwd: 'public/'},
["**/*.js", ['**/*.html']])
.forEach(function (dir) {
fileRead = grunt.file.read('public/' + dir).split('\n');
firstLine = fileRead[0];
if (firstLine.indexOf(copyrightInfo > -1)) {
counter++;
grunt.log.write(dir);
grunt.log.writeln(" -->doesn't have copyright. Writing it.");
//need to be careful about:
//what kind of comment we can add to each type of file. i.e /* <text> */ to js
fileExtension = re.exec(dir)[1];
switch (fileExtension) {
case 'js':
commentWrapper = '/* ' + copyrightInfo + ' */';
break;
case 'html':
commentWrapper = '<!-- ' + copyrightInfo + ' //-->';
break;
default:
commentWrapper = null;
grunt.log.writeln('file extension not recognized');
break;
}
if (commentWrapper) {
fileRead.unshift(commentWrapper);
fileRead = fileRead.join('\n');
grunt.file.write( 'public/' + dir, fileRead);
}
}
});
grunt.log.ok('Found', counter, 'files without copyright');
})
Instead of checking to see if it's there and failing, why not just have a task that automatically injects it? See grunt-banner.
https://github.com/thekua/grunt-regex-check could be what you want. You define the regex to check for and if it finds it then the task fails.

Resources