This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

can JavaScript know the project/source location?

Hello,

I'm using JavaScript in the Scripting Console, for various CCS operations, including running a static analysis program on the source files.  In order to do this, I somehow have to get the script to have knowledge of the program/project location.  I can get the working directory of the JavaScript, i.e. c:\ti\ccs1040\ccs.  But what I really need is the location of my project and related source file.  Essentially the same as PROJECT_LOC in Linked Resources for the project.  I've looked through all the documentation and examples, but have found no way to make such a linkage.  Is there? 

Please advise,

Robert

  • Hello Robert,

    Eclipse variables like PROJECT_LOC cannot be used in a JS script run from the scripting console. 

    There is a way to return the location of the loaded out file however. symbol.getSymbolFileName() will return the file name in addition to the full path. This path may be helpful to then discern the project location - especially if the out file location is in the configuration subfolder of the project folder.

    Hope this helps

    ki

  • Thanks Ki.  As mentioned, that does require the pre-load of an executable, which may or may not be the case when running static analysis on a project, that I'm trying to automate with javascript.  But I appreciate any ideas.

    Best,

    Robert

  • As mentioned, that does require the pre-load of an executable, which may or may not be the case when running static analysis on a project, that I'm trying to automate with javascript. 

    Ah, right. Let me mull on this a bit and see if i can think of something that would work...

  • A simple but effective method I use to avoid all project path issues is using a drive mapping batch file. At the root of my project source check out is a batch file which calls DOS subst. e.g.:

    T: /D
    subst T: .

    Now any project references using T: as its root will be the same for everyone and anything including CI servers. You can then hard code paths in your JavaScript file using T:\

  • Hi Kier,

    Thanks much for the idea.  But I'd like to avoid batch files, and special prescriptions/drives for this effort.

    Robert

  • As an intermediate step, perhaps you can use "sed" to dump all the necessary info (eg. PROJECT_LOC) to a text file and then use your Java Script to parse the text file to get all necessary locations. Or you could get sed to modify your .js file directly at build time.

    For example, I put this string in my Pre-build steps to insert ${current_date} into 'build_info.h' so that my source and hex are timestamped at build time.

     

    This updates the string initialiser as shown below

  • Thanks Kier.  I have noted your suggested approach!, will keep it in the bag of tools, for potential use.  Will mark the thread resolved for now.

    Best,

    Robert (cygwin guy too)