Build script error[2]

I’m trying to run a Build Script to selectively copy files to the apps framework - based on constants set in App.

I have the following code (I’ve not yet added the doShellScript parts):

[code] dim compileTo as integer

compileTo = ConstantValue(“App.CompileTo”)

select case compileTo
case 1 //app.kTargetDeveloper

case 2 //app.kTargetMAS

case 3// app.kTargetMyStore

end select[/code]

but it fails with a compile error [2] in line 4. Scripting error [2] implies a type mismatch - but I don’t see one.

I always struggle with the limited documentation on Build Scripts - can anyone assist?

Possibly related to this post?

I’ve tried some different permutations with respect to Tim’s suggestion but can’t seem to get it to work. The Post seems to be related to an IDE script rather than a build script - the documentation seems to imply I should use “app.kConstantName”.

perhaps that constant value returns a string not an integer ?

Const CompileTo = 3

Shows it as a Number in the “Type” drop down and as Double in the definition.

I tried setting the local dim as a double - but get the same error.

ConstantValue() returns a string regardless of what type you defined the constant as

hence

[code] dim compileTo as integer

compileTo = ConstantValue(“App.CompileTo”)
[/code]

gives a type mismatch since constantvalue returns a string & you’re trying to shove it into an integer

Thanks Norman for that clarity.[quote=166566:@Norman Palardy]ConstantValue() returns a string regardless of what type you defined the constant as

hence

[code] dim compileTo as integer

compileTo = ConstantValue(“App.CompileTo”)
[/code]

gives a type mismatch since constantvalue returns a string & you’re trying to shove it into an integer[/quote]

Yip, that is the problem. Couldn’t find that in the documentation.

PS interesting - just seen that the quote I included from you is not the same as the statement I was trying to quote - Forum error?

Its in the PDF’s - Framework (book 3)

ConstantValue
Gets or sets the value of a project item constant.
Syntax?
ConstantValue(name As String) As String

Thanks Norman.

A little more assist if you are able. I now have

[code] select case ConstantValue(“App.CompileTo”)
case constantValue( “app.kTargetDeveloper” )

case constantValue( “app.kTargetMAS”)

case constantValue( “app.kTargetMyStore” )

dim sourcePath as string =  "~/Documents/Xojo Files/LimeLM/libTurboActivate.dylib"

dim targetPath as string = CurrentBuildLocation + "/Contents/Frameworks/"

dim copyFile as string =  "cp " + sourcePath +" "+ targetPath 

print doShellCommand( copyFile )

end select[/code]

But the print command gives the result:

[quote]usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file … target_directory[/quote]

And the file doesn’t get copied. What am I missing now?

that some of the paths aren’t shell paths so they wont be formatted correctly for use with cp

I’d do
print copyFile
the copy that and run it in terminal and you’ll see what I mean

Norman

After a fair bit of trial and error with Terminal and Posix paths - finally got it working. Provided here for reference.

[code] select case ConstantValue(“App.CompileTo”)
case constantValue( “app.kTargetDeveloper” )

case constantValue( “app.kTargetMAS”)

case constantValue( “app.kTargetMyStore” )

dim sourcePath as string =  getShellString( "/Users/yourUserName/Documents/Xojo Files/LimeLM/libTurboActivate.dylib") //set the path to your file here
//print sourcePath

dim appName as string = getShellString(currentBuildAppName) + ".app"
dim targetPath as string  = ( CurrentBuildLocation + "/" +appName + "/Contents/Frameworks/libTurboActivate.dylib" )
//print targetPath

dim copyFile as string =  "cp -R " + sourcePath +" "+ targetPath 
//print copyFile

call doShellCommand( copyFile )

end select

function getShellString(theString as String) as string
theString = ReplaceAll(theString, " ", "\ ")
theString = ReplaceAll(theString, “-”, “\-”)
theString = ReplaceAll(theString, “(”, “\(” )
theString = ReplaceAll(theString, “)”, “\)”)
return theString
end Function
[/code]

It appears that CurrentBuildLocation provides an escaped Posix path, whereas currentBuildAppName does not. You also need to ensure you add “.app” after the app name to get the right path.

Have also lodged some Feedbacks wrt typing “New F” anywhere in a build script - which crashes Xojo for some reason.