Skip to content

Commit 17a7414

Browse files
author
jantje
committed
#1126 build nearly works
1 parent 1010f39 commit 17a7414

9 files changed

+102
-82
lines changed

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ArchiveNameProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import io.sloeber.core.common.Common;
99
import io.sloeber.core.common.Const;
1010
import io.sloeber.core.tools.Helpers;
11-
import io.sloeber.managedBuild.api.IManagedOutputNameProviderJaba;
11+
import io.sloeber.managedBuild.api.INewManagedOutputNameProvider;
1212

13-
public class ArchiveNameProvider implements IManagedOutputNameProviderJaba {
13+
public class ArchiveNameProvider implements INewManagedOutputNameProvider {
1414

1515
@Override
1616
public IPath getOutputName(IProject project, IConfiguration cConf, ITool tool, IPath primaryInput) {

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ArduinoGnuMakefileGenerator.java

+4
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ public IPath getBuildWorkingDir() {
576576
return null;
577577
}
578578

579+
public IFile getBuildFolder() {
580+
return topBuildDir;
581+
}
582+
579583
/*
580584
* (non-Javadoc)
581585
*

io.sloeber.core/src/io/sloeber/managedBuild/Internal/LinkNameProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import io.sloeber.core.common.Common;
99
import io.sloeber.core.common.Const;
1010
import io.sloeber.core.tools.Helpers;
11-
import io.sloeber.managedBuild.api.IManagedOutputNameProviderJaba;
11+
import io.sloeber.managedBuild.api.INewManagedOutputNameProvider;
1212

13-
public class LinkNameProvider implements IManagedOutputNameProviderJaba {
13+
public class LinkNameProvider implements INewManagedOutputNameProvider {
1414

1515
@Override
1616
public IPath getOutputName(IProject project, IConfiguration cConf, ITool tool, IPath inputName) {

io.sloeber.core/src/io/sloeber/managedBuild/Internal/MakeRule.java

+27-30
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.eclipse.cdt.managedbuilder.core.ITool;
2222
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
2323
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacroProvider;
24-
import org.eclipse.cdt.managedbuilder.internal.macros.FileContextData;
2524
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
2625
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
2726
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyCalculator;
@@ -249,7 +248,7 @@ private String enumPrerequisites(IFile buildFolder) {
249248
}
250249

251250
public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfiguration config) {
252-
251+
ICConfigurationDescription confDesc = ManagedBuildManager.getDescriptionForConfiguration(config);
253252
String cmd = myTool.getToolCommand();
254253
//For now assume 1 target with 1 or more prerequisites
255254
// if there is more than 1 prerequisite we take the flags of the first prerequisite only
@@ -283,9 +282,8 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
283282
boolean resourceNameRequiresExplicitRule = containsSpecialCharacters(sourceLocation.getLocation().toOSString());
284283
needExplicitRuleForFile = resourceNameRequiresExplicitRule
285284
|| BuildMacroProvider.getReferencedExplitFileMacros(myTool).length > 0
286-
|| BuildMacroProvider.getReferencedExplitFileMacros(cmd, IBuildMacroProvider.CONTEXT_FILE,
287-
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null,
288-
myTool)).length > 0;
285+
|| BuildMacroProvider.getReferencedExplitFileMacros(cmd, IBuildMacroProvider.CONTEXT_CONFIGURATION,
286+
confDesc).length > 0;
289287

290288
String outflag = myTool.getOutputFlag();
291289
String buildCmd = cmd + WHITESPACE + flags.toString().trim() + WHITESPACE + outflag + WHITESPACE
@@ -304,19 +302,17 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
304302
IBuildMacroProvider provider = ManagedBuildManager.getBuildMacroProvider();
305303
if (!needExplicitRuleForFile) {
306304
resolvedCommand = provider.resolveValueToMakefileFormat(buildCmd, EMPTY_STRING, WHITESPACE,
307-
IBuildMacroProvider.CONTEXT_FILE,
308-
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
305+
IBuildMacroProvider.CONTEXT_CONFIGURATION, confDesc);
309306
} else {
310307
// if we need an explicit rule then don't use any builder
311308
// variables, resolve everything to explicit strings
312309
resolvedCommand = provider.resolveValue(buildCmd, EMPTY_STRING, WHITESPACE,
313-
IBuildMacroProvider.CONTEXT_FILE,
314-
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
310+
IBuildMacroProvider.CONTEXT_CONFIGURATION, confDesc);
315311
}
316-
if (!resolvedCommand.isBlank())
312+
if (resolvedCommand != null && !resolvedCommand.isBlank())
317313
buildCmd = resolvedCommand.trim();
318314
} catch (BuildMacroException e) {
319-
/* JABA is not going to write this code */
315+
//Continue using the default buildCmd value
320316
}
321317

322318
StringBuffer buffer = new StringBuffer();
@@ -328,7 +324,7 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
328324
// JABA add sketch.prebuild and postbouild if needed
329325
//TOFIX this should not be here
330326
if ("sloeber.ino".equals(fileName)) { //$NON-NLS-1$
331-
ICConfigurationDescription confDesc = ManagedBuildManager.getDescriptionForConfiguration(config);
327+
332328
String sketchPrebuild = io.sloeber.core.common.Common.getBuildEnvironmentVariable(confDesc,
333329
"sloeber.sketch.prebuild", new String(), true); //$NON-NLS-1$
334330
String sketchPostBuild = io.sloeber.core.common.Common.getBuildEnvironmentVariable(confDesc,
@@ -386,21 +382,20 @@ private Set<String> getBuildFlags(IFile buildFolder, IConfiguration config, IFil
386382
private String expandCommandLinePattern(IConfiguration config, String sourceExtension, Set<String> flags,
387383
String outputFlag, String outputName, Set<String> inputResources, IFile inputLocation,
388384
IFile outputLocation) {
385+
ICConfigurationDescription confDesc = ManagedBuildManager.getDescriptionForConfiguration(config);
389386
String cmd = myTool.getToolCommand();
390387
// try to resolve the build macros in the tool command
391388
try {
392389
String resolvedCommand = null;
393390
if ((inputLocation != null && inputLocation.toString().indexOf(WHITESPACE) != -1)
394391
|| (outputLocation != null && outputLocation.toString().indexOf(WHITESPACE) != -1)) {
395392
resolvedCommand = ManagedBuildManager.getBuildMacroProvider().resolveValue(cmd, EMPTY_STRING,
396-
WHITESPACE, IBuildMacroProvider.CONTEXT_FILE,
397-
new FileContextData(inputLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
393+
WHITESPACE, IBuildMacroProvider.CONTEXT_CONFIGURATION, confDesc);
398394
} else {
399395
resolvedCommand = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(cmd,
400-
EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE,
401-
new FileContextData(inputLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
396+
EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_CONFIGURATION, confDesc);
402397
}
403-
if ((resolvedCommand = resolvedCommand.trim()).length() > 0)
398+
if (resolvedCommand != null && (resolvedCommand = resolvedCommand.trim()).length() > 0)
404399
cmd = resolvedCommand;
405400
} catch (BuildMacroException e) {
406401
/* JABA is not going to write this code */
@@ -461,27 +456,29 @@ public void addPrerequisites(IInputType inputType, Set<IFile> files) {
461456
}
462457

463458
/**
464-
* A simple rule is a rule that takes exactly 1 input type containing exactly
465-
* one file
459+
* A simple rule is a rule that takes exactly 1 input type
466460
* and exactly 1 output type containing exactly 1 file
467461
*
468462
* @return true if this rule is a simple rule
469463
* otherwise false
470464
*/
471465

472466
public boolean isSimpleRule() {
473-
int counter = 0;
474-
for (Set<IFile> files : myTargets.values()) {
475-
if ((++counter > 1) || (files.size() != 1)) {
476-
return false;
477-
}
478-
}
479-
counter = 0;
480-
for (Set<IFile> files : myPrerequisites.values()) {
481-
if ((++counter > 1) || (files.size() != 1)) {
482-
return false;
483-
}
467+
if ((myTargets.size() != 1) || (myTargets.size() != 1)) {
468+
return false;
484469
}
470+
// int counter = 0;
471+
// for (Set<IFile> files : myTargets.values()) {
472+
// if ((++counter > 1) || (files.size() != 1)) {
473+
// return false;
474+
// }
475+
// }
476+
// counter = 0;
477+
// for (Set<IFile> files : myPrerequisites.values()) {
478+
// if ((++counter > 1)) {
479+
// return false;
480+
// }
481+
// }
485482
return true;
486483

487484
}

io.sloeber.core/src/io/sloeber/managedBuild/Internal/MakeRules.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public void addRule(MakeRule newMakeRule) {
3636
inputType = curTarget.getKey();
3737
files = curTarget.getValue();
3838
}
39-
newMakeRule.addPrerequisites(inputType, files);
39+
makerule.addPrerequisites(inputType, files);
40+
} else {
41+
myMakeRules.add(newMakeRule);
4042
}
4143
}
42-
myMakeRules.add(newMakeRule);
44+
4345
}
4446

4547
public MakeRule findTarget(IOutputType outputType, IFile correctOutputPath) {

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ManagebBuildCommon.java

+35-17
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.eclipse.core.runtime.Path;
4343

4444
import io.sloeber.core.common.Common;
45-
import io.sloeber.managedBuild.api.IManagedOutputNameProviderJaba;
45+
import io.sloeber.managedBuild.api.INewManagedOutputNameProvider;
4646

4747
@SuppressWarnings("nls")
4848
public class ManagebBuildCommon {
@@ -592,14 +592,14 @@ static public String getToolCommandLinePattern(IConfiguration config, ITool tool
592592

593593
}
594594

595-
static public IManagedOutputNameProviderJaba getJABANameProvider(IOutputType iType) {
595+
static public INewManagedOutputNameProvider getJABANameProvider(IConfiguration cConf, IPath referencedFrom,
596+
IOutputType iType) {
596597
OutputType type = (OutputType) iType;
597598
IConfigurationElement element = type.getNameProviderElement();
598599
if (element != null) {
599600
try {
600601
if (element.getAttribute(IOutputType.NAME_PROVIDER) != null) {
601-
return (IManagedOutputNameProviderJaba) element
602-
.createExecutableExtension(IOutputType.NAME_PROVIDER);
602+
return (INewManagedOutputNameProvider) element.createExecutableExtension(IOutputType.NAME_PROVIDER);
603603
}
604604
} catch (@SuppressWarnings("unused") CoreException e) {
605605
//ignore errors
@@ -608,24 +608,41 @@ static public IManagedOutputNameProviderJaba getJABANameProvider(IOutputType iTy
608608
String[] outputNames = type.getOutputNames();
609609
if (outputNames != null && outputNames.length > 0) {
610610
String outputName = outputNames[0];
611-
return new IManagedOutputNameProviderJaba() {
611+
IBuildMacroProvider provider = ManagedBuildManager.getBuildMacroProvider();
612+
String expanded = outputName;
613+
try {
614+
expanded = provider.resolveValue(outputName, EMPTY_STRING, WHITESPACE,
615+
IBuildMacroProvider.CONTEXT_CONFIGURATION, cConf);
616+
} catch (BuildMacroException e) {
617+
// default will do
618+
e.printStackTrace();
619+
}
620+
IPath expandedPath = new Path(expanded);
621+
if (expandedPath.segmentCount() > 1) {
622+
expandedPath = GetNiceFileName(referencedFrom, new Path(expanded));
623+
}
624+
final IPath ret=expandedPath;
625+
return new INewManagedOutputNameProvider() {
612626

613627
@Override
614628
public IPath getOutputName(IProject project, IConfiguration cConf, ITool tool, IPath inputName) {
615-
return new Path(outputName);
616-
//return project.getFile(cConf.getName()).getFullPath().append(outputName);
629+
return ret;
617630
}
618631
};
619632
}
620633

621634
String[] outputExtensions = type.getOutputExtensionsAttribute();
622635
if (outputExtensions != null && outputExtensions.length > 0) {
623636
String outputExtension = outputExtensions[0];
624-
return new IManagedOutputNameProviderJaba() {
637+
return new INewManagedOutputNameProvider() {
625638

626639
@Override
627640
public IPath getOutputName(IProject project, IConfiguration cConf, ITool tool, IPath inputName) {
628-
return inputName.addFileExtension(outputExtension);
641+
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
642+
ICConfigurationDescription confDesc = prjDesc.getConfigurationByName(cConf.getName());
643+
String expanded = Common.getBuildEnvironmentVariable(confDesc, inputName.toString(),
644+
inputName.toString(), true);
645+
return new Path(expanded).addFileExtension(outputExtension);
629646
}
630647
};
631648
}
@@ -634,17 +651,18 @@ public IPath getOutputName(IProject project, IConfiguration cConf, ITool tool, I
634651
}
635652

636653
static public String GetNiceFileName(IFile buildPath, IFile path) {
637-
IPath buildLocation = buildPath.getLocation();
638-
IPath fileLocation = path.getLocation();
639-
if (buildLocation.isPrefixOf(path.getLocation())) {
640-
return fileLocation.makeRelativeTo(buildLocation).toOSString();
641-
//return DOT_SLASH_PATH.append(fileLocation.makeRelativeTo(buildLocation)).toOSString();
654+
return GetNiceFileName(buildPath.getLocation(), path.getLocation()).toOSString();
655+
}
656+
657+
static public IPath GetNiceFileName(IPath buildPath, IPath filePath) {
658+
if (buildPath.isPrefixOf(filePath)) {
659+
return filePath.makeRelativeTo(buildPath);
642660
}
643-
if (buildLocation.removeLastSegments(1).isPrefixOf(fileLocation)) {
644-
return fileLocation.makeRelativeTo(buildLocation).toOSString();
661+
if (buildPath.removeLastSegments(1).isPrefixOf(filePath)) {
662+
return filePath.makeRelativeTo(buildPath);
645663

646664
}
647-
return fileLocation.toOSString();
665+
return filePath;
648666
}
649667

650668
static public String makeVariable(String variableName) {

io.sloeber.core/src/io/sloeber/managedBuild/Internal/SubDirMakeGenerator.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.eclipse.core.runtime.IPath;
2424
import org.eclipse.core.runtime.Path;
2525

26-
import io.sloeber.managedBuild.api.IManagedOutputNameProviderJaba;
26+
import io.sloeber.managedBuild.api.INewManagedOutputNameProvider;
2727

2828
public class SubDirMakeGenerator {
2929
private ArduinoGnuMakefileGenerator caller;
@@ -33,11 +33,11 @@ public class SubDirMakeGenerator {
3333
SubDirMakeGenerator(ArduinoGnuMakefileGenerator theCaller, IContainer module) {
3434
caller = theCaller;
3535
IProject project = getProject();
36-
IPath buildRoot = getBuildWorkingDir();
37-
if (buildRoot == null) {
36+
IPath buildPath = getBuildPath();
37+
if (buildPath == null) {
3838
return;
3939
}
40-
IPath moduleOutputPath = buildRoot.append(module.getProjectRelativePath());
40+
IPath moduleOutputPath = buildPath.append(module.getProjectRelativePath());
4141
myMakefile = project.getFile(moduleOutputPath.append(MODFILE_NAME));
4242
getMakeRulesFromSourceFiles(module);
4343
}
@@ -102,10 +102,14 @@ public Map<IOutputType, Set<IFile>> getTargets() {
102102
return ret;
103103
}
104104

105-
private IPath getBuildWorkingDir() {
105+
private IPath getBuildPath() {
106106
return caller.getBuildWorkingDir();
107107
}
108108

109+
private IPath getBuildFolder() {
110+
return caller.getBuildFolder().getLocation();
111+
}
112+
109113
private IFile getTopBuildDir() {
110114
return caller.getTopBuildDir();
111115
}
@@ -181,6 +185,7 @@ private void getMakeRulesFromSourceFiles(IContainer module) {
181185
myMakeRules.clear();
182186
IConfiguration config = getConfig();
183187
IProject project = getProject();
188+
IPath buildPath = getBuildFolder();
184189

185190
// Visit the resources in this folder
186191
try {
@@ -206,7 +211,8 @@ private void getMakeRulesFromSourceFiles(IContainer module) {
206211
continue;
207212
}
208213
for (IOutputType outputType : tool.getOutputTypes()) {
209-
IManagedOutputNameProviderJaba nameProvider = getJABANameProvider(outputType);
214+
INewManagedOutputNameProvider nameProvider = getJABANameProvider(config, buildPath,
215+
outputType);
210216
if (nameProvider == null) {
211217
continue;
212218
}

0 commit comments

Comments
 (0)