module QCloudHive

Constants

CODE_OA_CONFIG_PRIVATE_TOKEN
CODE_OA_GROUDP
CODE_OA_TEAM_NAME
HIVE_MODULES_FILE_NAME
REPO_ROOT_NAME
VERSION

Public Class Methods

BuildFramework(cmd, opts) click to toggle source
# File lib/qcloudhive/framework.rb, line 70
def QCloudHive.BuildFramework(cmd, opts)
  name = opts[:i_name]
  if name == nil
    L.error "ERROR! no project name, please input one"
    L.error cmd.help
    exit(1)
  end
  buildSimArch = opts[:i_build_sim]
  if buildSimArch.nil?
    buildSimArch = true
  end
  L.info "build sim #{buildSimArch}"
  unlinked = opts[:i_unlinked_frameworks]
  if unlinked.nil?
    unlinked = []
  end
  L.info "un linked frameworks #{unlinked}"
  output = Dir.pwd
  rootShellPath = Config.scriptesDirectory
  Rake::sh "#{rootShellPath}HiveFramework #{name}"

  projectDir = "#{output}/#{name}"
  project = Xcodeproj::Project.open("#{output}/#{name}/#{name}.xcodeproj")
  project.targets.each do |target|
    if target.name == name
      target.build_configurations.each do |config|
        config.build_settings['ENABLE_BITCODE'] = 'NO'
        puts "set bitcode NO"
      end
    end
    puts "target name #{name}"
  end

  project.save

  Rake::sh "cd #{name} \n" +
  "pod update\n"
  # delete unlinked frameworks
  project = Xcodeproj::Project.open("#{output}/#{name}/#{name}.xcodeproj")
  xcconfigFiles = project.files.select{ |f|
    L.info "file #{f.path}"
    f.path.end_with?(".xcconfig")
  }
  L.info("config files #{xcconfigFiles}")
  hiveXcodeProject = QCloudHive.xcodeprojectByPath(Pathname.new("#{output}/#{name}").realpath.to_s)
  xcconfigFiles.each { |f|
    path = Pathname.new(projectDir).join(f.path)
    config = Xcodeproj::Config.new(path)
    linked = config.other_linker_flags[:libraries].to_a
    L.info "#{config.other_linker_flags}"
    frameworkLinked = config.other_linker_flags[:frameworks].to_a
    L.info "linked #{linked}"
    # unlinked.each { |e|
    #   linked.delete e
    #   willUnlink = UnlinkedModule(e, hiveXcodeProject)
    #   L.info "will unlink #{willUnlink}"
    #   linked -= willUnlink
    #   frameworkLinked -= willUnlink
    # }
    linked = linked.compact
    frameworkLinked = frameworkLinked.compact
    config.other_linker_flags[:libraries] = linked.to_set
    config.other_linker_flags[:frameworks] = frameworkLinked.to_set
    L.info "final linked #{linked}"
    config.save_as(path)
  }
  #

  productsDir = "Products"
  productsDir = "#{projectDir}/#{productsDir}"
  if not Pathname.new(productsDir).exist?
    Pathname.new(productsDir).mkdir
  end



  buildCMD = BuildShell.new()
  buildCMD.config = "Release"
  buildCMD.productsDir = productsDir
  buildCMD.other_cflags = "\"-fembed-bitcode\""
  buildCMD.name = name
  buildCMD.sdk = "iphoneos"
  beginShell(name,buildCMD.to_cmd)


  deviceFramework="#{productsDir}/Build/Products/#{buildCMD.config}-iphoneos/#{name}.framework"

  if buildSimArch == true
    buildCMD = BuildShell.new()
    buildCMD.config = "Release"
    buildCMD.productsDir = productsDir
    buildCMD.other_cflags = "\"-fembed-bitcode\""
    buildCMD.name = name
    buildCMD.sdk = "iphonesimulator"

    beginShell(name,buildCMD.to_cmd)
    simFramework="#{productsDir}/Build/Products/#{buildCMD.config}-iphonesimulator/#{name}.framework"
    Rake::sh " lipo -create #{deviceFramework}/#{name} #{simFramework}/#{name} -output #{deviceFramework}/#{name}"

  end

  puts "Copy frameworks"
  outputFramework = "#{name}.framework"
  outputFrameworkPath = Pathname.new(outputFramework)
  if outputFrameworkPath.exist?
    FileUtils.rm_rf(outputFrameworkPath.to_path)
  end
  Rake::sh "cp -rvf #{deviceFramework} #{outputFramework}"
  Rake::sh "cp #{name}/.hivemodules #{outputFramework}/"
  headersPath = Pathname.new("#{outputFramework}/Headers/")
  if not headersPath.exist?
    headersPath.mkdir
  end
  if Pathname("#{name}/Pods/Headers/Public").exist?
    shell = "find #{name}/Pods/Headers/Public -name \"*.h\" -exec cp {}  #{outputFramework}/Headers/  \\;"
    Rake::sh shell
  end
  willRmBuild = opts[:i_rm_build]
  if willRmBuild != false
    FileUtils.rm_rf("#{name}")
  end
end
CreateAPP(cmd, opts) click to toggle source
# File lib/qcloudhive/product.rb, line 5
def QCloudHive.CreateAPP(cmd, opts)
  name = opts[:c_name]
  if name == nil
    puts "ERROR! no name, please input one"
    puts cmd.help
    exit(1)
  end
  Rake::sh "#{Config.scriptesDirectory}HiveApp.sh #{name}"
  Rake::sh "cd #{name} \n" +
  "pod install \n" +
  "open #{name}.xcworkspace"


  url = opts[:c_url]
  if url == nil
    puts "您没有设置URL,将不会进行Git 远端仓库配置"
  else
    Rake::sh "cd #{name} \n" +
    '''
    git init
    git add .
    git commit -m "init"
    ''' + "git remote add origin #{url} \n " +
    " git push -u origin master \n"
  end
end
FindRepoRoot(path) click to toggle source
# File lib/qcloudhive/config.rb, line 151
def QCloudHive.FindRepoRoot(path)
  pwd = Pathname(path)
  if pwd.to_path == "/"
    return nil
  end
  if pwd.to_path == '.repo'
    return pwd
  end
  aimPath = nil
  pwd.entries.each { |x|
    if x.to_path == REPO_ROOT_NAME
      aimPath = pwd.join(x)
      break
    end
  }
  if aimPath != nil
    return aimPath
  else
    parentDir = pwd.dirname
    if parentDir.to_path == REPO_ROOT_NAME
      return nil
    end
    return FindRepoRoot(parentDir)
  end
end
RemapProduct(cmd, opts) click to toggle source
# File lib/qcloudhive/repo.rb, line 14
def QCloudHive.RemapProduct(cmd, opts)
  pods = HivePod.podspecs
  Repo.addChildSpec("xxxx",pods[3])
end
UnlinkedModule(name, hiveXcodeProject) click to toggle source
# File lib/qcloudhive/framework.rb, line 39
def QCloudHive.UnlinkedModule(name, hiveXcodeProject)
  podspec = hiveXcodeProject.hiveSpecModules.select { |s|
    s.name == name
  }.first
  if podspec.nil?
    Error "您不想链接的模块#{name}, 不存在本地"
  end
  unlinked = []
  L.info "$$$$$$$$#{podspec.path}"
  if not podspec.path.nil?
    pod = Pod::Specification.from_file(podspec.path)
    vendored_libraries = pod.attributes_hash["vendored_libraries"]
    vendoredFrameworks = pod.attributes_hash["vendored_frameworks"]
    if not vendoredFrameworks.nil?
      vendoredFrameworks.each { |e|
        unlinked << Pathname.new(e).fileName
      }
    end
    if not vendored_libraries.nil?
      vendored_libraries.each { |e|
        name = Pathname.new(e).fileName
        if name.start_with?("lib")
          name = name[3..-1]
        end
        unlinked << name
      }
    end
    L.info "Unlinked #{unlinked}"
    return unlinked
  end
end
UpdateProducts(cmd, opts) click to toggle source
# File lib/qcloudhive/xcodeproj.rb, line 148
def QCloudHive.UpdateProducts(cmd, opts)
  name = opts[:i_name]
  Config.dumpShareConfig
  if name.nil?
    updateAllProducts
  end

end
addCMD(origin , cmd) click to toggle source
# File lib/qcloudhive/project.rb, line 66
def QCloudHive.addCMD(origin , cmd)
  return origin + "\n" + cmd + "\n"
end
beginShell(path, shell) click to toggle source
# File lib/qcloudhive/framework.rb, line 35
def QCloudHive.beginShell(path, shell)
  Rake::sh "cd #{path}\n #{shell}"
end
checkDependencies(cmd, opts) click to toggle source
# File lib/qcloudhive/feature.rb, line 61
  def QCloudHive.checkDependencies(cmd, opts)
    Config.manifest.projects.each { |p|
      L.info("#{p.path} exist #{p.exsitLocal?}")
      if  p.exsitLocal? and (not p.podspec.nil?)
        L.info("#{p.path}")
        version = Versionomy.parse(p.podspec.version.version)
        versionNumber = version.major*1000*1000 + version.minor*1000 + version.tiny
        str = "
#ifndef #{p.moduleName}ModuleVersion_h
#define #{p.moduleName}ModuleVersion_h
#define #{p.moduleName}ModuleVersionNumber #{versionNumber}
FOUNDATION_EXTERN NSString * const #{p.moduleName}ModuleVersion;
FOUNDATION_EXTERN NSString * const #{p.moduleName}ModuleName;
#endif
        "
        file = Pathname(p.localPath).join("Pod/Classes/#{p.moduleName}Version.h")
        File.open(file, "w") { |f|
          f.write str
        }

        file = Pathname(p.localPath).join("Pod/Classes/#{p.moduleName}Version.m")
        File.open(file, "w") { |f|
          f.write "
#import \"#{p.moduleName}Version.h\"
NSString * const #{p.moduleName}ModuleVersion = @\"#{p.podspec.version.version}\";
NSString * const #{p.moduleName}ModuleName = @\"#{p.moduleName}\";
          "
        }
      end
    }
  end
commitFeature(cmd, opts) click to toggle source
# File lib/qcloudhive/feature.rb, line 45
def QCloudHive.commitFeature(cmd, opts)
  message = GetOptValue(cmd, opts, :i_message)
  Config.manifest.projects.each { |p|
    if p.exsitLocal?
      git = p.gitRepo
      if (not git.nil?) and (not git.clean?)
        L.info("#{git.dir} commit clean #{git.clean?}")
        git.add(:all=>true)
        git.commit_all(message)
      else
        L.info("#{git.dir} is clean")
      end
    end
  }
end
findXcodeProject(path) click to toggle source
# File lib/qcloudhive/xcodeproj.rb, line 103
def QCloudHive.findXcodeProject(path)
  dirPath = Pathname.new(path)
  if not dirPath.directory?
    return []
  end
  projects = dirPath.each_child.select{|f|
    f.extname == ".xcodeproj"
  }
  if projects.count != 0
    return [dirPath.to_path]
  else
    subProjects = []
    dirPath.each_child { |file|
      if file.basename.to_path == ".git"
        next
      end
      if file.basename.to_path == ".repo"
        next
      end
      subDir = dirPath.join(file)
      if subDir.directory?
         subProjects+=findXcodeProject(subDir)
      end
    }
    return subProjects
  end
end
listFeature(cmd, opts) click to toggle source
# File lib/qcloudhive/feature.rb, line 14
def QCloudHive.listFeature(cmd, opts)
end
pushFeature(cmd, opts) click to toggle source
# File lib/qcloudhive/feature.rb, line 17
def QCloudHive.pushFeature(cmd, opts)
  Config.manifest.projects.each { |p|
    if not p.gitRepo.clean?
      Error("模块:#{p.path} 在本地有未提交的修改,请检查并提交后再进行PUSH操作")
    end
  }

  Config.manifest.projects.each { |p|
    currentBranch = p.gitRepo.branches[p.gitRepo.current_branch]
    currentFreature = ProjectFeature.new(p, currentBranch)
    if currentFreature.remoteBranch.nil?
      puts "#{p.path} 提交 #{currentBranch.name}"
      L.info("#{p.gitRepo} git repo xxxxxx")
      p.gitRepo.push('origin', currentBranch.name, {"--set-upstream"=>currentBranch.name})
    else
      compareRet = currentFreature.compareRemote
      if compareRet == 1
        puts "#{p.path} 提交 #{currentBranch.name}"
        L.info("#{p.gitRepo} git repo")
        p.gitRepo.push('origin', currentBranch.name, {"--set-upstream"=>currentBranch.name})
      elsif compareRet == -1
        puts "#{p.path} 没有进行push操作 远端有新的修改,请及时Pull⬇️⬇️⬇️".blue
      else
      end
    end
  }
end
startFeature(cmd, opts) click to toggle source
# File lib/qcloudhive/feature.rb, line 11
def QCloudHive.startFeature(cmd, opts)
end
syncManifest() click to toggle source
# File lib/qcloudhive/manifest.rb, line 330
def QCloudHive.syncManifest
  repoRootPath = Config.repoRoot
  manifestsPath=repoRootPath+"./manifests/"
  cmd = ""
  cmd = addCMD(cmd,"cd #{manifestsPath}")
  cmd = addCMD(cmd, "git add .")
  cmd = addCMD(cmd, "git commit -m \"Project Edited\"")
  cmd = addCMD(cmd, "git checkout default")
  cmd = addCMD(cmd, "git push origin HEAD:default")
  cmd = addCMD(cmd, "git checkout master")
  cmd = addCMD(cmd, "git merge default")
  cmd = addCMD(cmd, "git push origin HEAD:master")
  cmd = addCMD(cmd, "git checkout default")
  L.debug cmd
  Rake::sh cmd
end
updateAllProducts() click to toggle source
# File lib/qcloudhive/xcodeproj.rb, line 157
def QCloudHive.updateAllProducts
  QCloudHive.xcodeprojects.each { |hive|
    L.debug "codeproject #{hive.path}"
    Rake::sh "cd #{Pathname(hive.path).to_path};pod update"
  }
end
xcodeprojectByPath(path) click to toggle source
# File lib/qcloudhive/xcodeproj.rb, line 144
def QCloudHive.xcodeprojectByPath(path)
  QCloudHive.xcodeprojects.select{|p| p.path == path}.first
end
xcodeprojects() click to toggle source
# File lib/qcloudhive/xcodeproj.rb, line 130
def QCloudHive.xcodeprojects
  if @@xcodeprojectvar.nil?
    root = Config.projectRootDirectory
    L.info("find xcode projects")
    projects = findXcodeProject(root)
    xcodePojects = []
    projects.each { |xcp|
        xcodePojects << XCodeProject.new(xcp)
    }
    @@xcodeprojectvar = xcodePojects
  end
  return @@xcodeprojectvar
end

Public Instance Methods

InitEmptyProject(cmd, opts) click to toggle source
# File lib/qcloudhive/project.rb, line 71
def InitEmptyProject(cmd, opts)
  name = opts[:i_name]
  url = opts[:i_url]
  if name == nil
    puts "ERROR! no project name, please input one"
    puts cmd.help
    exit(1)
  end
  if url == nil
    puts "ERROR! no git url"
    puts cmd.help
    exit(1)
  end
  if File.exist?(name)
    puts "ERROR! the project exist, can not cover it. please check"
    exit(1)
  end

  emptyProjectPath = CURRENT_PATH+name+"/"
  templatePath = CDM_RES_PATH + "manifests/"
  DZCopyFile(templatePath, emptyProjectPath, true)
  Rake::sh "cd #{emptyProjectPath} \n" +'''
  git init .
  git add .
  git commit -m "init project"
  ''' + "git remote add origin #{url} \n " +
  " git push -u origin master \n" +
  "cd .. \n" +
  "rm -rf #{name}\n" +
  "mkdir #{name}\n" +
  "cd #{name}\n" +
  '''
  echo "产品初始化完成,将使用下述命令从您常用的源码目录,checkout该项目:"
  ''' + "repo init -u #{url}"

end