Skip to content
Browse files

cabal sandboxing

  • Loading branch information...
1 parent 81386ec commit 3a675929638ed1ea10a452cdb96c81df66c0a884 @JPMoresmau committed Dec 31, 2013
View
16 ...sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BWFacade.java
@@ -70,6 +70,7 @@
public static final String DIST_FOLDER=".dist-buildwrapper";
public static final String DIST_FOLDER_CABAL=DIST_FOLDER+"/dist";
public static final String DIST_FOLDER_CABALDEV=DIST_FOLDER+"/cabal-dev";
+ public static final String DIST_FOLDER_CABALSANDBOX=DIST_FOLDER+"/.cabal-sandbox";
private static final String prefix="build-wrapper-json:";
@@ -761,7 +762,7 @@ public boolean write(IFile file,File tgt,String contents){
LinkedList<String> command=new LinkedList<String>();
command.add("dependencies");
if (SandboxHelper.isSandboxed(this)){
- command.add("--sandbox="+DIST_FOLDER_CABALDEV);
+ command.add("--sandbox="+getCabalImplDetails().getSandboxPath());
}
JSONArray arr=run(command,ARRAY);
if (arr==null){
@@ -1432,16 +1433,16 @@ private synchronized void addBuildWrapperPath(ProcessBuilder pb){
* run cabal with the given argument, using the flags defined on the project
* @param args
*/
- public void runCabal(LinkedList<String> args){
- runCabal(args,flags);
+ public void runCabal(LinkedList<String> args,File workDir){
+ runCabal(args,flags,workDir);
}
/**
* run cabal with the given argument, using the provided flags
* @param args
* @param explicitFlags
*/
- public void runCabal(LinkedList<String> args,String explicitFlags){
+ public void runCabal(LinkedList<String> args,String explicitFlags,File workDir){
if (isCanceled()){
return;
}
@@ -1462,7 +1463,12 @@ public void runCabal(LinkedList<String> args,String explicitFlags){
//File bd=new File (workingDir,BWFacade.DIST_FOLDER_CABAL);
//args.add("--builddir="+BWFacade.DIST_FOLDER_CABAL);
ProcessBuilder pb=new ProcessBuilder();
- pb.directory(workingDir);
+ if (workDir==null){
+ pb.directory(workingDir);
+ } else {
+ workDir.mkdirs();
+ pb.directory(workDir);
+ }
pb.redirectErrorStream(true);
pb.command(args);
addBuildWrapperPath(pb);
View
81 ...lipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/SandboxHelper.java
@@ -5,6 +5,7 @@
*/
package net.sf.eclipsefp.haskell.buildwrapper;
+import java.io.File;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
@@ -44,27 +45,59 @@
public static void installDeps(BWFacade f) throws CoreException{
if (f!=null){
SandboxType st=f.getCabalImplDetails().getType();
+ IProject p=f.getProject();
+
switch (st){
- case CABAL_DEV:
- IProject p=f.getProject();
-
- if (!f.getCabalImplDetails().isUniqueSandbox()){
- Set<IProject> processed=new HashSet<IProject>();
- processed.add(p);
- for (IProject pR:p.getReferencedProjects()){
- installDeps(f,pR,processed);
+ case CABAL_DEV:
+ {
+ if (!f.getCabalImplDetails().isUniqueSandbox()){
+ Set<IProject> processed=new HashSet<IProject>();
+ processed.add(p);
+ for (IProject pR:p.getReferencedProjects()){
+ installDeps(f,pR,processed);
+ }
}
+
+ LinkedList<String> args=new LinkedList<String>();
+ args.add("install-deps");
+ // enable tests
+ args.add("--enable-tests");
+ // enable benchmarks
+ args.add("--enable-benchmarks");
+ // force reinstalls since we won't break anything outside of the sandbox
+ args.add("--force-reinstalls");
+ args.addAll(f.getCabalImplDetails().getInstallOptions());
+ f.runCabal(args,null);
+ break;
+ }
+ case CABAL:
+ {
+ if (!f.getCabalImplDetails().isUniqueSandbox()){
+ Set<IProject> processed=new HashSet<IProject>();
+ processed.add(p);
+ for (IProject pR:p.getReferencedProjects()){
+ installDeps(f,pR,processed);
+ }
+ }
+ LinkedList<String> args=new LinkedList<String>();
+ args.add("sandbox");
+ args.add("init");
+ args.addAll(f.getCabalImplDetails().getInitOptions());
+
+ f.runCabal(args,null);
+
+ args=new LinkedList<String>();
+ args.add("install");
+ args.add("--only-dependencies");
+ // enable tests
+ args.add("--enable-tests");
+ // enable benchmarks
+ args.add("--enable-benchmarks");
+ // force reinstalls since we won't break anything outside of the sandbox
+ args.add("--force-reinstalls");
+ f.runCabal(args,null);
+ break;
}
-
- LinkedList<String> args=new LinkedList<String>();
- args.add("install-deps");
- // enable tests
- args.add("--enable-tests");
- // force reinstalls since we won't break anything outside of the sandbox
- args.add("--force-reinstalls");
- args.addAll(f.getCabalImplDetails().getInstallOptions());
- f.runCabal(args);
- break;
}
}
}
@@ -91,8 +124,10 @@ private static void installDeps(BWFacade sandboxFacade,IProject p,Set<IProject>
args.add("install");
args.add(p.getLocation().toOSString());
args.add("--force-reinstalls");
- args.addAll(sandboxFacade.getCabalImplDetails().getInstallOptions());
- sandboxFacade.runCabal(args);
+ if (SandboxType.CABAL_DEV.equals(sandboxFacade.getCabalImplDetails().getType())){
+ args.addAll(sandboxFacade.getCabalImplDetails().getInstallOptions());
+ }
+ sandboxFacade.runCabal(args,null);
}
}
@@ -106,6 +141,7 @@ public static void updateUsing(BWFacade f) throws CoreException{
SandboxType st=f.getCabalImplDetails().getType();
switch (st){
case CABAL_DEV:
+ case CABAL:
Set<IProject> processed=new HashSet<IProject>();
if (!f.getCabalImplDetails().isUniqueSandbox()){
IProject p=f.getProject();
@@ -150,7 +186,7 @@ private static boolean install(IProject changedProject,IProject p,Set<IProject>
if (changedF!=null){
expFlags=changedF.getFlags();
}
- f.runCabal(args,expFlags); // install the changed project with its own flags
+ f.runCabal(args,expFlags,null); // install the changed project with its own flags
if (f.isCanceled()){
return false;
}
@@ -230,6 +266,8 @@ public static boolean sandboxExists(BWFacade f){
switch (st){
case CABAL_DEV:
return f.getProject().getFolder(BWFacade.DIST_FOLDER_CABALDEV).exists();
+ case CABAL:
+ return f.getProject().getFolder(BWFacade.DIST_FOLDER_CABALSANDBOX).exists();
}
}
return false;
@@ -245,6 +283,7 @@ public static boolean isSandboxed(BWFacade f){
SandboxType st=f.getCabalImplDetails().getType();
switch (st){
case CABAL_DEV:
+ case CABAL:
return true;
}
}
View
23 ...askell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/types/CabalImplDetails.java
@@ -15,15 +15,20 @@
*/
public class CabalImplDetails {
public enum SandboxType {
- NONE, CABAL_DEV;
+ NONE, CABAL_DEV, CABAL;
}
private String executable;
private final List<String> options = new ArrayList<String>();
private final List<String> installOptions = new ArrayList<String>();
-
+ private final List<String> initOptions = new ArrayList<String>();
+
private SandboxType type = SandboxType.NONE;
+ private String sandboxPath;
+
+
+
/**
* do we have a unique sandbox?
*/
@@ -61,6 +66,13 @@ public void setType(SandboxType type) {
return installOptions;
}
+ /**
+ * @return the initOptions
+ */
+ public List<String> getInitOptions() {
+ return initOptions;
+ }
+
public boolean isUniqueSandbox() {
return uniqueSandbox;
}
@@ -69,4 +81,11 @@ public void setUniqueSandbox(boolean uniqueSandbox) {
this.uniqueSandbox = uniqueSandbox;
}
+ public String getSandboxPath() {
+ return sandboxPath;
+ }
+
+ public void setSandboxPath(String sandboxPath) {
+ this.sandboxPath = sandboxPath;
+ }
}
View
6 ...f.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/cabal/CabalImplementation.java
@@ -8,6 +8,7 @@
import net.sf.eclipsefp.haskell.util.QueryUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.osgi.framework.Version;
/**
* Cabal implementation manager container.
@@ -195,4 +196,9 @@ public void copy( final CabalImplementation theImpl ) {
resetVersions();
}
}
+
+ public boolean allowsSandbox(){
+ return new Version(getInstallVersion()).compareTo( new Version("1.18.0") )>=0;
+
+ }
}
View
2 net.sf.eclipsefp.haskell.ui/plugin.properties
@@ -77,7 +77,7 @@ stylishHaskellPP_name= Stylish Haskell
alexPP_name= Alex
happyPP_name= Happy
uuagcPP_name= UUAGC
-cabalDevPP_name=cabal-dev
+sandboxingPP_name=Sandboxing
implementationsPP_name = Haskell Implementations
#importLibsPP_name = Import Libraries
View
4 net.sf.eclipsefp.haskell.ui/plugin.xml
@@ -341,8 +341,8 @@
<page
class="net.sf.eclipsefp.haskell.ui.internal.preferences.scion.CabalDevPP"
id="net.sf.eclipsefp.haskell.ui.internal.preferences.scion.CabalDevPP"
- name="%cabalDevPP_name"
- category="net.sf.eclipsefp.haskell.ui.internal.preferences.scion.ScionPP">
+ name="%sandboxingPP_name"
+ category="net.sf.eclipsefp.haskell.ui.preferences.HaskellCategoryPP">
</page>
<page
View
1 ...haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/IPreferenceConstants.java
@@ -59,6 +59,7 @@
public final static String UUAGC_EXECUTABLE="UUAGC_EXECUTABLE"; //$NON-NLS-1$
public final static String CABALDEV_EXECUTABLE="CABALDEV_EXECUTABLE"; //$NON-NLS-1$
public final static String UNIQUE_SANDBOX="UNIQUE_SANDBOX"; //$NON-NLS-1$
+ public final static String CABAL_SANDBOX="CABAL_SANDBOX"; //$NON-NLS-1$
/**
* Source-graph
*/
View
17 ...efp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/scion/CabalDevPP.java
@@ -5,6 +5,8 @@
*/
package net.sf.eclipsefp.haskell.ui.internal.preferences.scion;
+import net.sf.eclipsefp.haskell.core.cabal.CabalImplementation;
+import net.sf.eclipsefp.haskell.core.cabal.CabalImplementationManager;
import net.sf.eclipsefp.haskell.ui.internal.preferences.IPreferenceConstants;
import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
import org.eclipse.jface.preference.BooleanFieldEditor;
@@ -22,6 +24,9 @@
public class CabalDevPP extends ExecutablePP {
private BooleanFieldEditor uniqueSandboxField;
+ private BooleanFieldEditor cabalSandboxField;
+
+
public CabalDevPP(){
super("cabal-dev","cabal-dev",IPreferenceConstants.CABALDEV_EXECUTABLE);
}
@@ -36,6 +41,17 @@ protected Control createContents( final Composite parentComposite ) {
Label l=new Label(parentComposite,SWT.NONE);
l.setText( UITexts.preferences_cabaldev_note);
+ cabalSandboxField= new BooleanFieldEditor( IPreferenceConstants.CABAL_SANDBOX,
+ UITexts.executables_preferences_cabal_sandbox,
+ parentComposite );
+ cabalSandboxField.setPage(this);
+ cabalSandboxField.setPreferenceStore( getPreferenceStore() );
+ cabalSandboxField.load();
+ CabalImplementation impl=CabalImplementationManager.getInstance().getDefaultCabalImplementation();
+ if (impl==null || !impl.allowsSandbox()){
+ cabalSandboxField.setEnabled( false, parentComposite );
+ }
+
uniqueSandboxField= new BooleanFieldEditor( IPreferenceConstants.UNIQUE_SANDBOX,
UITexts.executables_preferences_unique_sandbox,
parentComposite );
@@ -49,6 +65,7 @@ protected Control createContents( final Composite parentComposite ) {
@Override
public boolean performOk() {
uniqueSandboxField.store();
+ cabalSandboxField.store();
return super.performOk();
}
View
34 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/scion/ScionManager.java
@@ -949,10 +949,14 @@ private synchronized void startInstance( final IProject project ) {
}
}
- private static IPath getUniqueSandboxLocation(){
+ private static IPath getUniqueCabalDevSandboxLocation(){
return HaskellUIPlugin.getDefault().getStateLocation().append( ".cabal-dev" );
}
+ private static IPath getUniqueCabalSandboxLocation(){
+ return HaskellUIPlugin.getDefault().getStateLocation().append( ".cabal-sandbox" );
+ }
+
public static CabalImplDetails getCabalImplDetails(){
CabalImplDetails details=new CabalImplDetails();
String cabal=CabalImplementationManager.getCabalExecutable();
@@ -963,17 +967,33 @@ public static CabalImplDetails getCabalImplDetails(){
if (cabalDev!=null && cabalDev.length()>0 && new File(cabalDev).exists()){
details.setExecutable( cabalDev);
details.setUniqueSandbox( preferenceStore.getBoolean( IPreferenceConstants.UNIQUE_SANDBOX ) );
- if (details.isUniqueSandbox()){
- details.getOptions().add("--sandbox="+getUniqueSandboxLocation().toOSString());
- } else {
- details.getOptions().add("--sandbox="+BWFacade.DIST_FOLDER_CABALDEV);
- }
+ String sd=details.isUniqueSandbox()?
+ getUniqueCabalDevSandboxLocation().toOSString()
+ :BWFacade.DIST_FOLDER_CABALDEV;
+ details.setSandboxPath( sd );
+ details.getOptions().add("--sandbox="+sd);
details.getOptions().add("--with-cabal-install="+cabal);
details.setType( SandboxType.CABAL_DEV );
} else { // standard cabal
+
details.setExecutable(cabal);
- details.setType( SandboxType.NONE );
+
+ boolean cabalSandbox=preferenceStore.getBoolean( IPreferenceConstants.CABAL_SANDBOX );
+ if (cabalSandbox){
+ details.setUniqueSandbox( preferenceStore.getBoolean( IPreferenceConstants.UNIQUE_SANDBOX ) );
+
+ String sd=details.isUniqueSandbox()?
+ getUniqueCabalSandboxLocation().toOSString()
+ :BWFacade.DIST_FOLDER_CABALSANDBOX;
+ details.setSandboxPath( sd );
+ details.getInitOptions().add("--sandbox");
+ details.getInitOptions().add(sd);
+
+ details.setType( SandboxType.CABAL );
+ } else {
+ details.setType( SandboxType.NONE );
+ }
}
addCabalInstallOptions( details.getInstallOptions() );
View
1 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
@@ -848,6 +848,7 @@
public static String executables_preferences_console_activateonwrite;
public static String executables_preferences_browser_perspective;
public static String executables_preferences_unique_sandbox;
+ public static String executables_preferences_cabal_sandbox;
private static final String BUNDLE_NAME = UITexts.class.getPackage()
.getName() + ".uitexts"; //$NON-NLS-1$
View
3 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
@@ -101,6 +101,7 @@ executables_preferences_console_high = Maximum number of characters in Haskell C
executables_preferences_console_activateonwrite= Activate Haskell Console on write
executables_preferences_browser_perspective= Only start Browser when a Haskell perspective is open
executables_preferences_unique_sandbox=Use one sandbox for all projects in workspace
+executables_preferences_cabal_sandbox=Use cabal sandboxes
autodetectButton_label = Try to find the executable in common directories...
autodetectButton_text = Auto&detect
@@ -188,7 +189,7 @@ executablesmissing_install=Install
executablesmissing_user=Install for current user only
executablesmissing_ignore=Do not ask me again
-executables_extra=Install optional helper executables (hoogle, hlint, stylish-haskell, SourceGraph, cabal-dev)
+executables_extra=Install optional helper executables (hoogle, hlint, stylish-haskell, SourceGraph)
error_getVersion = Error retrieving executable version
error_checkVersion = Error checking executable version

0 comments on commit 3a67592

Please sign in to comment.
Something went wrong with that request. Please try again.