@@ -54,6 +54,7 @@ int main(string[] args)
5454
5555 int function (string [])[string ] entryPoints = [
5656 " build" : &buildMain,
57+ " build-universal" : &buildUniversalMain,
5758 " update" : &updateMain,
5859 " clean" : &cleanMain,
5960 " describe" : &describeMain,
@@ -246,6 +247,15 @@ int buildMain(string[] args)
246247 return buildProject (d).getReturnCode;
247248}
248249
250+ int buildUniversalMain (string [] args)
251+ {
252+ ArgsDetails argsDetails = resolveArguments(args);
253+ foreach (d; buildProjectUniversal (argsDetails))
254+ if (d.error)
255+ return d.getReturnCode;
256+ return 0 ;
257+ }
258+
249259int updateMain (string [] args)
250260{
251261 import core.runtime ;
@@ -407,148 +417,26 @@ string findProgramPath(string program)
407417ProjectDetails resolveDependencies (string [] args, bool isDescribeOnly = false )
408418{
409419 import std.file ;
410- import std.algorithm.comparison :either;
411- import std.getopt ;
412420 import redub.api;
413- string workingDir = std.file.getcwd ();
414- string targetPackage = getPackageFromCli(args);
415- string packageVersion = getVersionFromPackage(targetPackage);
416- string subPackage = getSubPackage(targetPackage);
417- string recipe;
418-
419- DubArguments bArgs;
420- GetoptResult res = betterGetopt(args, bArgs);
421-
422- if (res.helpWanted)
423- {
424- import std.getopt ;
425- string newCommands =
426- `
427- USAGE: redub [--version] [<command>] [<options...>] [-- [<application arguments...>]]
428-
429- Manages the redub project in the current directory. If the command is omitted,
430- redub will default to "run". When running an application, "--" can be used to
431- separate redub options from options passed to the application.
432-
433- Run "redub <command> --help" to get help for a specific command.
434-
435- Available commands
436- ==================
437-
438- Package creation
439- ----------------
440- init [<directory> [<dependency>...]]
441- Initializes an empty package skeleton
442-
443- Build, test and run
444- -------------------
445- run [<package>[@<version-spec>]]
446- Builds and runs a package (default command)
447- build [<package>[@<version-spec>]]
448- Builds a package (uses the main package in the current
449- working directory by default)
450- test [<package>[@<version-spec>]]
451- Executes the tests of the selected package
452- describe [<package>[@<version-spec>]]
453- Prints a description of the specified --data files
454- clean [<package>] Removes intermediate build files and cached build
455- results
456-
457- Additions to redub commands --
458-
459- update
460- Usage: redub update
461- Description: Updates with 'git pull' redub if the current redub is a git repository. If it is not, it will download the newest git tag from redub
462- repository. After updating the source, it will also optimally rebuild redub and replace the current one with the new build.
463- ` ;
464- defaultGetoptPrinter(RedubVersionShort~ " build information: \n\t " ~ newCommands, res.options);
465- return ProjectDetails.init;
466- }
467-
468- if (bArgs.version_)
469- {
470- import std.stdio ;
471- writeln(RedubVersion);
472- return ProjectDetails (null , Compiler.init, ParallelType.auto_, CompilationDetails.init, false , true );
473- }
474-
475- updateVerbosity(bArgs.cArgs);
476-
477- DubCommonArguments cArgs = bArgs.cArgs;
478- if (cArgs.root)
479- workingDir = cArgs.getRoot(workingDir);
480- if (recipe && (cArgs.recipe || cArgs.root))
481- throw new Error(` Can't specify a target package to build if you specify either --root or --recipe` );
482- if (bArgs.single && cArgs.recipe)
483- throw new RedubException(" Can't set both --single and --recipe" );
484- if (cArgs.recipe)
485- recipe = cArgs.getRecipe(workingDir);
486-
487- string localPackageName = getLocalPackageName(workingDir, recipe);
488-
489- if (shouldFetchPackage(localPackageName, targetPackage, subPackage))
490- {
491- import redub.package_searching.cache;
492- import redub.package_searching.entry;
493- PackageInfo* info = findPackage(targetPackage, null , packageVersion, " redub-run" );
494- if (! info)
495- throw new RedubException(" Could not find the package " ~ targetPackage~ " with version " ~ packageVersion);
496- workingDir = info.path;
497- recipe = findEntryProjectFile(info.path);
498- }
499-
500-
501- if (bArgs.arch && ! bArgs.compiler) bArgs.compiler = " ldc2" ;
502-
503-
504- if (bArgs.build.breadth)
505- {
506- import redub.command_generators.commons;
507- setSpanModeAsBreadth(bArgs.build.breadth);
508- }
509421
510- if (bArgs.single)
511- {
512- import std.path ;
513- if (! isAbsolute(bArgs.single))
514- recipe = buildNormalizedPath(workingDir, bArgs.single);
515- else
516- recipe = bArgs.single;
517- }
518-
519- if (bArgs.prefetch)
520- {
521- import redub.misc.path;
522- import redub.package_searching.dub;
523- string selections = redub.misc.path.buildNormalizedPath(workingDir, " dub.selections.json" );
524- auto timing = timed((){prefetchPackages(selections); return true ;});
525-
526- foreach (pkg; fetchedPackages)
527- {
528- infos(" Fetch Success: " , pkg.name, " v" ,pkg.version_, " required by " , pkg.reqBy);
529- }
530- fetchedPackages.length = 0 ;
531- infos(" Prefetch Finished: " , timing.msecs," ms" );
532- }
533-
534-
535- string bt = either(bArgs.buildType, BuildType.debug_);
422+ ArgsDetails argsD = resolveArguments(args, isDescribeOnly);
423+
536424
537425 ProjectDetails ret = redub.api.resolveDependencies(
538- bArgs .build.force,
426+ argsD.args .build.force,
539427 os,
540- CompilationDetails(bArgs.compiler, bArgs.cCompiler, bArgs.arch, bArgs.compilerAssumption, bArgs.build.incremental, bArgs.build.useExistingObj, bArgs.build.combined, bArgs.build.parallel) ,
541- ProjectToParse(bArgs.config, workingDir, subPackage, recipe, bArgs.single.length != 0 , isDescribeOnly) ,
542- getInitialDubVariablesFromArguments(bArgs, DubBuildArguments.init, os, args) ,
543- bt
428+ argsD.cDetails ,
429+ argsD.proj ,
430+ argsD.dubVars ,
431+ argsD.buildType
544432 );
545433
546- if (bArgs .targetPath)
547- ret.tree.requirements.cfg.outputDirectory = bArgs .targetPath;
548- if (bArgs .targetName)
549- ret.tree.requirements.cfg.targetName = bArgs .targetName;
434+ if (argsD.args .targetPath)
435+ ret.tree.requirements.cfg.outputDirectory = argsD.args .targetPath;
436+ if (argsD.args .targetName)
437+ ret.tree.requirements.cfg.targetName = argsD.args .targetName;
550438
551- if (bArgs .build.printBuilds)
439+ if (argsD.args .build.printBuilds)
552440 {
553441 import redub.parsers.build_type;
554442 info(" \t Available build types:" );
@@ -563,44 +451,3 @@ update
563451
564452 return ret;
565453}
566-
567- void updateVerbosity (DubCommonArguments a)
568- {
569- import redub.logging;
570- if (a.vquiet) return setLogLevel(LogLevel.none);
571- if (a.verror) return setLogLevel(LogLevel.error);
572- if (a.quiet) return setLogLevel(LogLevel.warn);
573- if (a.verbose) return setLogLevel(LogLevel.verbose);
574- if (a.vverbose) return setLogLevel(LogLevel.vverbose);
575- return setLogLevel (LogLevel.info);
576- }
577- private string getPackageFromCli (ref string [] args)
578- {
579- if (args.length > 1 && args[1 ][0 ] != ' -' )
580- {
581- string ret = args[1 ];
582- args = args[0 .. $] ~ args[2 .. $];
583- return ret;
584- }
585- return null ;
586- }
587-
588- private string getVersionFromPackage (ref string pkg)
589- {
590- import std.algorithm.searching ;
591- ptrdiff_t ver = countUntil! ((a => a == ' @' ))(pkg);
592- if (ver == - 1 ) return null ;
593- string ret = pkg[ver+ 2 .. $]; // Advance @ and v from the tag
594- pkg = pkg[0 .. ver];
595- return ret;
596- }
597-
598- private string getSubPackage (ref string pkg)
599- {
600- import std.algorithm.searching ;
601- ptrdiff_t subPackIndex = countUntil! ((a => a == ' :' ))(pkg);
602- if (subPackIndex == - 1 ) return null ;
603- string ret = pkg[subPackIndex+ 1 .. $];
604- pkg = pkg[0 .. subPackIndex];
605- return ret;
606- }
0 commit comments